#include #include #include "..\lib\7188.h" /* ------------------------------------------------------------------- */ void main() { int i1,i2,j,val; char c; InitLib(); /* driver initial */ InstallCom(1,57600L,8,0,1); /* COM1, RS-485, half-duplex mode, INT */ /* --> need to control 485 direction */ /* --> initial 485 direction = Receive */ /* Note : JP1 must select RS-485 */ InstallCom(2,57600L,8,0,1); /* COM2, RS-485, half-duplex mode, INT */ /* --> need to control 485 direction */ /* --> initial 485 direction = Receive */ /* COM4, RS-232, connect to PC's COM port for download */ Init5DigitLed(); /* initial & blank the 5-digit LED */ i1=i2=0; j=0; LedOn(); /* red-LED on */ for (;;) { if (IsCom(1)!=0) /* is COM1 receive any data ? */ if (IsCom(1)==QueueIsNotEmpty) /* is COM1 receive any data ? */ { /* Yes, receive some data */ val=ReadCom(1); /* read one character from COM1 */ Set485DirToTransmit(1); /* change 485 direction to Transmit */ ToCom(1,val); /* send this character back to COM1 */ /* --> you will see this character in PC's monitor*/ WaitTransmitOver(1); /* wait this character transmit over */ Set485DirToReceive(1); /* change 485 direction to Receive */ Show5DigitLed(4,val-'0'); i1++; i1=i1&0x07; Show5DigitLed(1,i1); j++; j=j&0x01; if (j==0) LedOn(); else LedOff(); } if (IsCom(2)==QueueIsNotEmpty) /* is COM2 receive any data ? */ { /* Yes, receive some data */ val=ReadCom(2); /* read one character from COM2 */ Set485DirToTransmit(2); /* change 485 direction to Transmit */ ToCom(2,val); /* send this character back to COM2 */ /* --> you will see this character in PC's monitor */ WaitTransmitOver(2); /* wait this character transmit over */ Set485DirToReceive(2); /* change 485 direction to Receive */ Show5DigitLed(5,val-'0'); i2++; i2=i2&0x07; Show5DigitLed(2,i2); j++; j=j&0x01; if (j==0) LedOn(); else LedOff(); } 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(1); RestoreCom(2); return; } } } }