Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 #include "TextLCD.h" 00003 00004 void SetDateTime(int year,int mon, int day, int hour,int min,int sec); 00005 00006 TextLCD lcd(D12, D11, D5, D4, D3, D2, TextLCD::LCD16x2); // rs, e, d4-d7 00007 DigitalOut myled(LED1); 00008 char buf[16]; 00009 00010 int main() 00011 { 00012 lcd.printf("RTC example."); 00013 //set_time(1387188323); 00014 SetDateTime(2016,10,24,14,17,0); 00015 lcd.locate(0,1); 00016 lcd.printf("Time is set."); 00017 wait(2); 00018 lcd.locate(0,1); 00019 lcd.printf(" "); 00020 while(1) { 00021 lcd.locate(0,1); 00022 time_t seconds = time(NULL); 00023 //lcd.printf("Time: ", ctime(&seconds)); 00024 strftime(buf,16, "%H:%M:%S", localtime(&seconds)); 00025 lcd.printf(buf); 00026 myled = !myled; 00027 wait(1); 00028 00029 } 00030 } 00031 00032 void SetDateTime(int year=2013,int mon=0, int day=1, int hour=0,int min=0,int sec=0) 00033 { 00034 struct tm Clock; 00035 Clock.tm_year = year - 1900; 00036 Clock.tm_mon = mon; 00037 Clock.tm_mday = day; 00038 Clock.tm_hour = hour; 00039 Clock.tm_min = min; 00040 Clock.tm_sec = sec; 00041 time_t epoch = mktime(&Clock); 00042 if (epoch == (time_t) -1) { 00043 error("Error in clock setting\n"); 00044 // Stop here 00045 } 00046 set_time(epoch); 00047 }
Generated on Fri Jul 15 2022 11:45:47 by
1.7.2