#include "usr.h" int usrGetDateTime( void ) { char tmp1[20]; char tmp2[20]; unsigned char KEY,x,y; int ret,newday,newmonth,newyear,newhour,newminute,newsecond; ret = 0; lcd_clear(); sprintf(tmp1,"Date %02d.%02d.%04d",(int)DAY,(int)MONTH,(int)YEAR); sprintf(tmp2,"Time %02d:%02d:%02d",(int)HOUR,(int)MINUTE,(int)SECOND); lcd_puts(0,0,tmp1); lcd_puts(1,0,tmp2); KEY = 0; x = 6; y = 0; while(KEY != KEY_E ){ if(KEY == KEY_C ){ lcd_clear(); return(ret); } KEY = 0; lcd_puts(0,0,tmp1); lcd_puts(1,0,tmp2); lcd_setcursor(y,x); while(! KEY ) { KEY = readkey(); } if(KEY == KEY_UP ){ if(y == 1){ y = 0; x = 6; } continue; } if(KEY == KEY_DOWN ){ if(y == 0){ y = 1; x = 6; } continue; } if(KEY == KEY_LEFT ){ if(x > 6 ){ x--; } if(x == 11 ){ x--; } if(x == 8){ x--; } continue; } if( ( KEY >= KEY_0 ) && ( KEY <= KEY_9 ) ){ if( y == 0 ) { tmp1[x] = KEY; } else { tmp2[x] = KEY; } KEY = 'R'; } if(KEY == KEY_RIGHT );{ x++; if(x == 8 ){ x++; } if(x == 11){ x++; } if(x > 15){ x--; } if( y == 1 ) { if(x > 13){ x--; } } continue; } } tmp1[8] = 0; tmp1[11] = 0; tmp2[8] = 0; tmp2[11] = 0; newday = atoi(&tmp1[6]); newmonth = atoi(&tmp1[9]); newyear = atoi(&tmp1[12]); newhour = atoi(&tmp2[6]); newminute = atoi(&tmp2[9]); newsecond = atoi(&tmp2[12]); if( ( newday > 0 ) && ( newday < 32 ) ){ if( ( newmonth > 0 ) && ( newmonth < 13 ) ) { if( newhour < 24 ) { if( newminute < 60 ) { if( newsecond < 60 ) { DAY = newday; MONTH = newmonth; YEAR = newyear; HOUR = newhour; MINUTE = newminute; SECOND = newsecond; ret = 1; } } } } } lcd_clear(); return( ret ); } void printDateTime( unsigned char row ) { char tmp1[20]; sprintf(tmp1,"%02d.%02d.%04d %02d:%02d", (int)DAY, (int)MONTH, (int)YEAR, (int)HOUR, (int)MINUTE); lcd_puts(row,0,tmp1); }