📄 89lv51.lst
字号:
C51 COMPILER V7.06 89LV51 03/21/2007 11:35:07 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE 89LV51
OBJECT MODULE PLACED IN 89lv51.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE 89lv51.c BROWSE INCDIR(D:\BAO\copy\24L01\新版24L01\source code new\24L01 so
-urce code\) DEBUG OBJECTEXTEND
stmt level source
1 #include <reg51.h>
2 #include <intrins.h>
3 #include "api.h"
4 /*
5 *This file is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTYT;
6 *
7 *uart:9600BPS
8 *****************
9 * 官方网址: http://www.tianyi-dz.com
10 * 官方论坛: http://www.tianyi-dz.com/bbs
11 ****************
12 ***TY Tech**
13 ***bai chun yu **
14 ***qq:472230383 328997835 **
15 ***Email:baichunyu1232000@163.com **
16 ****************
17 */
18 /***************************************************/
19 #define uchar unsigned char
20 #define TX_ADR_WIDTH 5 // 5 bytes TX(RX) address width
21 #define TX_PLOAD_WIDTH 20 // 20 bytes TX payload
22
23 uchar const TX_ADDRESS[TX_ADR_WIDTH] = {0x34,0x43,0x10,0x10,0x01}; // Define a static TX address
24
25 uchar rx_buf[TX_PLOAD_WIDTH];
26 uchar tx_buf[TX_PLOAD_WIDTH];
27 uchar flag;
28 /**************************************************/
29 sbit CE = P1^0;
30 sbit CSN= P1^1;
31 sbit SCK= P1^2;
32 sbit MOSI= P1^3;
33 sbit MISO= P1^4;
34 sbit IRQ = P1^5;
35 /**************************************************/
36 uchar bdata sta;
37 sbit RX_DR =sta^6;
38 sbit TX_DS =sta^5;
39 sbit MAX_RT =sta^4;
40 /**************************************************/
41
42 /**************************************************
43 Function: init_io();
44 Description:
45 flash led one time,chip enable(ready to TX or RX Mode),
46 Spi disable,Spi clock line init high
47 /**************************************************/
48 #define KEY 0xaa
49 void init_io(void)
50 {
51 1 P0=KEY; // led light
52 1 CE=0; // chip enable
53 1 CSN=1; // Spi disable
54 1 SCK=0; // Spi clock line init high
C51 COMPILER V7.06 89LV51 03/21/2007 11:35:07 PAGE 2
55 1 P0=0xff; // led close
56 1 }
57 /**************************************************/
58
59 /**************************************************
60 Function: Inituart();
61
62 Description:
63 set uart working mode
64 /**************************************************/
65 void Inituart(void)
66 {
67 1 TMOD = 0x20; //timer1 working mode 1
68 1 TL1 = 0xfd; //f7=9600 for 16mhz Fosc,and ...
69 1 TH1 = 0xfd; //...fd=19200 for 11.0592mhz Fosc
70 1 SCON = 0xd8; //uart mode 3,ren==1
71 1 PCON = 0x80; //smod=0
72 1 TR1 = 1; //start timer1
73 1 }
74 /**************************************************/
75
76 /**************************************************
77 Function: init_int0();
78
79 Description:
80 enable int0 interrupt;
81 /**************************************************/
82 void init_int0(void)
83 {
84 1 EA=1;
85 1 EX0=1; // Enable int0 interrupt.
86 1 }
87 /**************************************************/
88
89 /**************************************************
90 Function: delay100();
91
92 Description:
93 delay 100ms
94 /**************************************************
95 void delay(uchar )
96 {
97 uchar x;
98 uchar y;
99 for(x=0;x<100;x++)
100 {
101 for(y=0;y<100;y++)
102 _nop_();
103 }
104 }
105
106 /**************************************************/
107 void delay_ms(unsigned int x)
108 {
109 1 unsigned int i,j;
110 1 i=0;
111 1 for(i=0;i<x;i++)
112 1 {
113 2 j=108;
114 2 ;
115 2 while(j--);
116 2 }
C51 COMPILER V7.06 89LV51 03/21/2007 11:35:07 PAGE 3
117 1 }
118 /**************************************************/
119
120 /**************************************************
121 Function: SPI_RW();
122
123 Description:
124 Writes one byte to nRF24L01, and return the byte read
125 from nRF24L01 during write, according to SPI protocol
126 /**************************************************/
127 uchar SPI_RW(uchar byte)
128 {
129 1 uchar bit_ctr;
130 1 for(bit_ctr=0;bit_ctr<8;bit_ctr++) // output 8-bit
131 1 {
132 2 MOSI = (byte & 0x80); // output 'byte', MSB to MOSI
133 2 byte = (byte << 1); // shift next bit into MSB..
134 2 SCK = 1; // Set SCK high..
135 2 byte |= MISO; // capture current MISO bit
136 2 SCK = 0; // ..then set SCK low again
137 2 }
138 1 return(byte); // return read byte
139 1 }
140 /**************************************************/
141
142 /**************************************************
143 Function: SPI_RW_Reg();
144
145 Description:
146 Writes value 'value' to register 'reg'
147 /**************************************************/
148 uchar SPI_RW_Reg(BYTE reg, BYTE value)
149 {
150 1 uchar status;
151 1
152 1 CSN = 0; // CSN low, init SPI transaction
153 1 status = SPI_RW(reg); // select register
154 1 SPI_RW(value); // ..and write value to it..
155 1 CSN = 1; // CSN high again
156 1
157 1 return(status); // return nRF24L01 status byte
158 1 }
159 /**************************************************/
160
161 /**************************************************
162 Function: SPI_Read();
163
164 Description:
165 Read one byte from nRF24L01 register, 'reg'
166 /**************************************************/
167 BYTE SPI_Read(BYTE reg)
168 {
169 1 BYTE reg_val;
170 1
171 1 CSN = 0; // CSN low, initialize SPI communication...
172 1 SPI_RW(reg); // Select register to read from..
173 1 reg_val = SPI_RW(0); // ..then read registervalue
174 1 CSN = 1; // CSN high, terminate SPI communication
175 1
176 1 return(reg_val); // return register value
177 1 }
178 /**************************************************/
C51 COMPILER V7.06 89LV51 03/21/2007 11:35:07 PAGE 4
179
180 /**************************************************
181 Function: SPI_Read_Buf();
182
183 Description:
184 Reads 'bytes' #of bytes from register 'reg'
185 Typically used to read RX payload, Rx/Tx address
186 /**************************************************/
187 uchar SPI_Read_Buf(BYTE reg, BYTE *pBuf, BYTE bytes)
188 {
189 1 uchar status,byte_ctr;
190 1
191 1 CSN = 0; // Set CSN low, init SPI tranaction
192 1 status = SPI_RW(reg); // Select register to write to and read status byte
193 1
194 1 for(byte_ctr=0;byte_ctr<bytes;byte_ctr++)
195 1 pBuf[byte_ctr] = SPI_RW(0); // Perform SPI_RW to read byte from nRF24L01
196 1
197 1 CSN = 1; // Set CSN high again
198 1
199 1 return(status); // return nRF24L01 status byte
200 1 }
201 /**************************************************/
202
203 /**************************************************
204 Function: SPI_Write_Buf();
205
206 Description:
207 Writes contents of buffer '*pBuf' to nRF24L01
208 Typically used to write TX payload, Rx/Tx address
209 /**************************************************/
210 uchar SPI_Write_Buf(BYTE reg, BYTE *pBuf, BYTE bytes)
211 {
212 1 uchar status,byte_ctr;
213 1
214 1 CSN = 0; // Set CSN low, init SPI tranaction
215 1 status = SPI_RW(reg); // Select register to write to and read status byte
216 1 for(byte_ctr=0; byte_ctr<bytes; byte_ctr++) // then write all byte in buffer(*pBuf)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -