TextLCD_clock using internal realtime clock function (to check VB functionality)

Dependencies:   mbed

Committer:
nxpfan
Date:
Fri Jul 02 07:35:05 2010 +0000
Revision:
1:c782bfadd12d
Parent:
0:94bb7dad733c

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nxpfan 0:94bb7dad733c 1 // This code based on
nxpfan 0:94bb7dad733c 2 // http://mbed.org/users/okano/notebook/nxp_pcf2127a-demo-code/
nxpfan 0:94bb7dad733c 3 // http://mbed.org/users/roen/notebook/real-time/
nxpfan 0:94bb7dad733c 4 //
nxpfan 0:94bb7dad733c 5 // 2010-07-02 @nxpfan
nxpfan 0:94bb7dad733c 6 // Released under the MIT License: http://mbed.org/license/mit
nxpfan 0:94bb7dad733c 7
nxpfan 0:94bb7dad733c 8 #include "mbed.h"
nxpfan 0:94bb7dad733c 9 #include "TextLCD.h"
nxpfan 0:94bb7dad733c 10
nxpfan 0:94bb7dad733c 11 TextLCD lcd(p24, p25, p26, p27, p28, p29, p30); // rs, rw, e, d0, d1, d2, d3
nxpfan 0:94bb7dad733c 12 Ticker updater;
nxpfan 0:94bb7dad733c 13
nxpfan 0:94bb7dad733c 14 void lcd_update()
nxpfan 0:94bb7dad733c 15 {
nxpfan 0:94bb7dad733c 16 struct tm dt, *dtp;
nxpfan 0:94bb7dad733c 17 time_t t;
nxpfan 0:94bb7dad733c 18 char s[ 30 ];
nxpfan 0:94bb7dad733c 19 dtp = &dt;
nxpfan 0:94bb7dad733c 20
nxpfan 0:94bb7dad733c 21 t = time( NULL );
nxpfan 0:94bb7dad733c 22 dtp = localtime( &t );
nxpfan 0:94bb7dad733c 23
nxpfan 0:94bb7dad733c 24 strftime( s, 20, "%H:%M:%S", dtp );
nxpfan 0:94bb7dad733c 25 lcd.locate( 0, 0 );
nxpfan 0:94bb7dad733c 26 lcd.printf( "%s", s );
nxpfan 0:94bb7dad733c 27
nxpfan 0:94bb7dad733c 28 strftime( s, 20, "%Y/%b/%d(%a)", dtp );
nxpfan 0:94bb7dad733c 29 lcd.locate( 0, 1 );
nxpfan 0:94bb7dad733c 30 lcd.printf( "%s", s );
nxpfan 0:94bb7dad733c 31 }
nxpfan 0:94bb7dad733c 32
nxpfan 0:94bb7dad733c 33 int main() {
nxpfan 0:94bb7dad733c 34
nxpfan 0:94bb7dad733c 35 // get the current time from the terminal
nxpfan 0:94bb7dad733c 36 struct tm t;
nxpfan 0:94bb7dad733c 37
nxpfan 1:c782bfadd12d 38 if ( 0 == time( NULL ) ) { // it should return ((time_t)-1) if it is not initialized but...
nxpfan 0:94bb7dad733c 39 lcd.locate( 0, 0 );
nxpfan 0:94bb7dad733c 40 lcd.printf( "please set time from terminal" );
nxpfan 0:94bb7dad733c 41
nxpfan 0:94bb7dad733c 42 printf("Enter current date and time:\n");
nxpfan 0:94bb7dad733c 43 printf("YYYY MM DD HH MM SS[enter]\n");
nxpfan 0:94bb7dad733c 44 scanf("%d %d %d %d %d %d", &t.tm_year, &t.tm_mon, &t.tm_mday
nxpfan 0:94bb7dad733c 45 , &t.tm_hour, &t.tm_min, &t.tm_sec);
nxpfan 0:94bb7dad733c 46
nxpfan 0:94bb7dad733c 47 // adjust for tm structure required values
nxpfan 0:94bb7dad733c 48 t.tm_year = t.tm_year - 1900;
nxpfan 0:94bb7dad733c 49 t.tm_mon = t.tm_mon - 1;
nxpfan 0:94bb7dad733c 50
nxpfan 0:94bb7dad733c 51 // set the time
nxpfan 0:94bb7dad733c 52 set_time(mktime(&t));
nxpfan 0:94bb7dad733c 53 }
nxpfan 0:94bb7dad733c 54
nxpfan 0:94bb7dad733c 55 updater.attach(&lcd_update, 1.0);
nxpfan 0:94bb7dad733c 56
nxpfan 0:94bb7dad733c 57 while (1)
nxpfan 0:94bb7dad733c 58 ;
nxpfan 0:94bb7dad733c 59 }