#include #include #include "..\..\lib\7188.h" /* ------------------------------------------------------------------- */ void main() { int i,i1,i2,j,val,t; 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 */ for (j=0; j<8; j++) for (i=0; i<256; i+=16) { t=ReadEEP(j,i); printf("\nRead EEPROM : block=%x,addr=%x,data=%x",j,i,t); if (t!=((i+j)&0xff)) printf("\7"); } printf("\n"); for (i=0; i<31; i++) { t=ReadNVRAM(i); /* read back NVRAM for check */ printf("\nRead NVSRAM : addr=%x,data=%x",i,t); if (i!=t) printf("\7"); } i1=i2=0; j=0; for (;;) { LedOn(); Set485DirToTransmit(2); ToCom(2,0x5A); WaitTransmitOver(2); Set485DirToReceive(2); i=0; while (IsCom(1)==0) { i++; if (i>30000) printf("\nCOM2 send 5A --> COM1 no respons"); goto next_2; } val=ReadCom(1); printf("\nCOM2 send 5A --> COM1 receive %x",val); next_2: Set485DirToTransmit(2); ToCom(2,0xA5); WaitTransmitOver(2); Set485DirToReceive(2); i=0; while (IsCom(1)==0) { i++; if (i>30000) printf("\nCOM2 send A5 --> COM1 no respons"); goto next_3; } val=ReadCom(1); printf("\nCOM2 send A5 --> COM1 receive %x",val); next_3: DelayTimeMs(500); LedOff(); Set485DirToTransmit(1); ToCom(1,0x5A); WaitTransmitOver(1); Set485DirToReceive(1); i=0; while (IsCom(2)==0) { i++; if (i>30000) printf("\nCOM1 send 5A --> COM2 no respons"); goto next_4; } val=ReadCom(2); printf("\nCOM1 send 5A --> COM2 receive %x",val); next_4: Set485DirToTransmit(1); ToCom(1,0xA5); WaitTransmitOver(1); Set485DirToReceive(1); i=0; while (IsCom(2)==0) { i++; if (i>30000) printf("\nCOM1 send A5 --> COM2 no respons"); goto next_5; } val=ReadCom(2); printf("\nCOM1 send A5 --> COM2 receive %x",val); next_5: 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; } } DelayTimeMs(500); } }