#include #include "7186E\7186e.h" #include "CCON\CCON.h" void main(void) { int ret,i; unsigned char MsgData[8],DI[8],Status,c; unsigned char NodeID, DO[8]; unsigned char TotalByteCount; //unsigned long MsgID,MsgUpperTimeStamp,MsgLowerTimeStamp,MsgCnt=0; InitLib(); NodeID = 0x0A; XSCCON_Init(1000000UL,0,0,0x00000000UL,0xffffffffUL); //Set the heartbeat of the Host //if the parameter is 0, it will disable the heartbeat mechanism. XSCCON_SetHostHeartbeat(10); XSCCON_SetModuleConfig(NodeID, 8, 8, 0, 0, 0, 0); //8-DI/8-DO XSCCON_SetAutoRespData(NodeID, 50); //Set I/O module replies data every 50ms XSCCON_SetModuleHeartbeatTimeout(NodeID, 100); //Set the host heartbeat timeout of the modules //if the parameter is 0, it will disable the heartbeat mechanism. /********************************************************/ /* Initial all LEDs */ /********************************************************/ L1Off(); L2Off(); L3Off(); while(1) { XSCCON_Main(); XSCCON_ModuleStatus(NodeID,&Status); if(Status == 0) { XSCCON_ReadDI(NodeID, &TotalByteCount, DI); Print("DI = %02X \r",DI[0]); } else { Print("%02X Timeout \r",NodeID); } c = Kbhit(); if (c) { /*if press any key, exit the program*/ switch(c) { case 'A': MsgData[0] = 0xFF; TotalByteCount = 1; XSCCON_WriteDO(NodeID, TotalByteCount, MsgData); Getch(); break; case 'B': XSCCON_WriteDOBit(NodeID, 2, 0); Getch(); break; case 'C': XSCCON_ReadbackDO(NodeID, &TotalByteCount, DO); Print("DO = %02X \r\n",DO[0]); Getch(); break; case 'D': DO[0] = 0xAA; TotalByteCount = 1; XSCCON_WriteDO(NodeID, TotalByteCount, DO); Getch(); break; case 'E': DO[0] = 0x55; TotalByteCount = 1; XSCCON_WriteDO(NodeID, TotalByteCount, DO); Getch(); break; case 'F': DO[0] = 0x00; TotalByteCount = 1; XSCCON_WriteDO(NodeID, TotalByteCount, DO); Getch(); break; default: Print("Exit this program!\n"); XSCCON_Restore(); return; } } } } void UserFunc_CANStatusError(unsigned char CANChip_RegisterStatus) { Print("CAN Error : %02X\r\n",CANChip_RegisterStatus); //Light on the LED or show some error message }