//#define Debug /****************************************************************** * DESCRIPTION: Can Example * SOURCE: cannode2.c * Date: 10-16-2005 * AUTHOR: Jianjian Song * Reference: Embedded Systems by Steven Barrett and Daniel Pack, ******************************************************************/ #include "can.h" //================ can node 2 ================================== // Receive a "on" and "off" message from another node to control an LED //=============================================================== ulong busclk; void SetClockSpeed(); // hardware interface #define Light Pim.ptm.bit.ptm3 #define LightPortDirection Pim.ddrm.bit.ddrm3=1 #define TurnOnLight Light=0; #define TurnOffLight Light=1; /* Main Routine */ void main () { uchar SwitchState; // 0 for OFF and 1 for ON LightPortDirection; SEI(); // Disable Interrupts SetLedindicator(); CLI(); // enable I bit interrupts #ifndef Debug SetClockSpeed(); busclk = oscclk/2; // Set Bus Freq. = (1/2) * Oscillator Freq. (void) InitSCI(BaudRate); // Initialize SCI module (void) printf("\n\r*********************************************\n\r\n\r"); (void) printf("ECE331 Fall 2005\n\r"); (void) printf("Jianjian Song\n\r"); (void) printf("Initializing MSCAN .....\n\r"); #endif (void) can_initialize(); #ifndef Debug (void) printf("\n\r***MSCAN has been initialized successfully ***\n\r"); #endif #ifndef Debug (void) printf("\n\r***I am Node 2, waiting to receive a switch control command***\n\r"); #endif TurnOnLight; for (;;) { can_receive_message(&SwitchState); switch (SwitchState) { case 0: TurnOffLight; break; case 1: TurnOnLight; break; case 2: break; default: break; } } #ifndef Debug printf("\n\rEnd of Can Message Exchange\n\r"); #endif while(1); }