#include #include #include #include "..\lib\7188.h" int ascii_to_hex(char c); int read_MMICON(char cmd[]); int set_MMICON(int k, char cmd[]); int read_7000(int k, char cmd[]); int find_key(int i); /* address 1 : MMICON, connect to COM2 or 7188 address 2 : MMICON, connect to COM2 or 7188 address 3 : MMICON, connect to COM2 or 7188 address 4 : 7011, connect to COM2 or 7188 address 5 : 7013, connect to COM2 or 7188 */ /* ------------------------------------------------------------------- */ void main() { int i,j,k; char c,str[80]; InitLib(); /* driver initial */ InstallCom(2,9600L,8,0,1); /* COM2, RS-485, half-duplex mode, INT */ /* --> need to control 485 direction */ /* --> initial 485 direction = Receive */ /* --> address 1-3 = MMICON */ /* --> address 5 = 7011 */ /* --> address 6 = 7013 */ /* COM4, RS-232, connect to PC's COM port for download */ Init5DigitLed(); /* initial & blank the 5-digit LED */ LedOn(); /* red-LED on */ j=0; for (;;) { j++; j=j&0x01; if (j==0) LedOn(); else LedOff(); i=read_MMICON("$01K"); /* key pressed ? (for MMICOn address-1) */ if (i>0) /* yes, some key is pressed */ { k=find_key(i); /* read this key */ set_MMICON(k,"$01P00"); /* change to PAGE_key */ printf("\n[1] : select page_%d",k); /* show to COM4=PC's monitor */ Show5DigitLed(1,1); /* show in 5-digit led for debug */ } i=read_MMICON("$02K"); /* key pressed ? (for MMICOn address-2) */ if (i>0) /* yes, some key is pressed */ { k=find_key(i); /* read this key */ set_MMICON(k,"$02P00"); /* change to PAGE_key */ printf("\n[2] : select page_%d",k); /* show to COM4=PC's monitor */ Show5DigitLed(1,2); /* show in 5-digit led for debug */ } i=read_MMICON("$03K"); /* key pressed ? (for MMICOn address-3) */ if (i>0) /* yes, some key is pressed */ { k=find_key(i); /* read this key */ set_MMICON(k,"$03P00"); /* change to PAGE_key */ printf("\n[3] : select page_%d",k); /* show to COM4=PC's monitor */ Show5DigitLed(1,3); /* show in 5-digit led for debug */ } read_7000(4,"$04M"); /* read module name of address-4 */ read_7000(5,"$05M"); /* read module name of address-5 */ DelayTimeMs(100); /* for led_of_off display delay */ if (kbhit()) /* is user press PC's keyboard from COM4 */ { c=getch(); /* if this key is Q or Q --> exit this program */ if ((c=='q') || (c=='Q')) { RestoreCom(2); return; } } } } /* ------------------------------------------------------------------- */ int read_MMICON(char cmd[]) { char str[80],h,l,val,len; /* send $AAK --> receive $AA0[0x0d] if no key-pressed */ /* send $AAK --> receive $AA0??[0x0d] if key-pressed */ SendCmdTo7000(2, cmd, 0); /* send cmd to MMICON */ val=ReceiveResponseFrom7000(2, str, 60000L, 0); /* receive result from MMICON */ if (val==NoError) { len=strlen(str); /* printf("\nSend=%s, Receive=%s, len=%d",cmd,str,len); */ if (len<=4) return(-1); h=ascii_to_hex(str[4]); l=ascii_to_hex(str[5]); val=h*16+l; return(val); } printf("(Error1)"); /* for debug */ return(val); } int find_key(int i) /* this is default key-code for MMICON */ { switch(i) { case 0x01 : return(0); case 0x04 : return(1); case 0x05 : return(2); case 0x06 : return(3); case 0x08 : return(4); case 0x09 : return(5); case 0x0A : return(6); case 0x0C : return(7); case 0x0D : return(8); case 0x0E : return(9); default : return(0); } } /* ------------------------------------------------------------------- */ int set_MMICON(int k, char cmd[]) /* change LCD_DISPLAY of MMICON to PAGE_K */ { char str[80],h,l,val,len,ret; /* send $AAP?? --> change to page ?? */ l=k&0x0f; k=k>>4; h=k&0x0f; Show5DigitLed(2,h); Show5DigitLed(3,l); l=hex_to_ascii[l]; h=hex_to_ascii[h]; cmd[4]=h; cmd[5]=l; SendCmdTo7000(2, cmd, 0); val=ReceiveResponseFrom7000(2, str, 60000L, 0); if (val<0) printf("(Error2)"); return(val); } /* ------------------------------------------------------------------- */ int read_7000(int k, char cmd[]) /* send cmd & receive result to 7000 module */ { char str[80],h,l,val,len; SendCmdTo7000(2, cmd, 0); val=ReceiveResponseFrom7000(2, str, 60000L, 0); if (val==NoError) { /* send $AAM --> !AA701? */ printf("\nSend=%s, Receive=%s",cmd,str); l=ascii_to_hex(str[6]); Show5DigitLed(k,l); return(0); } printf("(Error3)"); return(-1); }