Skip to content

Instantly share code, notes, and snippets.

@okhiroyuki
Created June 30, 2012 01:23
Show Gist options
  • Save okhiroyuki/3021682 to your computer and use it in GitHub Desktop.
Save okhiroyuki/3021682 to your computer and use it in GitHub Desktop.
Setting RTC on mbed from GPS(GT-720F)
#include "mbed.h"
#include "TinyGPS.h"
TinyGPS gps;
Serial pc(USBTX, USBRX); // tx, rx
Serial device(p9, p10); // tx, rx
int main() {
struct tm t;
int year;
byte month, day, hour, minute, second, hundredths;
while(1) {
if(device.readable()) {
if(gps.encode(device.getc())){
gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths);
t.tm_sec = second; // 0-59
t.tm_min = minute; // 0-59
t.tm_hour = hour+9; // 0-23
t.tm_mday = day; // 1-31
t.tm_mon = month; // 0-11
t.tm_year = year-1900; // year since 1900
// convert to timestamp and set (1256729737)
time_t seconds = mktime(&t);
set_time(seconds);
seconds = time(NULL);
printf("Time as a string = %s", ctime(&seconds));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment