#ifndef __usr_c #define __usr_c #include "usr.h" prog_char row_blank[17] = " \0"; prog_char row_choose[17] = " CHOOSE / ENTER \0"; prog_char row_sep[17] = "----------------\0"; //for numbers 0..9 top should be 0x30, and bottom 0x39, and start inside this range. //for chars A..Z top should be 0x31, and bottom 0x5a, and start inside this range. //for chars a..z top should be 0x61, and bottom 0x7a, and start inside this range. unsigned char usr_choose_nr(unsigned char row, unsigned char pos,unsigned char top, unsigned char bottom, unsigned char start ) { unsigned char k,c; c = start; k = NOKEY; while( (( k = readkey()) == NOKEY) || (k == KEY_UP) || (k == KEY_DOWN) ){ LCDPos(row,pos); LCDWriteByte(c); LCDPos(row,pos); if( ( k == KEY_UP ) && ( c < bottom ) ){ c++; } if( ( k == KEY_DOWN ) && ( c > top ) ){ c--; } k = NOKEY; } if( k == KEY_NAK ){ return(0); } return(c); } void printDateTime(void) { char str[18]; sprintf(str,"%02d.%02d.%04d",DAY,MONTH,YEAR); LCDPos(2,0); LCDWrite(str); sprintf(str,"%02d:%02d:%02d",HOUR,MINUTE,SECOND); LCDPos(3,0); LCDWrite(str); } int setusrDate(void) { unsigned char k,p,c; char str[12]; LCDCls(); sprintf(str,"%02d.%02d.%04d",DAY,MONTH,YEAR); LCDPos(3,0); LCDWrite(str); k = 0; p = 0; LCDPos(3,p); while( ( k = readkey()) != KEY_ACK ){ if( k == KEY_NAK ){ return(0); } if( k == KEY_LEFT ){ if( p > 0 ){ p--; if( p == 5 ){ p = 4; } if( p == 2 ){ p = 1; } LCDPos(3,p); } } if( k == KEY_RIGHT ){ if( p < 9 ){ p++; if( p == 2 ){ p = 3; } if( p == 5 ){ p = 6; } LCDPos(3,p); } } if( ( k == KEY_UP ) || ( k == KEY_DOWN ) ){ LCDPos(0,0); LCDWriteP((char *)&row_choose); c = usr_choose_nr(3, p, 0x30, 0x39, str[p] ); if( c ){ str[p] = c; } LCDCls(); LCDPos(3,0); LCDWrite(str); LCDPos(3,p); } } str[2] = 0; str[5] = 0; str[10] = 0; DAY = atoi(&str[0]); MONTH = atoi(&str[3]); YEAR = atoi(&str[6]); return(1); } int setusrTime(void) { unsigned char k,p,c; char str[12]; LCDCls(); sprintf(str,"%02d:%02d:%02d",HOUR,MINUTE,SECOND); LCDPos(3,0); LCDWrite(str); k = 0; p = 0; LCDPos(3,p); while( ( k = readkey()) != KEY_ACK ){ if( k == KEY_NAK ){ return(0); } if( k == KEY_LEFT ){ if( p > 0 ){ p--; if( p == 5 ){ p = 4; } if( p == 2 ){ p = 1; } LCDPos(3,p); } } if( k == KEY_RIGHT ){ if( p < 7 ){ p++; if( p == 2 ){ p = 3; } if( p == 5 ){ p = 6; } LCDPos(3,p); } } if( ( k == KEY_UP ) || ( k == KEY_DOWN ) ){ LCDPos(0,0); LCDWriteP((char *)&row_choose); c = usr_choose_nr(3, p, 0x30, 0x39, str[p] ); if( c ){ str[p] = c; } LCDCls(); LCDPos(3,0); LCDWrite(str); LCDPos(3,p); } } str[2] = 0; str[5] = 0; str[8] = 0; HOUR = atoi(&str[0]); MINUTE = atoi(&str[3]); SECOND = atoi(&str[6]); return(1); } #endif