📄 car_cad.lst
字号:
C51 COMPILER V8.01 CAR_CAD 07/25/2007 10:26:21 PAGE 1
C51 COMPILER V8.01, COMPILATION OF MODULE CAR_CAD
OBJECT MODULE PLACED IN car_cad.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE car_cad.c BROWSE DEBUG OBJECTEXTEND
line level source
1 #include <STC12C2052AD.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <intrins.h>
5
6
7 #define uchr unsigned char
8 #define uint unsigned int
9
10 //================读指令==============
11 #define DRF_R 0x7e //只读
12 #define DRF_r/w 0xfe //读写
13
14 //================写指令==============
15
16
17 #define INBUF_LEN 25
18
19 sbit WORK_LED = P1^7;
20 sbit OPEN = P1^5;
21 sbit TXCT = P1^2; //控制选通(低电平有效)
22 sbit SCIO = P1^3; //数据输出
23 unsigned char rece_ok,g_cReceNum;
24 uchr RF_read_buf[INBUF_LEN]; //读缓冲区
25 uchr In_buf[INBUF_LEN]; //
26
27 //union
28 //{
29 // uchr crc[2];
30 // uint i;
31 //}Hex ;
32
33 bit timer_3ms;
34 bit timer_15ms;
35 bit timer_20ms;
36 bit timer_50ms;
37
38 bit read_flag;
39
40 uchr bdata get_chr;
41 sbit Bit7 = get_chr ^ 7;
42
43
44 void delay(uint i)
45 {
46 1 while(-- i);
47 1 }
48
49 void RF_init(void)
50 {
51 1 TXCT = 1;
52 1 SCIO = 1;
53 1 }
54
55 void RF_charge()
C51 COMPILER V8.01 CAR_CAD 07/25/2007 10:26:21 PAGE 2
56 {
57 1
58 1 TXCT = 0;
59 1 delay(39500); //50ms
60 1 TXCT = 1;
61 1
62 1
63 1 }
64
65
66 void RF_program()
67 {
68 1
69 1 TXCT = 0;
70 1 delay(11850); //写完之后延时15 ms
71 1 TXCT = 1;
72 1 }
73
74 //===================================
75 //向串口发送一个字符
76 void send_char_com(uchr ch)
77 {
78 1 SBUF=ch;
79 1 while(TI==0);
80 1 TI=0;
81 1 }
82
83 //向串口发送一个字符串,strlen为该字符串长度
84 void send_string_com(uchr *str,uint strlen)
85 {
86 1 uint k=0;
87 1 do
88 1 {
89 2 send_char_com(*(str + k));
90 2 k++;
91 2 } while(k < strlen);
92 1 }
93
94
95 //=================================================
96 // *ptr指向发送数据块的首地址, len是数据块以字节为单位的长度.
97 uint RF_crc(unsigned char *ptr, unsigned char len)
98 {
99 1 unsigned char i;
100 1
101 1 uint crc = 0;
102 1 while(len -- != 0)
103 1 {
104 2 for(i = 0x01;i!=0;i <<= 1)
105 2 {
106 3 if((crc & 0x0001)!=0)
107 3 {
108 4 crc >>= 1;
109 4 crc ^= 0x8408;
110 4 }
111 3 else
112 3 crc >>= 1;
113 3 if((*ptr&i)!=0) crc ^= 0x8408;
114 3 }
115 2 ptr ++;
116 2 }
117 1 return(crc);
C51 COMPILER V8.01 CAR_CAD 07/25/2007 10:26:21 PAGE 3
118 1 }
119
120 //===============读程序=============
121 uchr RF_read_byte(void)
122 {
123 1 uchr temp;
124 1
125 1 get_chr = 0;
126 1 while(1)
127 1 {
128 2 if(SCIO == 1) // 开始位
129 2 {
130 3
131 3 delay(75); //96us
132 3 for(temp = 0;temp < 8;temp ++)
133 3 {
134 4 get_chr = get_chr >> 1;
135 4 Bit7 = SCIO;
136 4 Bit7 = ~ Bit7;
137 4 delay(46); //64us
138 4 }
139 3
140 3 delay(46);
141 3 return (get_chr);
142 3 }
143 2 }
144 1 }
145
146 void RF_read()
147 {
148 1 uchr temp1;
149 1 TR0 = 1;
150 1 timer_20ms = 0;
151 1 while(1)
152 1 {
153 2 if(timer_20ms == 1)
154 2 {
155 3 timer_20ms = 0;
156 3 TR0 = 0;
157 3 return ;
158 3 }
159 2 if(SCIO == 1)
160 2 {
161 3 RF_read_buf[0] = RF_read_byte();
162 3
163 3 if(RF_read_buf[0] == 0x7e)
164 3 {
165 4 for(temp1 = 1;temp1 < 14;temp1 ++)
166 4 {
167 5 RF_read_buf[temp1] = RF_read_byte();
168 5 }
169 4 }
170 3 send_string_com(RF_read_buf,14);
171 3 return;
172 3 }
173 2 }
174 1 }
175
176
177 //==============写程序==============
178
179 void RF_write_byte(uchr i)
C51 COMPILER V8.01 CAR_CAD 07/25/2007 10:26:21 PAGE 4
180 {
181 1 uchr temp;
182 1
183 1 WORK_LED = 0;
184 1
185 1 for(temp = 0;temp < 8;temp ++)
186 1 {
187 2
188 2 if((i & 0x01) == 0)
189 2 {
190 3 delay(235); //0.3ms
191 3 TXCT = 0;
192 3 delay(1340); //1.7ms
193 3 TXCT = 1;
194 3 }
195 2 else
196 2 {
197 3 delay(789); //1ms
198 3 TXCT = 0;
199 3 delay(789); //1ms
200 3 TXCT = 1;
201 3 }
202 2 i >>= 1;
203 2 }
204 1 TXCT = 1;
205 1 }
206
207
208
209 void RF_write(unsigned char choose,unsigned char *write_buf)
210 {
211 1 uchr temp;
212 1 uchr i;
213 1 uint crc_check = 0;
214 1 unsigned char RF_write_buf[INBUF_LEN];
215 1
216 1 temp = 0;
217 1 i = 0;
218 1
219 1 if(choose==0) //写第一页
220 1 RF_write_buf[0] = 0x05; //第1页 写入
221 1 else if(choose==1) //写第二页
222 1 RF_write_buf[0]=0x09;
223 1 else if(choose==2) //写第三页
224 1 RF_write_buf[0]=0x0d;
225 1 for(temp = 1;temp < 9;temp ++) //要写入的8位ID号
226 1 {
227 2 RF_write_buf[temp] = write_buf[temp-1];
228 2 }
229 1 crc_check = RF_crc(RF_write_buf + 1,8); //ID号的CRC校验值
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -