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