#include #include "..\..\lib\7186e.h" #include "..\..\lib\xc100.h" /*If the UserCANInt() function is not used, please don't remove it.*/ void UserCANInt(char CANInt){ if (CANInt) ; /*avoid complier warning*/ } void main(void) { int ret,i=0; InitLib(); /*******************************************************/ /* initialize and configure the CAN controller */ /*******************************************************/ ret=XC100Init(1,0,125000UL,0,0,0x00000000UL,0xffffffffUL); /* XCANInit function Parameter descriptions 1 : for 7186EX(D) model number (7188XB(D) model number is 0) 0 : for IntMode useless 125000UL : for CAN baud 0 : for BT0 of user defined baud 0 : for BT1 of user defined baud 0x00000000UL : for AccCode of CAN message filter 0xffffffffUL : for AccMask of CAN message filter */ switch (ret){ /*Check if configuration is OK*/ case CAN_ResetError: Print("Reset Error!\n\r"); return; case CAN_SetACRError: Print("\n\rSet ACR Error!"); return; case CAN_SetAMRError: Print("\n\rSet AMR Error!"); return; case CAN_SetBaudRateError: Print("\n\rSet Baud Rate Error!"); return; case CAN_BaudNotSupport: Print("\n\rBaud Rate Not Support!"); return; case CAN_ConfigError: Print("\n\rConfiguration Failure!"); return; default: if (ret >0){ Print("Default=%d\n\r",ret); return; } } /********************************************************/ /* Initial all LEDs */ /********************************************************/ Print("Press any key to exit the program.\n\r"); while(1){ switch(i){ case 0: L1On(); L2Off(); L3Off(); break; case 1: L1Off(); L2On(); L3Off(); break; case 2: L1Off(); L2Off(); L3On(); } if (++i==3) i=0; DelayMs(500); if (Kbhit()){ /*if press any key, exit the program*/ Print("Exit this program!\n"); break; } } L1Off(); L2Off(); L3Off(); CAN_Restore(); }