Created
June 30, 2012 01:23
-
-
Save okhiroyuki/3021682 to your computer and use it in GitHub Desktop.
Setting RTC on mbed from GPS(GT-720F)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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