📄 wireless_api.lst
字号:
C51 COMPILER V9.00 WIRELESS_API 11/13/2010 15:06:02 PAGE 1
C51 COMPILER V9.00, COMPILATION OF MODULE WIRELESS_API
OBJECT MODULE PLACED IN wireless_api.OBJ
COMPILER INVOKED BY: D:\Program Files\KEIL C V4\C51\BIN\C51.EXE wireless_api.c LARGE BROWSE DEBUG OBJECTEXTEND
line level source
*** WARNING C500 IN LINE 1 OF WIRELESS_API.C: LICENSE ERROR (R208: RENEW LICENSE ID CODE (LIC))
1
2 #include "reg24le1.h"
3 #include "wireless_api.h"
4 #include "rf24le1.h"
*** WARNING C317 IN LINE 104 OF rf24le1.h: attempt to redefine macro 'PTX'
*** WARNING C317 IN LINE 105 OF rf24le1.h: attempt to redefine macro 'PRX'
*** ERROR C141 IN LINE 186 OF RF24LE1.H: syntax error near 'SetupData'
5
6 #define CSN_LOW() RFCSN = 0;
7 #define CSN_HIGH() RFCSN = 1;
8 #define CE_LOW() RFCE = 0;Timer_10Us(1);
9 #define CE_HIGH() RFCE = 1;
10 #define CE_PULSE() CE_HIGH();Timer_10Us(2);CE_LOW();
11
12 idata unsigned char radio_status;
13 static unsigned char gnDataPipeNumber;
14 code const address[]={0x12,37,0x55,0x79,0x97};
15
16
17 static unsigned char Rf24L01_Reg_RW(unsigned char byte)
18 {
19 1 SPIRDAT = byte; //write spi
20 1 RFSPIF = 0;
21 1 while(!RFSPIF); //wait untill the spi ready again
22 1 return SPIRDAT; //return the state
23 1 return 0;
24 1 }
25
26 unsigned char Rf24L01_WriteByte(unsigned char reg, unsigned char value)
27 {
28 1 unsigned char status;
29 1
30 1 CSN_LOW();
31 1
32 1 status = Rf24L01_Reg_RW(reg); // select register
33 1
34 1 Rf24L01_Reg_RW(value); // ..and write value to it..
35 1
36 1 CSN_HIGH();
37 1
38 1 return(status); // return nRF24L01 status byte
39 1 }
40
41
42 unsigned char Rf24L01_WriteMultiByte(unsigned char reg, unsigned char *pBuf, unsigned char len)
43 {
44 1 unsigned char status,i;
45 1
46 1 CSN_LOW();
47 1
48 1 status = Rf24L01_Reg_RW(reg); // Select register to write to and read status byte
49 1
50 1 for(i=0; i<len; i++) // then write all byte in buffer(*pBuf)
51 1 {
C51 COMPILER V9.00 WIRELESS_API 11/13/2010 15:06:02 PAGE 2
52 2 Rf24L01_Reg_RW(*pBuf++);
53 2 }
54 1
55 1 CSN_HIGH();
56 1
57 1 return(status); // return nRF24L01 status byte
58 1 }
59
60
61 unsigned char Rf24L01_Clear_IRQ(unsigned char irq_flag)
62 {
63 1 return Rf24L01_WriteByte(WRITE_REG + STATUS, irq_flag);
64 1 }
65
66 void Rf24L01_Flush_TX(void)
67 {
68 1 Rf24L01_WriteByte(FLUSH_TX,0);
69 1 }
70
71
72 void Rf24L01_Flush_RX(void)
73 {
74 1 Rf24L01_WriteByte(FLUSH_RX,0);
75 1 }
76
77
78 unsigned char Rf24L01_ReadByte(unsigned char reg)
79 {
80 1 unsigned char reg_val;
81 1
82 1 CSN_LOW();
83 1
84 1 Rf24L01_Reg_RW(reg); // Select register to read from..
85 1
86 1 reg_val = Rf24L01_Reg_RW(0); // ..then read registervalue
87 1
88 1 CSN_HIGH();
89 1
90 1 return(reg_val); // return register value
91 1 }
92
93 void Rf24L01_RxTx_Switch(unsigned char bMode)
94 {
95 1 unsigned char bConfig;
96 1
97 1 CE_LOW();
98 1
99 1 Rf24L01_Flush_RX(); //set TX/RX FIFO to be empty
100 1 Rf24L01_Flush_TX(); //
101 1 Rf24L01_Clear_IRQ(MASK_IRQ_FLAGS); //clear IRQ STATUS register
102 1
103 1 bConfig = Rf24L01_ReadByte(CONFIG);
104 1
105 1 if(bMode == PRX)
106 1 {
107 2 if((bConfig&0x01))
108 2 {
109 3 CE_HIGH();
110 3 return;
111 3 }
112 2
113 2 bConfig &= 0xfe;
C51 COMPILER V9.00 WIRELESS_API 11/13/2010 15:06:02 PAGE 3
114 2 bConfig |= 0x01;
115 2
116 2 Rf24L01_WriteByte(WRITE_REG + CONFIG, bConfig);
117 2
118 2 CE_HIGH();
119 2 }
120 1 else if(bMode == PTX)
121 1 {
122 2 if(!(bConfig&0x01))
123 2 {
124 3 return;
125 3 }
126 2
127 2 bConfig &= 0xfe;
128 2
129 2 Rf24L01_WriteByte(WRITE_REG + CONFIG, bConfig);
130 2 }
131 1 }
132
133
134 static unsigned char Rf24L01_ReadMultiByte(unsigned char reg, unsigned char *pBuf, unsigned char len)
135 {
136 1 unsigned char status,i;
137 1
138 1 CSN_LOW();
139 1
140 1 status = Rf24L01_Reg_RW(reg); // Select register to write to and read status byte
141 1
142 1 for (i=0;i<len;i++)
143 1 {
144 2 pBuf[i] = Rf24L01_Reg_RW(0); // Perform Rf24L01_Reg_RW to read byte from nRF24L01
145 2 }
146 1 pBuf[i]='\0';
147 1
148 1 CSN_HIGH();
149 1
150 1 return(status); // return nRF24L01 status byte
151 1 }
152
153 //-----------------------------------------------------------------------------
154 //
155 // Used in RX mode.
156 //
157 //-----------------------------------------------------------------------------
158
159 static void Rf24L01_RX(unsigned char *prx_buf)
160 {
161 1 unsigned char gnRF_RecvLen;
162 1 gnRF_RecvLen=Rf24L01_ReadByte(READ_PAYLAODLEN); // READ_PAYLAODLEN is a cmd to get the rx payload length
163 1
164 1 if (prx_buf != NULL) Rf24L01_ReadMultiByte(RD_RX_PLOAD, prx_buf, gnRF_RecvLen); //read data from rd_rx_pl
-o
165 1 }
166
167 //-----------------------------------------------------------------------------
168
169
170
171 //-----------------------------------------------------------------------------
172
173 void Rf24L01_TX(unsigned char *ptx_buf,unsigned char nLen)
174 {
C51 COMPILER V9.00 WIRELESS_API 11/13/2010 15:06:02 PAGE 4
175 1
176 1 // Rf24L01_RxTx_Switch(PTX); //转换到发送模式
177 1
178 1 Rf24L01_Flush_TX(); //clear 24L01 tx buffer
179 1
180 1 //Rf24L01_WriteMultiByte(WR_TX_PLOAD, ptx_buf, nLen); //连续写入要发送的数据
181 1 Rf24L01_WriteByte(WR_TX_PLOAD,*ptx_buf);
182 1 CE_PULSE(); //20us的高脉冲
183 1 }
184
185
186 void Rf24L01_TXABYTE(unsigned char x)
187 {
188 1
189 1 Rf24L01_RxTx_Switch(PTX); //转换到发送模式
190 1
191 1 Rf24L01_Flush_TX(); //clear 24L01 tx buffer
192 1
193 1 Rf24L01_WriteByte(WR_TX_PLOAD, x); //写入要发送的数据
194 1 // Rf24L01_WriteByte(unsigned char reg, unsigned char value)
195 1
196 1 CE_PULSE(); //20us的高脉冲
197 1 }
198
199
200
201 //-----------------------------------------------------------------------------
202 //
203 // Function: Rf24L01_Polling_IRQ
204 //
205 // Description:
206 // Deal with IQR event with polling mode
207 //
208 //-----------------------------------------------------------------------------
209
210 static void rf_rdy_ov_interrupt(void) interrupt INTERRUPT_RFRDY {} //SPI ready
211
212 //---------------------------------------------------------------------------
213 static void rfirq_ov_interrupt(void) interrupt INTERRUPT_RFIRQ
214 {
215 1 radio_status =0xFF;
216 1 }
217 //---------------------------------------------------------------------------
218
219 unsigned char Rf24L01_Polling_IRQ(unsigned char * rev_buf)
220 {
221 1 unsigned char irq_status;
222 1
223 1 if(radio_status == 0x00)
224 1 {
225 2 if(Rf24L01_ReadByte(FIFO_STATUS) & MASK_RX_EMPTY) return IDLE; //当前FIFO为空
226 2
227 2 Rf24L01_RX(rev_buf); //将收到的有效数据存到revbuf指针当中
228 2
229 2 irq_status=Rf24L01_ReadByte(STATUS); //读取SPI状态寄存器
230 2
231 2 gnDataPipeNumber=(irq_status>>1)&0x7; //取当前收到数据的通道号
232 2
233 2 return (unsigned char)RX_DR; //成功的接收到数据
234 2 }
235 1
236 1 radio_status = 0x00;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -