#include #include #include #define F3 131 int init8(); int showdata(); int hextobi(char *, unsigned char *); int main() { int key, message; static char st[]="Press F3"; InstallCom2(115200L,8,0); initLCD(); clrLCD(); LCDPrintf("%s",st); for(;;) { if(Kbhit()) { key=Getch(); Print("[%d]",key); if(key=='Q') { ToCom2(key); break; } else if(key==F3) { ToCom2(key); init8(); } else ToCom2(key); } showdata(); } WaitTransmitOver2(); RestoreCom2(); closeLCD(); return 0; } int init8() { clrLCD(); for(;;) { if(Kbhit()) { int key=Getch(); Print("[%d]",key); if(key=='Q') { ToCom2(key); break; } else ToCom2(key); } if(IsCom2()) { int message=ReadCom2(); if(message<129) LCDPrintf("%c",message); else break;//when receive F3 from 8k then break->quit } } loadBMP("iview.bmp"); showBMP1(); return 0; } int showdata() { int message2; int count=0; unsigned char data[40]; clrLCD(); for(;;) { if(IsCom2()) //read from 8k { message2=ReadCom2(); if(message2!=13)//DI value from 8k, ready to show, 4 bytes, 2 for DO, 2 for DI data[count++]=message2; else //data send finished, ready to show { unsigned char temp[5]; char tt[17]; data[count]=0; count=0; temp[0]=data[0]; temp[1]=data[1]; temp[2]=data[2]; temp[3]=data[3]; hextobi(tt,data); textoutT(1,2,"DO value"); textoutT(1,3,tt); temp[0]=data[4]; temp[1]=data[5]; temp[2]=data[6]; temp[3]=data[7]; textoutT(1,5,"DI value"); hextobi(tt,temp); textoutT(1,6,tt); } } if(Kbhit()) break;//quit from this subroutine } return 0; } int hextobi(char tt[],unsigned char ydl[]) { int i,j,value; // char tt[17]; for(i=0;i<4;i++) { if(isupper(ydl[i])) value=ydl[i]-'A'+10; else if( islower(ydl[i])) value=ydl[i]-'a'+10; else if(isdigit(ydl[i])) value=ydl[i]-'0'; for(j=3;j>=0;j--) { if(value%2) tt[i*4+j]='1'; else tt[i*4+j]='0'; value>>=1; } } tt[16]=0; return 0; }