CAN总线硬件连接及程序Word下载.docx
《CAN总线硬件连接及程序Word下载.docx》由会员分享,可在线阅读,更多相关《CAN总线硬件连接及程序Word下载.docx(26页珍藏版)》请在冰豆网上搜索。
12.//
CAN1.c
CAN2.c
are
a
simple
example
of
configuring
CAN
network
to
13.//
transmit
receive
data
on
network,
how
move
information
14.//
from
RAM
message
objects.
Each
C8051F040-TB
node
is
configured
15.//
send
when
it'
s
P3.7
button
depressed/released,
with
0x11
16.//
indicate
the
pushed,
0x00
released.
also
has
17.//
object
messages.
The
C8051
tests
18.//
received
will
turn
on/off
target
board'
LED.
When
one
19.//
loaded
other
CAN1.c,
20.//
push-button
control
LED,
establishing
21.//
link
via
bus
can
be
observed
directly
22.//
boards.
23.////////////////////////////////////////////////////////////////////////////////
24.
25.////////////////////////////////////////////////////////////////////////////////
26.//
Includes
27.////////////////////////////////////////////////////////////////////////////////
28.
29.#include
<
c8051f040.h>
//
SFR
declarations
30.
31.//
Protocol
Register
Index
for
CAN0ADR,
TABLE
18.1
32.//
datasheet
33.////////////////////////////////////////////////////////////////////////////////
34.#define
CANCTRL
//Control
35.#define
CANSTAT
0x01
//Status
register
36.#define
ERRCNT
0x02
//Error
Counter
37.#define
BITREG
0x03
//Bit
Timing
38.#define
INTREG
0x04
//Interrupt
Low
Byte
39.#define
CANTSTR
0x05
//Test
40.#define
BRPEXT
0x06
//BRP
Extension
41.////////////////////////////////////////////////////////////////////////////////
42.//IF1
Interface
Registers
43.////////////////////////////////////////////////////////////////////////////////
44.#define
IF1CMDRQST
0x08
//IF1
Command
Rest
45.#define
IF1CMDMSK
0x09
Mask
46.#define
IF1MSK1
0x0A
Mask1
47.#define
IF1MSK2
0x0B
Mask2
48.#define
IF1ARB1
0x0C
Arbitration
1
49.#define
IF1ARB2
0x0D
2
50.#define
IF1MSGC
0x0E
Message
Control
51.#define
IF1DATA1
0x0F
Data
A1
52.#define
IF1DATA2
0x10
A2
53.#define
IF1DATB1
B1
54.#define
IF1DATB2
0x12
B2
55.////////////////////////////////////////////////////////////////////////////////
56.//IF2
57.////////////////////////////////////////////////////////////////////////////////
58.#define
IF2CMDRQST
0x20
//IF2
59.#define
IF2CMDMSK
0x21
60.#define
IF2MSK1
0x22
61.#define
IF2MSK2
0x23
62.#define
IF2ARB1
0x24
63.#define
IF2ARB2
0x25
64.#define
IF2MSGC
0x26
65.#define
IF2DATA1
0x27
66.#define
IF2DATA2
0x28
67.#define
IF2DATB1
0x29
68.#define
IF2DATB2
0x2A
69.////////////////////////////////////////////////////////////////////////////////
70.//Message
Handler
71.////////////////////////////////////////////////////////////////////////////////
72.#define
TRANSREQ1
0x40
//Transmission
Rest1
73.#define
TR