📄 ptr8000.lst
字号:
C51 COMPILER V7.02a PTR8000 04/23/2006 19:35:53 PAGE 1
C51 COMPILER V7.02a, COMPILATION OF MODULE PTR8000
OBJECT MODULE PLACED IN ptr8000.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ptr8000.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 #include <AT89X52.h>
2 #include <ABSACC.h>
3 #include <intrins.h>
4 #include <stdio.h>
5 #define uint unsigned int
6 #define uchar unsigned char
7 //配置口定义//
8 sbit TXEN = P2^6;
9 sbit TRX_CE = P2^5;
10 sbit PWR = P2^4;
11 //SPI口定义//
12 sbit MISO = P2^3;
13 sbit MOSI = P2^2;
14 sbit SCK = P2^1;
15 sbit CSN = P2^0;
16 //sbit P2_0 = P2^0;
17 //状态输出口//
18 sbit AM =P3^2;
19 sbit DR = P3^3;
20 sbit LCD = P3^4;
21
22 //RF寄存器配置//
23 unsigned char idata RFConf[11]=
24 {
25 0x00, //配置命令//
26 0x6C, //CH_NO,配置频段在433.2MHZ
27 0x0E, //输出功率为10db,不重发,节电为正常模式
28 0x44, //地址宽度设置,为4字节
29 0x03,0x03, //接收发送有效数据长度为3字节
30 0xE7,0xE7,0xE7,0xE7, //接收地址
31 0xC0, //CRC充许,16位CRC校验16M晶振
32 };
33
34 uchar TxRxBuffer[5];
35 bit lcdbit;
36 ///////////延时/////////////////
37 void Delay(uint x)
38 {
39 1 uint i;
40 1 for(i=0;i<x;i++){
41 2 _nop_();
42 2 }
43 1 }
44
45 ////////////用SPI口写数据至NRF905内//////////
46 void SpiWrite(unsigned char b)
47 {
48 1 unsigned char i=8;
49 1 while (i--)
50 1 {
51 2 Delay(10);
52 2 SCK=0;
53 2 MOSI=(bit)(b&0x80);
54 2 b<<=1 ;
55 2 Delay(10);
C51 COMPILER V7.02a PTR8000 04/23/2006 19:35:53 PAGE 2
56 2 SCK=1;
57 2 Delay(10);
58 2 SCK=0;
59 2 }
60 1 SCK=0;
61 1 }
62 ///////////////from 905 read data////////////////
63 unsigned char SpiRead(void)
64 {
65 1 register unsigned char i=8;
66 1 unsigned char ddata=0;
67 1 while (i--)
68 1 {
69 2 ddata<<=1 ;
70 2 SCK=0;
71 2 Delay(20);
72 2 ddata|=MISO;
73 2 SCK=1 ;
74 2 Delay(20);
75 2 }
76 1 SCK=0;
77 1 return ddata;
78 1 }
79 ///////////////接收数据包/////////////////
80 void RxPacket(void)
81 {
82 1 uchar i;
83 1 i=0;
84 1 while(DR)
85 1 {
86 2 TxRxBuffer[i] = SpiRead();
87 2 i++;
88 2 }
89 1 }
90
91 /*
92 ;写发射数据命令:20H
93 ;读发射数据命令:21H
94 ;写发射地址命令:22H
95 ;读发射地址命令:23H
96 ;读接收数据命令:24H
97 */
98 void TxPacket(void)
99 { PWR=1;
100 1 TXEN=1;
101 1 CSN=0;
102 1 SpiWrite(0x22); //写发送地址,后面跟4字节地址//
103 1 SpiWrite(0xE7);
104 1 SpiWrite(0xE7);
105 1 SpiWrite(0xE7);
106 1 SpiWrite(0xE7);
107 1 CSN=1;
108 1 Delay(2);
109 1 CSN=0;
110 1 SpiWrite(0x20); //写发送数据命令,后面跟三字节数据//
111 1 SpiWrite(0x01);
112 1 SpiWrite(0x02);
113 1 SpiWrite(0x03);
114 1 CSN=1;
115 1 Delay(2);
116 1 TRX_CE=1; //使能发射模式//
117 1 Delay(100); //等带发送完成//
C51 COMPILER V7.02a PTR8000 04/23/2006 19:35:53 PAGE 3
118 1 TRX_CE=0;
119 1 while(!DR);
120 1
121 1 }
122 ////////////////等待接收数据包///////////////////
123 uchar temp;
124 void Wait_Rec_Packet(void)
125 {
126 1 TXEN=0;
127 1 TRX_CE=1;
128 1 PWR=1;
129 1 Delay(1000);
130 1 while(1)
131 1 { //if (LCD==1) P0=~P0;
132 2 if(DR)
133 2 { //P0=~P0;
134 3 TRX_CE=0; //如果数据准备好,则进入待机模式,以便SPI口操作
135 3 CSN=0;
136 3 SpiWrite(0x24);
137 3 RxPacket();
138 3 CSN=1;
139 3 temp=TxRxBuffer[0]+TxRxBuffer[1]+TxRxBuffer[2];
140 3 if(temp==0x06){
141 4 lcdbit=!lcdbit;
142 4 LCD=lcdbit;
143 4 P0=~P0;
144 4 //如果接收的数据正确
145 4 }
146 3 break;
147 3 }
148 2 }
149 1 }
150 ////////////初始化配置寄存器////////////////
151 void Ini_System(void)
152 {
153 1 uchar i;
154 1 LCD=0;
155 1 Delay(10000);
156 1 LCD=1;
157 1 lcdbit=1;
158 1 CSN=1;
159 1 SCK=0;
160 1 PWR=1;
161 1 TRX_CE=0;
162 1 TXEN=0;
163 1 Delay(2);
164 1 CSN=0;
165 1
166 1 SpiWrite( 0x00); //配置命令//
167 1 SpiWrite( 0x6C); //CH_NO,配置频段在433.2MHZ
168 1 SpiWrite( 0x0E); //输出功率为10db,不重发,节电为正常模式
169 1 SpiWrite( 0x44); //地址宽度设置,为4字节
170 1 SpiWrite( 0x03);SpiWrite( 0x03); //接收发送有效数据长度为3字节
171 1 SpiWrite( 0xE7);SpiWrite( 0xE7);SpiWrite( 0xE7);SpiWrite( 0xE7); //接收地址
172 1 SpiWrite( 0xDE);
173 1
174 1
175 1 /*for(i=0;i<11;i++){
176 1 SpiWrite(RFConf[i]);
177 1 }*/
178 1 CSN=1;
179 1 PWR=1;
C51 COMPILER V7.02a PTR8000 04/23/2006 19:35:53 PAGE 4
180 1 TRX_CE=1;
181 1 TXEN=0;
182 1 Delay(1000);
183 1 }
*** WARNING C280 IN LINE 153 OF PTR8000.C: 'i': unreferenced local variable
184
185
186
187
188
189
190
191 #define max_len_string 8
192 #define INBUF_LEN 4 //数据长度
193 char checksum,count3;
194 char inbuf1[max_len_string];
195 bit read_flag=0;
196
197
198 void delay();
199 void send_char_com(char ch)
200 {
201 1 SBUF=ch;
202 1 while(TI==0);
203 1 TI=0;
204 1 }
205
206 void send_string_com( char *str,int strlen)//发送数据帧格式:02-数据-校验和-03
207 { char sum;
208 1
209 1 int k=0;
210 1 //send_char_com(02);
211 1 do
212 1 { //sum^=*(str+k);
213 2 send_char_com(*(str + k));
214 2 k++;
215 2 } while(k < strlen);
216 1 //send_char_com(sum);
217 1 //send_char_com(03);
218 1 }
*** WARNING C280 IN LINE 207 OF PTR8000.C: 'sum': unreferenced local variable
219
220
221 void serial () interrupt 4 using 3
222 {
223 1 if(RI)
224 1 {
225 2 char ch;
226 2 RI = 0;
227 2 ch=SBUF;
228 2 if(ch>127)
229 2 {
230 3 count3=0;
231 3 inbuf1[count3]=ch;
232 3 checksum= ch-128;
233 3 }
234 2 else
235 2 {
236 3 count3++;
237 3 inbuf1[count3]=ch;
238 3 checksum ^= ch;
239 3 if( (count3==(INBUF_LEN-1)) && (!checksum) )
C51 COMPILER V7.02a PTR8000 04/23/2006 19:35:53 PAGE 5
240 3 {
241 4 read_flag=1; //如果串口接收的数据达到INBUF_LEN个,且校验没错,
242 4 //就置位取数标志
243 4 }
244 3 }
245 2 }
246 1 }
247
248
249 void init_serial()
250 {
251 1 PCON = 0x80;
252 1 SCON = 0x50; //串口方式1,允许接收
253 1 TMOD = 0x20; //定时器1定时方式2
254 1 TCON = 0x40; //设定时器1开始计数
255 1 TH1 = 0xE6; //11.0592MHz 1200波特率
256 1 TL1 = 0xE6;
257 1 TI = 1;
258 1 TR1 = 1; //启动定时器}
259 1
260 1 }
261
262
263
264
265
266
267
268
269
270 void main(void)
271 {
272 1 uchar i;
273 1 init_serial();
274 1 Ini_System();
275 1 PWR=0;
276 1 P0=0;
277 1 DR=0;
278 1 //TxPacket();
279 1 send_string_com("Test_OK:",8);
280 1 while(1)
281 1 {
282 2 Wait_Rec_Packet(); //等待接收完成
283 2 send_string_com("Test_OK:",8);
284 2 send_string_com(TxRxBuffer,5);
285 2 // for(i=0;i<2;i++)
286 2 // Delay(65530);
287 2 //TxPacket();
288 2 //Delay(50000);
289 2 P0=~P0;
290 2 }
291 1 }
*** WARNING C280 IN LINE 272 OF PTR8000.C: 'i': unreferenced local variable
292
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 531 ----
CONSTANT SIZE = 9 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 16 9
C51 COMPILER V7.02a PTR8000 04/23/2006 19:35:53 PAGE 6
IDATA SIZE = 11 ----
BIT SIZE = 2 ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 3 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -