📄 com.lst
字号:
C51 COMPILER V7.50 COM 11/15/2007 14:43:54 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE COM
OBJECT MODULE PLACED IN com.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE com.c BROWSE DEBUG OBJECTEXTEND
line level source
1
2 /*----------------------------- Program Overview -------------------------------
3 Device Name: AT89S52
4 ROM: 8 K bytes
5 RAM: 512 bytes
6 Chip Basic Functions: 40pin, 32I/O, 16 bit Timer *3, 8 bit UART *1, Eight Interrupt Sources
7 4.0V to 5.5V Operating Range, OSC 11.0592 MHz (0.9216 us)
8 Complier: keil C 750
9 Simulator: keil C 750
10 Programmer:
11 File Name: com.c
12 File Functtion: RF communication function
13 Copyright: XIAZHAOJUN
14 First Version Finished Date: 2007.11.6
15 Others:
16 ------------------------------- Modified Note ----------------------------------
17 Old Version:
18 New Version:
19 New CheckSum:
20 Modifier:
21 Modified Date:
22 Modified Causation:
23 Modified Mean:
24 -------------------------------------------------------------------------------*/
25
26 //----------------------------- Include ----------------------------------------
27 #include <reg52.h>
28 //#include <stdio.h>
29 #include <intrins.h>
30 #include <com.h>
31 #include <lcm.h>
32 #include <fbuzz.h>
33
34 //----------------------------- SFR Definition ---------------------------------
35
36 //<nRF905>
37 sbit TX_EN =P2^6;
38 sbit TRX_CE =P2^5;
39 sbit PWR_UP =P2^4;
40 sbit AM =P3^2;
41 sbit DR =P3^3;
42 sbit CD =P3^5;
43 //<SPI>
44 sbit MISO =P2^3;
45 sbit MOSI =P2^2;
46 sbit SCK =P2^1;
47 sbit CSN =P2^0;
48
49
50
51 //----------------------------- Macro Definition -------------------------------
52 #define uchar unsigned char
53 #define uint unsigned int
54
55 #define WC 0x00 // Write configuration register command
C51 COMPILER V7.50 COM 11/15/2007 14:43:54 PAGE 2
56 #define RC 0x10 // Read configuration register command
57 #define WTP 0x20 // Write TX Payload command
58 #define RTP 0x21 // Read TX Payload command
59 #define WTA 0x22 // Write TX Address command
60 #define RTA 0x23 // Read TX Address command
61 #define RRP 0x24 // Read RX Payload command
62
63 #define CH_NO_FREQ_422_4MHz 0x0000 //工作频率422.4MHz(433MHz频段最低频率)
64 #define CH_NO_FREQ_422_5MHz 0x0001 //工作频率422.5MHz
65 #define CH_NO_FREQ_425_0MHz 0x001a //工作频率425.0MHz
66 #define CH_NO_FREQ_427_5MHz 0x0033 //工作频率427.5MHz
67 #define CH_NO_FREQ_430_0MHz 0x004c //工作频率430.0MHz
68 #define CH_NO_FREQ_433_0MHz 0x006a //工作频率433.0MHz(433MHz频段基准频率)
69 #define CH_NO_FREQ_433_1MHz 0x006b //工作频率433.1MHz
70 #define CH_NO_FREQ_433_2MHz 0x006c //工作频率433.2MHz
71 #define CH_NO_FREQ_434_7MHz 0x007b //工作频率434.7MHz
72 #define CH_NO_FREQ_473_5MHz 0x01ff //工作频率473.5MHz(433MHz频段最高频率)
73
74 #define CH_NO_FREQ_844_8MHz 0x0000 //工作频率844.8MHz(868MHz频段最低频率)
75 #define CH_NO_FREQ_862_0MHz 0x0056 //工作频率862.0MHz
76 #define CH_NO_FREQ_868_0MHz 0x0074 //工作频率868.0MHz(868MHz频段基准频率)
77 #define CH_NO_FREQ_868_2MHz 0x0075 //工作频率868.2MHz
78 #define CH_NO_FREQ_868_4MHz 0x0076 //工作频率868.4MHz
79 #define CH_NO_FREQ_869_8MHz 0x007d //工作频率869.8MHz
80 #define CH_NO_FREQ_895_8MHz 0x00ff //工作频率895.8MHz
81 #define CH_NO_FREQ_896_0MHz 0x0100 //工作频率896.0MHz
82 #define CH_NO_FREQ_900_0MHz 0x0114 //工作频率900.0MHz
83 #define CH_NO_FREQ_902_2MHz 0x011f //工作频率902.2MHz
84 #define CH_NO_FREQ_902_4MHz 0x0120 //工作频率902.4MHz
85 #define CH_NO_FREQ_915_0MHz 0x015f //工作频率915.0MHz(915MHz频段基准频率)
86 #define CH_NO_FREQ_927_8MHz 0x019f //工作频率927.8MHz
87 #define CH_NO_FREQ_947_0MHz 0x01ff //工作频率947.0MHz(915MHz频段最高频率)
88
89 #define CH_NO_FREQ CH_NO_FREQ_433_0MHz //工作频率433.0MHz
90
91 //--------------------------------------------------------------
92 //<RF-Configuration-Register 配置信息>
93 #define CH_NO CH_NO_FREQ //freq=422.4+76/10=430MHz
94 #define HFREQ_PLL 0x00 //433Mhz / 868/915Mhz
95 #define PA_PWR 0x03 //最大输出功率
96 #define RX_RED_PWR 0x00 //接收功率
97 #define AUTO_RETRAN 0x00 //自动重新发送
98 #define RX_AWF 0x04 //Rx 本地接收地址宽度
99 #define TX_AWF 0x04 //Tx 本地发送地址宽度
100 #define RX_PW 0x20 //Rx 本地接收有效数据宽度
101 #define TX_PW 0x20 //Tx 本地发送有效数据宽度
102
103 #define RX_ADDR_Bit0 0xcc //本机地址 最高字节
104 #define RX_ADDR_Bit1 0xcc
105 #define RX_ADDR_Bit2 0xcc
106 #define RX_ADDR_Bit3 0xcc //本机地址 最低字节
107
108 #define UP_CLK_FREQ 0x00 //输出时钟频率
109 #define UP_CLK_EN 0x00 //输出时钟使能
110 #define XOF 0x03 //晶体振荡器频率,必须依据外部晶体的标称频率设置
111 #define CRC_EN 0x01 //CRC校验允许
112 #define CRC_MODE 0x00 //CRC模式 0b0-8位CRC校验位; 0b1-16位CRC校验位 (默认)
113
114
115
116
117
C51 COMPILER V7.50 COM 11/15/2007 14:43:54 PAGE 3
118
119
120
121
122 //-----------------------------------------------------------
123
124 //<将设置信息组合成每个字节的数据信息,此区域无需修改>
125 #define RFConfig_Bit0 (CH_NO & 0xff)
126 #define RFConfig_Bit1 (AUTO_RETRAN<<5 | RX_RED_PWR<<4 | PA_PWR<<2 | HFREQ_PLL<<1 | CH_NO>>8)
127 #define RFConfig_Bit2 (TX_AWF<<4 | RX_AWF)
128 #define RFConfig_Bit3 RX_PW
129 #define RFConfig_Bit4 TX_PW
130 #define RFConfig_Bit5 RX_ADDR_Bit0
131 #define RFConfig_Bit6 RX_ADDR_Bit1
132 #define RFConfig_Bit7 RX_ADDR_Bit2
133 #define RFConfig_Bit8 RX_ADDR_Bit3
134 #define RFConfig_Bit9 (CRC_MODE<<7 | CRC_EN<<6 | XOF<<3 | UP_CLK_EN<<2 | UP_CLK_FREQ)
135
136 //----------------------------- Variable Definition ----------------------------
137 uchar data TxBuf[32];
138 uchar data RxBuf[32];
139
140 uchar data comcmd;
141 uchar data comdata;
142 //uchar data comdata_old;
143 uchar data dataresult;
144
145
146 //----------------------------- Bit Definition ---------------------------------
147 bit b_send_fg;
148
149 uchar bdata DATA_BUF;
150 sbit flag =DATA_BUF^7;
151 sbit flag1 =DATA_BUF^0;
152
153 //----------------------------- RF Config -------------------------------------
154 typedef struct
155 {
156 uchar n;
157 uchar buf[10];
158 }RFConfig;
159
160 code RFConfig RxTxConf =
161 {
162 10,
163 RFConfig_Bit0,
164 RFConfig_Bit1,
165 RFConfig_Bit2,
166 RFConfig_Bit3,
167 RFConfig_Bit4,
168 RFConfig_Bit5,
169 RFConfig_Bit6,
170 RFConfig_Bit7,
171 RFConfig_Bit8,
172 RFConfig_Bit9
173 // 0x01, 0x0c, 0x44, 0x20, 0x20, 0xcc, 0xcc, 0xcc,0xcc, 0x58
174 };
175 // The content of this struct is nRF905's initialize data.初始化数据
176 // CH_NO=1;433MHZ;Normal Opration,No Retrans;RX,TX Address is 4 Bytes
177 // RX TX Payload Width is 32 Bytes;Disable Extern Clock;Fosc=16MHZ
178 // 8 Bits CRC And enable
179
C51 COMPILER V7.50 COM 11/15/2007 14:43:54 PAGE 4
180 //----------------------------- Program Code -----------------------------------
181 /*----------------------------- Subroutine -------------------------------------
182 Name: Delay
183 Function:
184 Entry:
185 Exit:
186 Caution:
187 -------------------------------------------------------------------------------*/
188 void Delay(uchar n)
189 {
190 1 uint i;
191 1 while(n--)
192 1 for(i=0;i<80;i++);
193 1 }
194 /*----------------------------- Subroutine -------------------------------------
195 Name: 905 SPI Iinitial
196 Function:
197 Entry:
198 Exit:
199 Caution:
200 -------------------------------------------------------------------------------*/
201 void SPI_Init(void){
202 1 CSN=1; // Spi disable
203 1 SCK=0; // Spi clock line init low
204 1 MOSI=1;
205 1 MISO=1;
206 1 }
207 /*----------------------------- Subroutine -------------------------------------
208 Name: nRF905init
209 Function:
210 Entry:
211 Exit:
212 Caution:
213 -------------------------------------------------------------------------------*/
214 void nRF905Init(void){
215 1 SPI_Init();
216 1 /*ICO*/
217 1 DR=1; // Init DR for input
218 1 AM=1; // Init AM for input
219 1 CD=1; // Init CD for input
220 1
221 1 /*模式设置*/
222 1 PWR_UP=1; // nRF905 power on
223 1 TRX_CE=0; // Set nRF905 in standby mode
224 1 TX_EN=0; // set radio in Rx mode
225 1 }
226 /*----------------------------- Subroutine -------------------------------------
227 Name: setRxMode
228 Function:
229 Entry:
230 Exit:
231 Caution:
232 -------------------------------------------------------------------------------*/
233 void SetRxMode(void){
234 1 TX_EN=0;
235 1 TRX_CE=1;
236 1 Delay(1); // delay for mode change(>=650us)
237 1 }
238 /*----------------------------- Subroutine -------------------------------------
239 Name: setTxMode
240 Function:
241 Entry:
C51 COMPILER V7.50 COM 11/15/2007 14:43:54 PAGE 5
242 Exit:
243 Caution:
244 -------------------------------------------------------------------------------*/
245 void SetTxMode(void){
246 1 TX_EN=1;
247 1 TRX_CE=0;
248 1 Delay(1); // delay for mode change(>=650us)
249 1 }
250 /*----------------------------- Subroutine -------------------------------------
251 Name: spi write
252 Function:
253 Entry:
254 Exit:
255 Caution:
256 -------------------------------------------------------------------------------*/
257 void SpiWrite(uchar byte){
258 1 uchar i;
259 1 DATA_BUF=byte; // Put function's parameter into a bdata variable
260 1 for (i=0;i<8;i++) // Setup byte circulation bits
261 1 {
262 2
263 2 if (flag) // Put DATA_BUF.7 on data line
264 2 MOSI=1;
265 2 else
266 2 MOSI=0;
267 2 SCK=1; // Set clock line high
268 2 DATA_BUF=DATA_BUF<<1; // Shift DATA_BUF
269 2 SCK=0; // Set clock line low
270 2 }
271 1 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -