1、1.// F04x_CAN1.c 2.//------------------------------------------------------------------------------ 3.// 4.// 5.// DEVICE: C8051F040 6.// 7.// AUTHOR: LS 8.// 9.// TOOLS: Keil C-compiler and Silicon Labs IDE 10.// 11.// 12.// CAN1.c and CAN2.c are a simple exam
2、ple of configuring a CAN network to 13.// transmit and receive data on a CAN network, and how to move information to 14.// and from CAN RAM message objects. Each C8051F040-TB CAN node is configured 15.// to send a message when it's P3.7 button is depressed/released, with a 0x1
3、1 16.// to indicate the button is pushed, and 0x00 when released. Each node also has 17.// a message object configured to receive messages. The C8051 tests the 18.// received data and will turn on/off the target board's LED. When one target 19.// is loaded with CAN2.c and the
4、 other is loaded with CAN1.c, one target 20.// board's push-button will control the other target board's LED, establishing 21.// a simple control link via the CAN bus and can be observed directly on the 22.// target boards. 23./////////////////////////////////////////////////
5、/////////////////////////////// 24. 25.//////////////////////////////////////////////////////////////////////////////// 26.// Includes 27.//////////////////////////////////////////////////////////////////////////////// 28. 29.#include
6、 // SFR declarations 30. 31.// CAN Protocol Register Index for CAN0ADR, from TABLE 18.1 of the C8051F040 32.// datasheet 33.//////////////////////////////////////////////////////////////////////////////// 34.#define CANCTRL 0x00 //Control Registe