?? nrf24l01.lst
字號(hào):
C51 COMPILER V8.05a NRF24L01 08/21/2009 10:54:35 PAGE 1
C51 COMPILER V8.05a, COMPILATION OF MODULE NRF24L01
OBJECT MODULE PLACED IN NRF24l01.OBJ
COMPILER INVOKED BY: D:\Program Files\keil 中文版\C51\BIN\C51.EXE NRF24l01.c BROWSE DEBUG OBJECTEXTEND
line level source
1 #include <reg51.h>
2 #include <intrins.h>
3 #include "api.h"
4 /***************************************************/
5 #define uchar unsigned char
6 #define TX_ADR_WIDTH 5 // 5 bytes TX(RX) address width
7 #define TX_PLOAD_WIDTH 5 // 20 bytes TX payload
8
9 uchar const TX_ADDRESS[TX_ADR_WIDTH] = {0x34,0x43,0x10,0x10,0x01}; // Define a static TX address
10
11 uchar rx_buf[TX_PLOAD_WIDTH];
12 //uchar tx_buf[TX_PLOAD_WIDTH];
13 uchar tx_buf[TX_PLOAD_WIDTH]={0xaa,0x55,0xf0,0x0f,0x00};
14 uchar flag;
15 /**************************************************/
16 sbit CE = P2^0;
17 sbit CSN= P2^1;
18 sbit SCK= P2^2;
19 sbit MOSI= P2^3;
20 sbit MISO= P2^4;
21 sbit IRQ = P3^2;
22 /**************************************************/
23 uchar bdata sta;
24 sbit RX_DR =sta^6;
25 sbit TX_DS =sta^5;
26 sbit MAX_RT =sta^4;
27 /**************************************************/
28
29 sbit k1=P1^0;
30 sbit k2=P1^1;
31 sbit k3=P1^2;
32 sbit k4=P1^3;
33
34 /**************************************************
35 Function: init_io();
36 Description:
37 flash led one time,chip enable(ready to TX or RX Mode),
38 Spi disable,Spi clock line init high
39 /**************************************************/
40 void init_io(void)
41 {
42 1 P0=0x0f; // led light
43 1 CE=0; // chip enable
44 1 CSN=1; // Spi disable
45 1 SCK=0; // Spi clock line init high
46 1 P0=0xff; // led close
47 1 }
48 /**************************************************/
49
50 /**************************************************
51 Function: Inituart();
52
53 Description:
54 set uart working mode
55 /**************************************************/
C51 COMPILER V8.05a NRF24L01 08/21/2009 10:54:35 PAGE 2
56 void Inituart(void)
57 {
58 1 TMOD = 0x20; //timer1 working mode 1
59 1 TL1 = 0xfd; //f7=9600 for 16mhz Fosc,and ...
60 1 TH1 = 0xfd; //...fd=19200 for 11.0592mhz Fosc
61 1 SCON = 0xd8; //uart mode 3,ren==1
62 1 PCON = 0x80; //smod=0
63 1 TR1 = 1; //start timer1
64 1 }
65 /**************************************************/
66
67 /**************************************************
68 Function: init_int0();
69
70 Description:
71 enable int0 interrupt;
72 /**************************************************/
73 void init_int0(void)
74 {
75 1 EA=1;
76 1 EX0=1; // Enable int0 interrupt.
77 1 }
78 /**************************************************/
79
80
81 /**************************************************
82 Function: delay100();
83
84 Description:
85 delay 100ms
86 /**************************************************/
87 void delay100()
88 {
89 1 uchar x;
90 1 uchar y;
91 1 for(x=0;x<100;x++)
92 1 {
93 2 for(y=0;y<100;y++)
94 2 _nop_();
95 2 }
96 1 }
97 /**************************************************
98 Function: delay_ms();
99
100 Description: delay
101 /**************************************************/
102 void delay_ms(unsigned int x)
103 {
104 1 unsigned int i,j;
105 1 i=0;
106 1 for(i=0;i<x;i++)
107 1 {
108 2 j=108;
109 2 ;
110 2 while(j--);
111 2 }
112 1 }
113 /**************************************************/
114
115 /**************************************************
116 Function: SPI_RW();
117
C51 COMPILER V8.05a NRF24L01 08/21/2009 10:54:35 PAGE 3
118 Description:
119 Writes one byte to nRF24L01, and return the byte read
120 from nRF24L01 during write, according to SPI protocol
121 /**************************************************/
122 uchar SPI_RW(uchar byte)
123 {
124 1 uchar bit_ctr;
125 1 for(bit_ctr=0;bit_ctr<8;bit_ctr++) // output 8-bit
126 1 {
127 2 MOSI = (byte & 0x80); // output 'byte', MSB to MOSI
128 2 byte = (byte << 1); // shift next bit into MSB..
129 2 SCK = 1; // Set SCK high..
130 2 byte |= MISO; // capture current MISO bit
131 2 SCK = 0; // ..then set SCK low again
132 2 }
133 1 return(byte); // return read byte
134 1 }
135 /**************************************************/
136
137 /**************************************************
138 Function: SPI_RW_Reg();
139
140 Description:
141 Writes value 'value' to register 'reg'
142 /**************************************************/
143 uchar SPI_RW_Reg(BYTE reg, BYTE value)
144 {
145 1 uchar status;
146 1
147 1 CSN = 0; // CSN low, init SPI transaction
148 1 status = SPI_RW(reg); // select register
149 1 SPI_RW(value); // ..and write value to it..
150 1 CSN = 1; // CSN high again
151 1
152 1 return(status); // return nRF24L01 status byte
153 1 }
154 /**************************************************/
155
156 /**************************************************
157 Function: SPI_Read();
158
159 Description:
160 Read one byte from nRF24L01 register, 'reg'
161 /**************************************************/
162 BYTE SPI_Read(BYTE reg)
163 {
164 1 BYTE reg_val;
165 1
166 1 CSN = 0; // CSN low, initialize SPI communication...
167 1 SPI_RW(reg); // Select register to read from..
168 1 reg_val = SPI_RW(0); // ..then read registervalue
169 1 CSN = 1; // CSN high, terminate SPI communication
170 1
171 1 return(reg_val); // return register value
172 1 }
173 /**************************************************/
174
175 /**************************************************
176 Function: SPI_Read_Buf();
177
178 Description:
179 Reads 'bytes' of bytes from register 'reg'
C51 COMPILER V8.05a NRF24L01 08/21/2009 10:54:35 PAGE 4
180 Typically used to read RX payload, Rx/Tx address
181 /**************************************************/
182 uchar SPI_Read_Buf(BYTE reg, BYTE *pBuf, BYTE bytes)
183 {
184 1 uchar status,byte_ctr;
185 1
186 1 CSN = 0; // Set CSN low, init SPI tranaction
187 1 status = SPI_RW(reg); // Select register to write to and read status byte
188 1
189 1 for(byte_ctr=0;byte_ctr<bytes;byte_ctr++)
190 1 pBuf[byte_ctr] = SPI_RW(0); // Perform SPI_RW to read byte from nRF24L01
191 1
192 1 CSN = 1; // Set CSN high again
193 1
194 1 return(status); // return nRF24L01 status byte
195 1 }
196 /**************************************************/
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -