Kenji Arai / Mbed 2 deprecated RTC_tst

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 //
00002 // RTC Test Program
00003 //          Kenji Arai / JH1PJL
00004 //          March 27th,2010  Started
00005 //          March 27th,2010  
00006 //
00007 #include "mbed.h"
00008 #include "TextLCD.h"
00009 
00010 #define TIME_KEEP_AS_IS
00011 //#define STYLE1
00012 #define STYLE2
00013 
00014 DigitalOut myled1(LED1);                                // Assign LED1 output port
00015 TextLCD lcd(p22, p28, p27, p26, p25, p24, p23, 40, 2);  // rs,rw,e,d0,d1,d2,d3,40char's x 2 lines
00016 
00017 int main() {
00018     char buf[40];
00019     time_t seconds;
00020 
00021 #ifndef TIME_KEEP_AS_IS
00022     // setup time structure for 27 March 2010 13:24:00
00023     struct tm t;
00024     t.tm_sec = 00;    // 0-59
00025     t.tm_min = 24;    // 0-59
00026     t.tm_hour = 13;   // 0-23
00027     t.tm_mday = 27;   // 1-31
00028     t.tm_mon = 3;     // 0-11
00029     t.tm_year = 110;  // year since 1900
00030     seconds = mktime(&t);
00031     set_time(seconds);
00032 #endif
00033     lcd.cls();
00034     lcd.locate(0, 0);
00035     lcd.locate(0, 0);   // 1st line top    
00036     lcd.printf("since Jan.1,1970 = %d\n", seconds);
00037     wait(2.0);
00038     // If you have implemented the "Windows USB Serial Port Driver", you can use follows.
00039     // http://mbed.org/projects/handbook/wiki/WindowsSerialConfiguration
00040     printf("\r\n  Start RTC Test Program\r\n ");
00041 #ifdef TIME_KEEP_AS_IS
00042     printf("Defined TIME_KEEP_AS_IS\r\n");
00043 #else
00044     printf("Not define TIME_KEEP_AS_IS\r\n");
00045 #endif
00046     for(;;){
00047         myled1 = 1;
00048         wait(0.5);
00049         myled1 = 0;
00050         wait(0.5);
00051         seconds = time(NULL);       
00052         lcd.cls();
00053         lcd.locate(0, 0);   // 1st line top
00054         lcd.printf("It is %d sec since Jan.1,1970\n", seconds); 
00055         lcd.locate(0, 1);   // 2nd line top
00056  #ifdef STYLE1
00057         //                  27 Mar 2010 13:24:00
00058         strftime(buf,40, "%x %X \n", localtime(&seconds));
00059  #endif
00060  #ifdef STYLE2
00061         //                 13:24:00 PM (2010/03/27)
00062         strftime(buf,40, "%I:%M:%S %p (%Y/%m/%d)\n", localtime(&seconds));
00063  #endif
00064         lcd.printf("Time = %s", buf);
00065         printf("Time = %s\r", buf);
00066     }
00067 }
00068