#include #include #include #include #include #include #include #include #define ELAPP_C167 #define ELAPP_C167_BASE #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" #include "serctrl.c" const char main_txt0[18] = " C167 BLANK\0"; const char main_txt1[18] = " VERSION 1.00\0"; const char main_txt2[18] = " E. Benninghaus\0"; const char main_txt3[18] = " Rottweil 2004\0"; const char menu_txt[12][18] = { " SET DATE-TIME\0", " RESERVED 01\0", " RESERVED 02\0", " RESERVED 03\0", " RESERVED 04\0", " RESERVED 05\0", " RESERVED 06\0", " RESERVED 07\0", " RESERVED 08\0", " RESERVED 09\0", " RESERVED 10\0", " SERIAL CTRL.\0" }; #define MAINMENULASTOFFSET 9 void main( void ) { REAL_TIME Time; unsigned char KEY; unsigned char y,_y,upd,cf; int cmd; ADDRSEL1 = 0x0406; BUSCON1 = 0x04AE; ADDRSEL2 = 0x0806; BUSCON2 = 0xc40b; ADDRSEL3 = 0x0C06; BUSCON3 = 0x04AE; ADDRSEL4 = 0x1000; BUSCON4 = 0x060D; DP2_8 = INPUT; DP2_9 = INPUT; DP2_10 = INPUT; DP2_11 = INPUT; DP2_12 = OUTPUT; 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; lcd_puts(0,0,main_txt0); lcd_puts(1,0,main_txt1); lcd_puts(2,0,main_txt2); lcd_puts(3,0,main_txt3); /////////// 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(); } wait_10ms(100); wait_10ms(100); lcd_clear(); wait_10ms(1); cf = 'X'; y = 0; _y = 0; upd = 1; while(1){ if( upd ) { lcd_clear(); lcd_puts(0,0,menu_txt[ y + 0 ]); lcd_puts(1,0,menu_txt[ y + 1 ]); lcd_puts(2,0,menu_txt[ y + 2 ]); upd = 0; } printDateTime(3); lcd_setcursor(_y,0); lcd_putchar( cf ); KEY = readkey(); if(KEY == KEY_DOWN ){ lcd_setcursor(_y,0); lcd_putchar(' '); if(_y < 2 ){ _y++; } else { if( y < MAINMENULASTOFFSET ){ y++; upd = 1; } _y = 2; } continue; } if(KEY == KEY_UP ){ lcd_setcursor(_y,0); lcd_putchar(' '); if( _y > 0 ){ _y--; } else { if( y > 0 ){ y--; upd = 1; } _y = 0; } continue; } if(KEY == KEY_E ){ cmd = y + _y; switch( cmd ) { case 0: // set date-time stopTimerInt(); if( usrGetDateTime() ){ //Time.Weekday = THURSDAY; 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(); } } else { startTimerInt(); } break; case 1: // reserved 01 break; case 2: // reserved 02 break; case 3: // reserved 03 break; case 4: // reserved 04 break; case 5: // reserved 05 break; case 6: // reserved 06 break; case 7: // reserved 07 break; case 8: // reserved 08 break; case 9: // reserved 09 break; case 10: // reserved 10 break; case 11: serialcontrol(); break; } upd = 1; } } }