📄 接收.lst
字号:
C51 COMPILER V7.50 接收 01/15/2009 10:48:31 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE 接收
OBJECT MODULE PLACED IN 接收.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE 接收.c BROWSE DEBUG OBJECTEXTEND
line level source
1 #include <c8051f040.h> // SFR declarations
2 #include "can.h"
3
4
5 ////////////////////////////////////////////////////////////////////////////////
6 //Global Variables
7 ////////////////////////////////////////////////////////////////////////////////
8 char MsgNum;
9 char status;
10 char receivedata;
11 char transmitdata;
12 int i;
13 int MOTwoIndex = 0;
14 int MOOneIndex = 0;
15 int StatusCopy;
16 int RXbuffer [4];
17 int TXbuffer [8];
18 int MsgIntNum;
19 int Temperature;
20 sbit BUTTON = P3^4;
21 sbit BUTTON1= P3^5;
22 sbit BUTTON2= P3^6;
23 sbit BUTTON3= P3^7;
24 sbit LED = P1^6;
25
26
27 data unsigned char temppage;
28
29 ////////////////////////////////////////////////////////////////////////////////
30 // Function PROTOTYPES
31 ////////////////////////////////////////////////////////////////////////////////
32
33 // Initialize Message Object
34
35 void transmit_data(char MsgNum);
36 void receive_data (char MsgNum);
37 void external_osc (void);
38 void config_IO (void);
39
40 void delay(int tim);
41 void uart_init();
42 void time_init();
43
44 void delay(int tim)
45 { int i,j;
46 1 for(i=0;i<tim;i++)
47 1 {for(j=0;j<i;j++);}
48 1 }
49 ////////////////////////////////////////////////////////////////////////////////
50 // MAIN Routine
51 ////////////////////////////////////////////////////////////////////////////////
52 void main (void) {
53 1
54 1 // disable watchdog timer
55 1 WDTCN = 0xde;
C51 COMPILER V7.50 接收 01/15/2009 10:48:31 PAGE 2
56 1 WDTCN = 0xad;
57 1 uart_init();
58 1 time_init();
59 1
60 1 //configure Port I/O
61 1 config_IO();
62 1
63 1 // switch to external oscillator
64 1 external_osc();
65 1
66 1
67 1 ////////////////////////////////////////////////////////////////////////////////
68 1 // Configure CAN communications
69 1 //
70 1 // IF1 used for procedures calles by main program
71 1 // IF2 used for interrupt service procedure receive_data
72 1 //
73 1 // Message Object assignments:
74 1 // 0x02: Used to transmit commands to toggle its LED, arbitration number 1
75 1 //
76 1 ////////////////////////////////////////////////////////////////////////////////
77 1
78 1 // Clear CAN RAM
79 1 clear_msg_objects();
80 1
81 1 // Initialize message object to transmit data
82 1 init_msg_object_TX (0x02,2);
83 1
84 1 // Initialize message object to receive data
85 1 init_msg_object_RX (0x01,1);
86 1
87 1 // Enable CAN interrupts in CIP-51
88 1 EIE2 = 0x20;
89 1
90 1 //Function call to start CAN
91 1 start_CAN();
92 1
93 1 //Global enable 8051 interrupts
94 1 EA = 1;
95 1 IE=0x90;
96 1 IP=0x00;//uart0中断优先级为低
97 1 EIP2=0x20;//can0中断优先级为高
98 1
99 1 while(1);
100 1 }
101
102
103 ////////////////////////////////////////////////////////////////////////////////
104 // Set up C8051F040
105 ////////////////////////////////////////////////////////////////////////////////
106
107 // Switch to external oscillator
108 void external_osc (void)
109 {
110 1 int n; // local variable used in delay FOR loop.
111 1 SFRPAGE = CONFIG_PAGE; // switch to config page to config oscillator
112 1 OSCXCN = 0x77; // start external oscillator; 22.1 MHz Crystal
113 1 // system clock is 22.1 MHz / 2 = 11.05 MHz
114 1 for (n=0;n<255;n++); // delay about 1ms
115 1 while ((OSCXCN & 0x80) == 0); // wait for oscillator to stabilize
116 1 CLKSEL |= 0x01; // switch to external oscillator
117 1 }
C51 COMPILER V7.50 接收 01/15/2009 10:48:31 PAGE 3
118
119 void config_IO (void)
120 {
121 1 SFRPAGE = CONFIG_PAGE; //Port SFR's on Configuration page
122 1 XBR3 = 0x80; // Configure CAN TX pin (CTX) as push-pull digital output
123 1 P1MDOUT |= 0x40; // Configure P1.6 as push-pull to drive LED
124 1 XBR2 = 0x40; // Enable Crossbar/low ports
125 1 XBR0 = 0x04;
126 1 P0MDOUT = 0X10;
127 1 }
128
129 ////////////////////////////////////////////////////////////////////////////////
130 //CAN Functions
131 ////////////////////////////////////////////////////////////////////////////////
132
133
134
135 //Transmit CAN frame to turn other node's LED ON
136 void transmit_data (char MsgNum)
137 {
138 1 SFRPAGE = CAN0_PAGE; // IF1 already set up for TX
139 1 CAN0ADR = IF1CMDMSK; // Point to Command Mask 1
140 1 CAN0DAT = 0x0087; // Config to WRITE to CAN RAM, write data bytes,
141 1 // set TXrqst/NewDat, Clr IntPnd
142 1 CAN0ADR = IF1DATA1; // Point to 1st byte of Data Field
143 1 CAN0DATL = transmitdata; // Ones signals to turn LED's light ON in data A1 field
144 1 CAN0ADR = IF1CMDRQST; // Point to Command Request Reg.
145 1 CAN0DATL = MsgNum; // Move new data for TX to Msg Obj "MsgNum"
146 1 }
147
148
149
150
151 // Receive Data from the IF2 buffer
152 void receive_data (char MsgNum)
153 { //int pass;
154 1 unsigned char receive_data;
155 1
156 1 SFRPAGE = CAN0_PAGE; // IF1 already set up for RX
157 1
158 1 CAN0ADR = IF2CMDMSK;
159 1 CAN0DATL = 0x0f;
160 1
161 1 CAN0ADR = IF2CMDRQST;// Point to Command Request Reg.
162 1 CAN0DATL = MsgNum; // Move new data for RX from Msg Obj "MsgNum"
163 1 // Move new data to a
164 1
165 1 // CAN0ADR=IF2MSGC; //消息接口寄存器2的
166 1 // pass=CAN0DAT;
167 1
168 1 // if(pass&0x8000 !=0)
169 1 // {
170 1 CAN0ADR = IF2DATA1; // Point to 1st byte of Data Field
171 1
172 1 receive_data = CAN0DATL;
173 1
174 1
175 1 // if (receive_data == 0x35) //Ones is signal from other node to turn LED ON
176 1 //LED = 1;
177 1 // else LED = 0; //Otherwise turn LED OFF (message was one's)
178 1 //指示灯亮灭!!
179 1
C51 COMPILER V7.50 接收 01/15/2009 10:48:31 PAGE 4
180 1 SFRPAGE = UART0_PAGE;
181 1 while(TI0==1); // 等待在串口中断程序那里将其清0
182 1 SBUF0=receive_data;
183 1
184 1 // }
185 1
186 1 }
187
188 ////////////////////////////////////////////////////////////////////////////////
189 //Interrupt Service Routine
190 ////////////////////////////////////////////////////////////////////////////////
191 void ISRname (void) interrupt 19
192 {
193 1 unsigned int abcd;
194 1 temppage=SFRPAGE;
195 1 SFRPAGE=CAN0_PAGE;
196 1
197 1 status = CAN0STA;
198 1 if ((status&0x10) != 0)
199 1 { // RxOk is set, interrupt caused by reception
200 2 CAN0STA = (CAN0STA&0xEF)|0x07; // Reset RxOk, set LEC to NoChange
201 2 /* read message number from CAN INTREG */
202 2
203 2 CAN0ADR=INTPEND1;
204 2 abcd=CAN0DAT;
205 2 if( (abcd&0x01)!=0 )
206 2 {
207 3 receive_data (0x01); // Up to now, we have only one RX message
208 3 }
209 2 }
210 1 if ((status&0x08) != 0)
211 1 { // TxOk is set, interrupt caused by transmision
212 2 CAN0STA = (CAN0STA&0xF7)|0x07; // Reset TxOk, set LEC to NoChange
213 2 }
214 1 if (((status&0x07) != 0)&&((status&0x07) != 7))
215 1 { // Error interrupt, LEC changed
216 2 /* error handling ? */
217 2 CAN0STA = CAN0STA|0x07; // Set LEC to NoChange
218 2 }
219 1
220 1 SFRPAGE=temppage;
221 1 }
222
223 void SERname (void) interrupt 4//从上位机接收到数据后
224 { //通过can总线发送给采集的开发板
225 1 if(TI0==1)
226 1 {TI0=0;}
227 1 if(RI0==1)
228 1 { RI0=0;
229 2 receivedata=SBUF0;
230 2 LED = ~LED ;
231 2 transmit_data(0x02);
232 2 }
233 1 }
234 //*串口初始化,选择UART1
235 //**************************************************************************/
236 void uart_init()
237 {
238 1 SFRPAGE = UART0_PAGE;
239 1 SCON0 = 0x50; //允许uart1
240 1
241 1 }
C51 COMPILER V7.50 接收 01/15/2009 10:48:31 PAGE 5
242 /*************************************************************************
243 *
244 *定时器初始化,作为UART0的波特率发生器
245 *************************************************************************/
246 void time_init()
247 {
248 1 SFRPAGE = TIMER01_PAGE;
249 1 TCON = 0X40;
250 1 TMOD = 0x20;
251 1 CKCON = 0X10;
252 1 TH1 = 0xDC;
253 1 TR1=1;
254 1
255 1
256 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 544 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 41 ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -