📄 main.lst
字号:
C51 COMPILER V6.12 MAIN 05/25/2007 13:54:27 PAGE 1
C51 COMPILER V6.12, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN .\main.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE .\main.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 #include <absacc.h>
2 #include <P89C58_PLUS.H>
3 #include "SJA1000.h"
4 #define MAX_AD_RECV_LEN 24
5 #define SLOT_ADDR 0xB000
6 #define SLOT_ADDR_COM 0x02 // base addr
7
8 #define CAN_FLAG_NONE 0x00
9 #define CAN_FLAG_START 0x01
10 #define CAN_FLAG_RUNNING 0x02
11 #define CAN_FLAG_END 0x03
12
13 #define STA_IDLE 0
14 #define STA_RECEIVING 1
15 #define STA_SENDING 2
16
17 sbit CAN0_RST = P3^4;
18 sbit CAN1_RST = P1^0;
19 sbit CS_LED = P1^3;
20 sbit AD_CLK = P1^4;
21 sbit AD_OUT = P1^5;
22 sbit AD_IN = P1^6;
23 sbit AD_EOC = P3^3;
24 sbit CS_AD = P1^7;
25
26 sbit TEST = P3^3;
27
28 unsigned char idata m_ad_buff[MAX_AD_RECV_LEN]; //高128位RAM7F-ff 指针方式
29 unsigned int idata m_ad_tmp[5][11];
30 unsigned char m_times;
31
32 unsigned char bdata m_led_cond;//可位寻址的内存空间
33 sbit b_led1=m_led_cond^0;
34 sbit b_led2=m_led_cond^1;
35 sbit b_led3=m_led_cond^2;
36 sbit b_led4=m_led_cond^3;
37 sbit b_led5=m_led_cond^4;
38 sbit b_led6=m_led_cond^5;
39 sbit b_led7=m_led_cond^6;
40 sbit b_led8=m_led_cond^7;
41
42
43 unsigned char xdata *m_pByte;
44 unsigned int m_last_time;
45 unsigned int m_out_time;
46
47 unsigned char m_addr;
48 unsigned char m_chn_no;
49
50 // ...CAN Buffer....
51 unsigned char m_CanSend[10];
52 unsigned char m_CanRecv[10];
53 bit m_bAuto;
54
55 unsigned char m_can_msg_len;
C51 COMPILER V6.12 MAIN 05/25/2007 13:54:27 PAGE 2
56 unsigned char m_can_recvs;
57 unsigned char idata m_buffull;
58
59 void P89C58_init();
60 void SJA1000_init();
61 bit SJA1000_Send();
62 void TLC2543C_init();
63
64 unsigned char GetCANAddr();
65
66 unsigned int GetCRC(unsigned char num,unsigned char *pData);
67 extern void _nop_ (void);
68
69 void delay(unsigned int num)
70 {
71 1 unsigned int i;
72 1 for (i = 0; i < num; i ++) {
73 2 _nop_();
74 2 }
75 1 }
76
77 void LightLed()
78 {
79 1 unsigned char i;
80 1 unsigned char tmp;
81 1 unsigned char led;
82 1 unsigned int m_ad_result;
83 1
84 1 led = 0;
85 1 for(i=0;i<8;i++)
86 1 {
87 2 m_ad_result = m_ad_buff[2*i]<<8;
88 2 m_ad_result += m_ad_buff[2*i+1];
89 2 tmp = m_led_cond&(0x01<<i);
90 2 if(tmp&&(m_ad_result < 630))
91 2 {
92 3 led = led & (~(0x01<<i));
93 3 }
94 2 else led = led | (0x01<<i);
95 2 }
96 1 EA = 0;
97 1 P0 = led;
98 1 CS_LED = 1;
99 1 CS_LED = 0;
100 1 EA = 1;
101 1 }
102
103 // ..Get CRC arrcording data
104 unsigned int GetCRC(unsigned char num,unsigned char *pData)
105 {
106 1 unsigned char i,j;
107 1 unsigned int m_CRC;
108 1
109 1 m_CRC = 0xffff;
110 1 for( i = 0; i < num; i ++)
111 1 {
112 2 m_CRC = m_CRC^(*(pData + i));
113 2 for( j = 0; j < 8; j++ )
114 2 {
115 3 if(m_CRC & 0x01)
116 3 {
117 4 m_CRC = m_CRC >> 1;
C51 COMPILER V6.12 MAIN 05/25/2007 13:54:27 PAGE 3
118 4 m_CRC=m_CRC ^ 0xa001;
119 4 }
120 3 else
121 3 {
122 4 m_CRC = m_CRC >> 1;
123 4 }
124 3 }
125 2 }
126 1 return m_CRC;
127 1 }
128
129 /*********************************************************************************************************
-******************************
130 ..........................................P89C58.............................
131 *********************************************************************************************************
-*****************************/
132 void P89C58_init()
133 {
134 1 TMOD = 0x21; //Mode 2: 8-bits with auto-reload from THx
135 1 RCAP2H = 0xFF;
136 1 RCAP2L = 0xB2;
137 1 CS_LED = 0; //disable 573
138 1 TH0 = 0xF8; //...1mS interrupt
139 1 TL0 = 0x30;
140 1
141 1 // ...Enable all interrupts.
142 1 IE = 0;
143 1 ET0 = 1; //Enable Timer0 interrupt
144 1 EX0 = 1; //Enable INT0 for SJA1000 INT
145 1 EX1 = 0; //Disable INT1 for AD INT
146 1 ES = 0; //Disable Serial port 0 interrupt.
147 1
148 1 // ...Start timer 2
149 1 TR0 = 1;
150 1 }
151
152
153 /* ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
154 * Function:P89C58_ISR_Timer0()
155 * Description:
156 * Timer0 interrupt service routine
157 */
158 void P89C58_ISR_Timer0() interrupt 1 using 2
159 {
160 1 m_last_time = m_last_time ++;
161 1 if(m_last_time > 3000) m_last_time = 3000;
162 1 TH0 = 0xF8; //...1mS interrupt
163 1 TL0 = 0x30;
164 1 TR0 = 1;
165 1 }
166
167 /*********************************************************************************************************
-******************************
168 ..........................................SJA1000.............................
169 *********************************************************************************************************
-*****************************/
170 void SJA1000_init()
171 {
172 1 int j;
173 1
174 1 CAN0_RST = 0;
175 1 for(j = 0; j < 1000; j ++)
C51 COMPILER V6.12 MAIN 05/25/2007 13:54:27 PAGE 4
176 1 {
177 2 _nop_();
178 2 }
179 1 CAN0_RST = 1;
180 1
181 1 // Enter reset mode
182 1 SJA_REG_CR = 0x01;
183 1
184 1 SJA_REG_ACR = m_addr;
185 1 SJA_REG_AMR = 0x03; // 0000 00XX 000
186 1
187 1 SJA_REG_BTR0 = 0x00;
188 1 SJA_REG_BTR1 = 0x14;
189 1 SJA_REG_OCR = 0xAA;
190 1 SJA_REG_CDR = 0x48;
191 1
192 1 // Enter operate mode
193 1 SJA_REG_CR = 0x1A; //Enable all interrupt but transmit
194 1 }
195 /* ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
196 * Function:SJA1000_ISR_0()
197 * Description:
198 * CAN interrupt service routine
199 */
200 void SJA1000_ISR_0() interrupt 0 using 1
201 {
202 1 unsigned char i;
203 1 unsigned char num;
204 1 unsigned char dlc;
205 1 unsigned char status;
206 1 unsigned char iir;
207 1
208 1 iir = SJA_REG_IR;
209 1 status = SJA_REG_SR;
210 1
211 1 if (iir & 0x01) {//RI receive interrupt
212 2 m_CanRecv[0] = SJA_REG_RxBuf0;
213 2 m_CanRecv[1] = SJA_REG_RxBuf1;
214 2 dlc = m_CanRecv[1] & 0x0F;
215 2 for ( i = 0; i < dlc; i ++){
216 3 m_pByte = SJA_REG + 0x16 + i; // 0x16: the offset of SJA_REG_RxBuf2
217 3 num = *m_pByte;
218 3 m_CanRecv[i + 2] = num;
219 3 }
220 2 m_can_msg_len=dlc-1;
221 2 m_buffull = 0x55;
222 2 SJA_REG_CMD = 0x04; // Set RRB bit(Release receive buffer)
223 2 }
224 1
225 1 if (iir & 0x08) {//data overrun interrupt
226 2 SJA_REG_CMD = 0x08; // Set CDO bit
227 2 }
228 1 }
229
230 /* ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
231 * Function:SJA1000_Send()
232 * Description:
233 * SJA1000 Send data
234 */
235 bit SJA1000_Send()
236 {
237 1 unsigned char i;
C51 COMPILER V6.12 MAIN 05/25/2007 13:54:27 PAGE 5
238 1 unsigned char num;
239 1 unsigned char status;
240 1
241 1 status = SJA_REG_SR;
242 1
243 1 if (status & 0x04 == 0) return 0;
244 1 if (status & 0x08 == 0) return 0;
245 1
246 1 for ( i = 0; i < 200; i ++) {
247 2 _nop_();
248 2 }
249 1
250 1 num = m_CanSend[1] & 0x0F;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -