This is the REAL TIME CLOCK for LPC1768
Fork of clock by
This code is for RTC of LPC1768. To give the value of year , one needs to substruct 1900 from the present year.
main.cpp@1:63e1320ed4f8, 2013-04-09 (annotated)
- Committer:
- tadns
- Date:
- Tue Apr 09 13:22:38 2013 +0000
- Revision:
- 1:63e1320ed4f8
- Parent:
- 0:11c4cf24f38b
RTC clock for LPC 1768
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jf1vrr | 0:11c4cf24f38b | 1 | #include "mbed.h" |
jf1vrr | 0:11c4cf24f38b | 2 | #include "TextLCD.h" |
jf1vrr | 0:11c4cf24f38b | 3 | |
jf1vrr | 0:11c4cf24f38b | 4 | TextLCD lcd(p24, p26, p27, p28, p29, p30); |
jf1vrr | 0:11c4cf24f38b | 5 | |
jf1vrr | 0:11c4cf24f38b | 6 | int main() { |
tadns | 1:63e1320ed4f8 | 7 | // setup time structure for Wed, 11 April 2013 5:00:00 |
tadns | 1:63e1320ed4f8 | 8 | struct tm t; |
tadns | 1:63e1320ed4f8 | 9 | t.tm_sec = 00; // 0-59 |
tadns | 1:63e1320ed4f8 | 10 | t.tm_min = 00; // 0-59 |
tadns | 1:63e1320ed4f8 | 11 | t.tm_hour = 5; // 0-23 |
tadns | 1:63e1320ed4f8 | 12 | t.tm_mday = 11; // 1-31 |
tadns | 1:63e1320ed4f8 | 13 | t.tm_mon = 3; // 0-11 |
tadns | 1:63e1320ed4f8 | 14 | t.tm_year = 113; // year since 1900 |
jf1vrr | 0:11c4cf24f38b | 15 | |
tadns | 1:63e1320ed4f8 | 16 | // convert to timestamp |
tadns | 1:63e1320ed4f8 | 17 | time_t seconds = mktime(&t); |
tadns | 1:63e1320ed4f8 | 18 | |
tadns | 1:63e1320ed4f8 | 19 | // Set RTC time today |
tadns | 1:63e1320ed4f8 | 20 | set_time(mktime(&t)); |
tadns | 1:63e1320ed4f8 | 21 | |
tadns | 1:63e1320ed4f8 | 22 | while(1) { |
tadns | 1:63e1320ed4f8 | 23 | |
jf1vrr | 0:11c4cf24f38b | 24 | time_t seconds = time(NULL); |
jf1vrr | 0:11c4cf24f38b | 25 | |
tadns | 1:63e1320ed4f8 | 26 | lcd.locate(0,0); |
tadns | 1:63e1320ed4f8 | 27 | char day[16]; |
tadns | 1:63e1320ed4f8 | 28 | strftime(day, 16, "%Y/%m/%d %a\n", localtime(&seconds)); |
tadns | 1:63e1320ed4f8 | 29 | lcd.printf("%s", day); |
tadns | 1:63e1320ed4f8 | 30 | |
tadns | 1:63e1320ed4f8 | 31 | char time[16]; |
tadns | 1:63e1320ed4f8 | 32 | strftime(time, 16, "%H:%M:%S\n", localtime(&seconds)); |
tadns | 1:63e1320ed4f8 | 33 | lcd.locate(0,1); |
tadns | 1:63e1320ed4f8 | 34 | lcd.printf("%s", time); |
tadns | 1:63e1320ed4f8 | 35 | |
tadns | 1:63e1320ed4f8 | 36 | |
jf1vrr | 0:11c4cf24f38b | 37 | wait(1.0); |
tadns | 1:63e1320ed4f8 | 38 | } |
tadns | 1:63e1320ed4f8 | 39 | |
tadns | 1:63e1320ed4f8 | 40 | |
tadns | 1:63e1320ed4f8 | 41 | |
tadns | 1:63e1320ed4f8 | 42 | |
jf1vrr | 0:11c4cf24f38b | 43 | } |