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
- Committer:
- tadns
- Date:
- 2013-04-09
- Revision:
- 1:63e1320ed4f8
- Parent:
- 0:11c4cf24f38b
File content as of revision 1:63e1320ed4f8:
#include "mbed.h"
#include "TextLCD.h"
TextLCD lcd(p24, p26, p27, p28, p29, p30);
int main() {
// setup time structure for Wed, 11 April 2013 5:00:00
struct tm t;
t.tm_sec = 00; // 0-59
t.tm_min = 00; // 0-59
t.tm_hour = 5; // 0-23
t.tm_mday = 11; // 1-31
t.tm_mon = 3; // 0-11
t.tm_year = 113; // year since 1900
// convert to timestamp
time_t seconds = mktime(&t);
// Set RTC time today
set_time(mktime(&t));
while(1) {
time_t seconds = time(NULL);
lcd.locate(0,0);
char day[16];
strftime(day, 16, "%Y/%m/%d %a\n", localtime(&seconds));
lcd.printf("%s", day);
char time[16];
strftime(time, 16, "%H:%M:%S\n", localtime(&seconds));
lcd.locate(0,1);
lcd.printf("%s", time);
wait(1.0);
}
}
