#include #include int I8054_do=0,I8054_di=0,I8054_do_old=1,I8054_di_old=1; void R8054() { int i; if(I8054_do != I8054_do_old) { for(i = 0 ; i < 8 ; i++) { LcdPrintfAt(4+i,3,"%d",(I8054_do>>i)&0x1); } I8054_do_old = I8054_do; } if(I8054_di != I8054_di_old) { for(i = 0 ; i < 8 ; i++) { LcdPrintfAt(4+i,4,"%d",(I8054_di>>i)&0x1); } I8054_di_old = I8054_di; } } void process_key(int get_key) { static int do_ch; int lcd_page,do_state; lcd_page = GetLCDPage(); if(lcd_page == 1) { LcdPrintfAt(12,6,"%c",get_key); if(get_key > '0' && get_key < '9') { do_ch = get_key-0x31; LCDSetToPage(2); ClrScrn(); LcdPrintfAt(1,1,"DO%d:",do_ch+1); do_state = (I8054_do >> do_ch) & 0x1; if(do_state) TextOutAt(5,1,"ON "); else TextOutAt(5,1,"OFF"); SetCursorAt(13,5); TextOutAt(1,3,"Key 1 : ON"); TextOutAt(1,4,"Key 2 : OFF"); TextOutAt(1,5,"Press Key :"); TextOutAt(12,8,"QUIT"); UnderLine(12,8,1,1); } } else if(lcd_page == 2) { LcdPrintfAt(13,5,"%c",get_key); if(get_key == '1') { I8054_do = I8054_do | (1 <<(do_ch)); SetCursorAt(12,6); LCDSetToPage(1); } else if(get_key == '2') { I8054_do = I8054_do & ~(1 <<(do_ch)); SetCursorAt(12,6); LCDSetToPage(1); } } } int main() { int key,comu_conf=0; long value,value1; InitLib(); InitLCD(); TimerOpen(); InstallCom1(115200L,8,0,1); SetCursorLine(2); SetCursorAt(12,6); TextOutAt(1,1,"I-8054"); TextOutAt(1,2," 12345678"); TextOutAt(1,3,"DO:"); TextOutAt(1,4,"DI:"); TextOutAt(1,5,"Change DO state"); TextOutAt(1,6,"Press 1-8 :"); TextOutAt(12,8,"QUIT"); UnderLine(12,8,1,1); value = GetTimeTicks(); value1 = GetTimeTicks(); for(;;) { if(Kbhit()) { key=Getch(); if(key=='Q' || key=='q') { break; } else process_key(key); } StopWatchReadValue(0,&value); if((value + 50) < GetTimeTicks()) { value = GetTimeTicks(); ToCom1(I8054_do); } if(IsCom1()) { comu_conf = 1; value1 = GetTimeTicks(); I8054_di=ReadCom1(); } if((value1 + 500) < GetTimeTicks()) comu_conf =0; if(GetLCDPage() == 1) R8054(); if(comu_conf) TextOutAt(10,1," OnLine"); else TextOutAt(10,1,"OFFLine"); } WaitTransmitOver1(); RestoreCom1(); CloseLCD(); return 0; }