#include #include #include #include #include #include #include #include #define ELAPP_C167 #define ELAPP_C167_APP #include "../../ram/inc/global.h" #include "../../ram/inc/asmutil.h" #include "../../ram/inc/int.h" #include "../../ram/inc/ext/MISC.H" #include "../../ram/inc/ext/I2C_HARD.H" #include "../../ram/inc/ext/I2C_BUS.H" #include "../../ram/inc/ext/RTC.H" #include "../../ram/inc/util.c" #include "../../ram/inc/usr.c" #include "../../ram/inc/comcs.c" void comcs_do_cmd(void){ unsigned char cmd,len; int *iptr; cmd = comcs_cmd[0]; switch( cmd ){ case COMCS_CMD_GETTIME: cmd = COMCS_CMDBIN_SETTIME; len = 14; iptr = (int *)&comcs_cmd[0]; iptr[0] = YEAR; iptr = (int *)&comcs_cmd[2]; iptr[0] = MONTH; iptr = (int *)&comcs_cmd[4]; iptr[0] = DAY; iptr = (int *)&comcs_cmd[6]; iptr[0] = HOUR; iptr = (int *)&comcs_cmd[8]; iptr[0] = MINUTE; iptr = (int *)&comcs_cmd[10]; iptr[0] = SECOND; iptr = (int *)&comcs_cmd[12]; iptr[0] = MSECOND; comcs_send_bincmd( cmd, len, &comcs_cmd[0] ); break; case COMCS_CMD_REBOOT: reset_to_rom(); break; default: break; } } void comcs_do_cmdstr(void){ unsigned char cmd,par; unsigned char *ptr; cmd = comcs_cmd[0]; par = comcs_cmd[1]; ptr = &comcs_cmd[2]; switch( cmd ){ default: break; } } void comcs_do_cmdbin(void){ unsigned char cmd,len; unsigned char *ptr; int *iptr; REAL_TIME Time; cmd = comcs_cmd[0]; len = comcs_cmd[1]; ptr = &comcs_cmd[2]; switch( cmd ){ case COMCS_CMDBIN_SETTIME: stopTimerInt(); iptr = (int *)&comcs_cmd[2]; YEAR = iptr[0]; iptr = (int *)&comcs_cmd[4]; MONTH = iptr[0]; iptr = (int *)&comcs_cmd[6]; DAY = iptr[0]; iptr = (int *)&comcs_cmd[8]; HOUR = iptr[0]; iptr = (int *)&comcs_cmd[10]; MINUTE = iptr[0]; iptr = (int *)&comcs_cmd[12]; SECOND = iptr[0]; MSECOND = 0; Time.Date = INT2BCD(DAY); Time.Month = INT2BCD(MONTH); Time.Year = INT2BCD(YEAR); Time.Hour = INT2BCD(HOUR); Time.Minute = INT2BCD(MINUTE); Time.Second = INT2BCD(SECOND); if (RTCSetTime(&Time, RTCDEVICEID ) == RTC_SUCCESSFUL) { setDaysOfMonth( MONTH, YEAR ); startTimerInt(); } break; default: break; } } char lcd_txt0[18]; char lcd_txt1[18]; void main( void ) { REAL_TIME Time; unsigned char KEY,keybflag,COMCS; //Do not change //ADDRSEL1, and BUSCON1 //this can be a ramprog //It is automatically //set by startup ADDRSEL2 = 0x0806; BUSCON2 = 0xc40b; ADDRSEL3 = 0x0C06; BUSCON3 = 0x04AE; ADDRSEL4 = 0x1000; BUSCON4 = 0x060D; comcs_init; DP7_0 = OUTPUT; DP7_1 = OUTPUT; DP7_2 = OUTPUT; DP7_3 = OUTPUT; DP7_4 = OUTPUT; DP7_5 = OUTPUT; DP7_6 = OUTPUT; DP7_7 = OUTPUT; DP8_0 = OUTPUT; DP8_1 = OUTPUT; DP8_2 = OUTPUT; DP8_3 = OUTPUT; DP8_4 = OUTPUT; DP8_5 = OUTPUT; DP8_6 = OUTPUT; DP8_7 = OUTPUT; init_lcd(); lcd_clear(); YEAR = 2003; MONTH = 1; DAY = 1; HOUR = 0; MINUTE = 0; SECOND = 0; MSECOND = 0; TIMER10 = 0; THISMDAYS = 31; strcpy(lcd_txt0,"C167BLANK V 0.12"); strcpy(lcd_txt1," "); lcd_puts(0,0,lcd_txt0); lcd_puts(1,0,lcd_txt1); /////////// IEN = 1; ////////// initTimerInt(); /// here we should get date/time from rtc. /// and set YEAR ... to values if (RTCGetTime(&Time, RTCDEVICEID ) == RTC_SUCCESSFUL) { DAY = BCD2INT( Time.Date ); MONTH = BCD2INT( Time.Month ); YEAR = BCD2INT( Time.Year ); HOUR = BCD2INT( Time.Hour ); MINUTE = BCD2INT( Time.Minute ); SECOND = BCD2INT( Time.Second ); setDaysOfMonth( MONTH, YEAR ); startTimerInt(); } else { lcd_puts(1,0,"ERROR:GETTIME "); wait_10ms(100); wait_10ms(100); wait_10ms(100); lcd_puts(1,0,"RESET TIME "); Time.Date = INT2BCD(DAY); Time.Month = INT2BCD(MONTH); Time.Year = INT2BCD(YEAR); Time.Hour = INT2BCD(HOUR); Time.Minute = INT2BCD(MINUTE); Time.Second = INT2BCD(SECOND); if (RTCSetTime(&Time, RTCDEVICEID ) == RTC_SUCCESSFUL) { setDaysOfMonth( MONTH, YEAR ); startTimerInt(); } } wait_10ms(10); lcd_txt1[1] = 0; printDateTime(1); keybflag = 0; while(1){ if( comcs_timeout == 1 ){ strcpy(lcd_txt1,"UNC20 TIMEOUT "); comcs_timeout++; } if( ( COMCS = comcs_lookup() ) != COMCS_LOOKUP_NOTHING ){ switch( COMCS ){ case COMCS_LOOKUP_CMD: lcd_txt1[0] = 0; comcs_do_cmd(); break; case COMCS_LOOKUP_CMDSTR: lcd_txt1[0] = 0; comcs_do_cmdstr(); break; case COMCS_LOOKUP_CMDBIN: lcd_txt1[0] = 0; comcs_do_cmdbin(); break; case COMCS_LOOKUP_STARTS: strcpy(lcd_txt1,"UNC20 COM ACTIVE"); break; case COMCS_LOOKUP_ENDS: strcpy(lcd_txt1,"UNC20 COM CLOSED"); break; case COMCS_LOOKUP_PROGRAMEND: stopTimerInt(); IEN = 0; strcpy(lcd_txt1,"SWITCHING TO ROM"); lcd_puts(1,0,lcd_txt1); reset_to_rom(); break; default: break; } } if( ( KEY = readkey() ) != NOKEY ){ if( ! keybflag ){ keybflag = 1; strcpy(lcd_txt1,"Ext Keyb present"); } } if ( lcd_txt1[0] == 0 ){ printDateTime(1); } else { lcd_puts(1,0,lcd_txt1); } } }