📄 ex1c.lst
字号:
C51 COMPILER V7.08 EX1C 06/06/2005 17:50:27 PAGE 1
C51 COMPILER V7.08, COMPILATION OF MODULE EX1C
OBJECT MODULE PLACED IN ex1c.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ex1c.c BROWSE DEBUG OBJECTEXTEND
line level source
1 /*= ex1c.c =====================================================================
2 *
3 * Copyright (C) 2003, 2004 2005 WWW.C51RF.COM
4 *
5 * This file is distributed in the hope that it will be useful, but WITHOUT
6 * WARRANTY OF ANY KIND.
7 *
8 * Author(s): WL ------ WWW. C51RF.COM
9 *
10 * DESCRIPTION:
11 *
12 * demo program.
13 *
14 * The functioN demo how to debug 24e1,
15 *
16 * COMPILER:
17 *
18 * This program has been tested with Keil V7.06
19 *
20 * $Revision: 1.12
21 *
22 *==============================================================================
23 */
24 #include <Nordic\reg24e1.h>
25 #include "ISD51.H"
26 sbit LEDR =P0^4;
27 sbit LEDG =P0^5;
28 sbit KEYR =P0^3;
29 sbit KEYT =P0^6;
30
31 unsigned char aaa,bbb;
32 static unsigned char idata buf[32];
33 const char ID[] = "24E1DEMO1234567907654321";
34 const unsigned char code rnd_tab[256] =
35 {
36
37 0x28, 0x29, 0x38, 0x07, 0x19, 0x17, 0x2F, 0x1F, 0x14, 0x16, 0x1F, 0x06, 0x38, 0x1B, 0x3B, 0x33,
38 0x33, 0x2F, 0x37, 0x1A, 0x32, 0x15, 0x19, 0x34, 0x1B, 0x2D, 0x13, 0x02, 0x3F, 0x18, 0x10, 0x10,
39 0x0A, 0x1D, 0x0D, 0x37, 0x3D, 0x0B, 0x2A, 0x25, 0x1F, 0x20, 0x41, 0x21, 0x2F, 0x2A, 0x36, 0x09,
40 0x1C, 0x2C, 0x0F, 0x1E, 0x39, 0x03, 0x06, 0x03, 0x2B, 0x0A, 0x1D, 0x02, 0x24, 0x3A, 0x32, 0x10,
41 0x16, 0x16, 0x13, 0x12, 0x20, 0x06, 0x13, 0x1F, 0x0D, 0x41, 0x1E, 0x08, 0x3D, 0x31, 0x09, 0x16,
42 0x23, 0x12, 0x2D, 0x12, 0x31, 0x1C, 0x36, 0x0B, 0x11, 0x21, 0x37, 0x13, 0x38, 0x41, 0x0B, 0x32,
43 0x1B, 0x33, 0x20, 0x29, 0x0E, 0x05, 0x41, 0x1E, 0x05, 0x0C, 0x38, 0x1D, 0x20, 0x2F, 0x29, 0x39,
44 0x3D, 0x04, 0x26, 0x10, 0x12, 0x36, 0x3B, 0x08, 0x3D, 0x3C, 0x1A, 0x24, 0x08, 0x07, 0x35, 0x15,
45 0x2A, 0x40, 0x2C, 0x11, 0x31, 0x28, 0x2A, 0x1E, 0x02, 0x07, 0x19, 0x32, 0x28, 0x39, 0x1A, 0x28,
46 0x19, 0x22, 0x03, 0x21, 0x39, 0x09, 0x03, 0x0F, 0x3E, 0x2D, 0x0D, 0x37, 0x18, 0x3E, 0x09, 0x25,
47 0x26, 0x11, 0x36, 0x1A, 0x18, 0x25, 0x3E, 0x29, 0x08, 0x3C, 0x2B, 0x33, 0x02, 0x0A, 0x05, 0x0A,
48 0x1C, 0x2C, 0x07, 0x23, 0x3E, 0x1B, 0x3F, 0x2E, 0x3B, 0x31, 0x2B, 0x24, 0x35, 0x26, 0x1D, 0x2E,
49 0x11, 0x3C, 0x15, 0x2B, 0x15, 0x24, 0x2C, 0x27, 0x0D, 0x34, 0x14, 0x23, 0x21, 0x04, 0x3A, 0x27,
50 0x0F, 0x40, 0x27, 0x0B, 0x30, 0x2E, 0x17, 0x25, 0x3C, 0x34, 0x40, 0x34, 0x0C, 0x2D, 0x30, 0x18,
51 0x40, 0x0F, 0x22, 0x26, 0x27, 0x3F, 0x30, 0x22, 0x30, 0x3F, 0x23, 0x14, 0x3A, 0x14, 0x3B, 0x0C,
52 0x06, 0x04, 0x05, 0x3A, 0x35, 0x0E, 0x0E, 0x0C, 0x17, 0x1C, 0x35, 0x0E, 0x04, 0x2E, 0x17, 0x22
53 };
54
55 #define ADDR_INDEX 8 // Index to default address bytes in RxTxConf.buf
C51 COMPILER V7.08 EX1C 06/06/2005 17:50:27 PAGE 2
56 #define ADDR_COUNT 4 // Number of address bytes
57
58 static unsigned char idata rfAddress[ADDR_COUNT];
59
60 struct RFConfig
61 {
62 unsigned char n;
63 unsigned char buf[15];
64 };
65
66 typedef struct RFConfig RFConfig;
67
68 const RFConfig RxTxConf =
69 {
70 15,
71 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
72 0xcd, 0xef, 0x12, 0xaa, 0x83, 0x4f, 0x04 //6f to 4f 250k 08/08/2004
73 };
74
75 static unsigned char seq, hopIdx, nBytes;
76 static unsigned rxTout, txTout;
77
78 const char hex_tab[] = "0123456789ABCDEF"; // ASCII-hex table used by hex-output routines
79
80 static volatile unsigned idata timer[2]; // Two utility timers used in radio.c
81 static volatile unsigned char t0lrel, t0hrel;
82
83 void Delay100us(unsigned char n)
84 {
85 1 unsigned char i;
86 1 while(n--)
87 1 for(i=0;i<35;i++)
88 1 ;
89 1 }
90
91 unsigned char SpiReadWrite(unsigned char b)
92 {
93 1 EXIF &= ~0x20; // Clear SPI interrupt
94 1 SPI_DATA = b; // Move byte to send to SPI data register
95 1 while((EXIF & 0x20) == 0x00) // Wait until SPI hs finished transmitting
96 1 ;
97 1 return SPI_DATA;
98 1 }
99
100 //void PutString(const char *s)
101 //{
102 // while(*s != 0)
103 // PutChara(*s++);
104 //}
105
106 void TimerInit(void)
107 {
108 1 timer[0] = timer[1] = 0;
109 1
110 1 TR0 = 0;
111 1 TMOD &= ~0x03;
112 1 TMOD |= 0x01; // mode 1
113 1 CKCON |= 0x08; // T0M = 1 (/4 timer clock)
114 1 t0lrel = 0x60; // 1KHz tick...
115 1 t0hrel = 0xF0; // ... = 65536-16e6/(4*1e3) = F060h
116 1 TF0 = 0; // Clear any pending Timer0 interrupts
117 1 TR0 = 1; // Start Timer0
C51 COMPILER V7.08 EX1C 06/06/2005 17:50:27 PAGE 3
118 1 ET0 = 1; // Enable Timer0 interrupt
119 1 }
120
121 void Timer0ISR (void) interrupt 1 using 1
122 {
123 1 TF0 = 0; // Clear Timer0 interrupt
124 1 TH0 = t0hrel; // Reload Timer0 high byte
125 1 TL0 = t0lrel; // Reload Timer0 low byte
126 1 timer[0]++; // Increment timer[0]
127 1 timer[1]++; // Increment timer[1
128 1 }
129
130 void ResetTimer(unsigned char n)
131 {
132 1 ET0 = 0; // Disable Timer0 interrupt
133 1 timer[n & 0x01] = 0; // Clear timer[n]
134 1 ET0 = 1; // Enable Timer0 interrupt
135 1 }
136
137 unsigned GetTimer(unsigned char n)
138 {
139 1 unsigned tmp;
140 1 ET0 = 0; // Disable Timer0 interrupt
141 1 tmp = timer[n]; // Clear timer[n]
142 1 ET0 = 1; // Enable Timer0 interrupt
143 1 return tmp;
144 1 }
145 void Init(void)
146 {
147 1 TH1 = 243; // 19200@16MHz (when T1M=1 and SMOD=1)
148 1 CKCON |= 0x10; // T1M=1 (/4 timer clock)
149 1 PCON = 0x80; // SMOD=1 (double baud rate)
150 1 SCON = 0x52; // Serial mode1, enable receiver
151 1 TMOD = 0x20; // Timer1 8bit auto reload
152 1 TR1 = 1; // Start timer1
153 1 //P0_DIR |= 0x02; // P0.1 (RxD) is an input
154 1 P0_ALT |= 0x06; // Select alternate functions on pins P0.1 and P0.2
155 1 P0_DIR=P0_DIR&0x1F; //led p0.6 p0.5 P0.7 output
156 1 P0_DIR=P0_DIR&0xCF; //led p0.4 p0.5 output
157 1 P0_DIR=P0_DIR |= 0x48; // P0.3 is input p0.6 input
158 1 ES = 0;
159 1 EA=1;
160 1 TimerInit();
161 1 }
162 //------------------------------------------------------------
163
164 //------------------------------------------------------------
165
166
167 static void SetRxMode(void)
168 {
169 1 // Put the transceiver into receive mode on current hopping frequency:
170 1 unsigned char ch;
171 1 CS = 1;
172 1 Delay100us(0);
173 1 ch = rnd_tab[hopIdx] << 1;
174 1 SpiReadWrite(ch | 0x01);
175 1 CS = 0;
176 1 }
177
178 static void SetTxMode(void)
179 {
C51 COMPILER V7.08 EX1C 06/06/2005 17:50:27 PAGE 4
180 1 // Put the transceiver into transmit mode on current hopping frequency:
181 1 unsigned char ch;
182 1 CS = 1;
183 1 Delay100us(0);
184 1 ch = rnd_tab[hopIdx] << 1;
185 1 SpiReadWrite(ch);
186 1 CS = 0;
187 1 }
188
189 static void InitCommon(unsigned char *pAddr)
190 {
191 1 unsigned char i;
192 1
193 1 hopIdx = 0; // Start at index #0 in the channel table above
194 1 if (pAddr != 0)
195 1 {
196 2 for(i=2;i<ADDR_INDEX;i++)
197 2 SpiReadWrite(RxTxConf.buf[i]);
198 2 for(i=0;i<ADDR_COUNT;i++)
199 2 {
200 3 rfAddress[i] = pAddr[i];
201 3 SpiReadWrite(pAddr[i]);
202 3 }
203 2 for(i=0;i<3;i++)
204 2 SpiReadWrite(RxTxConf.buf[RxTxConf.n-3+i]);
205 2 } else
206 1 {
207 2 for (i=0;i<ADDR_COUNT;i++)
208 2 {
209 3 rfAddress[i] = RxTxConf.buf[ADDR_INDEX+i];
210 3 }
211 2 for(i=2;i<RxTxConf.n;i++)
212 2 {
213 3 SpiReadWrite(RxTxConf.buf[i]);
214 3 }
215 2 }
216 1 CS = 0;
217 1 PWR_UP = 1; // Turn on power on radio
218 1 Delay100us(30); // Wait > 3ms
219 1 }
220
221 static void TransmitBytes(unsigned char *pBuf, unsigned char msgid)
222 {
223 1 // Transmit one packet with the format specified in the header of this file:
224 1 unsigned char i;
225 1
226 1 SetTxMode();
227 1 CE = 1;
228 1 Delay100us(1);
229 1
230 1 for (i=0;i<ADDR_COUNT;i++)
231 1 {
232 2 SpiReadWrite(rfAddress[i]);
233 2 }
234 1 SpiReadWrite(msgid); // All packets start with a one byte ID
235 1 for (i=0;i<nBytes;i++)
236 1 {
237 2 SpiReadWrite(pBuf[i]);
238 2 }
239 1 CE = 0;
240 1 Delay100us(13); // Wait until finished transmitting (200us + 256us)//dela
-y(5)
C51 COMPILER V7.08 EX1C 06/06/2005 17:50:27 PAGE 5
241 1 } // 250k to delay100 (13)
242
243 static void SendAck(unsigned char msgid)
244 {
245 1 // Send a one byte acknowledge
246 1 unsigned char i;
247 1
248 1 SetTxMode();
249 1 CE = 1;
250 1 Delay100us(1);
251 1
252 1 for (i=0;i<ADDR_COUNT;i++)
253 1 {
254 2 SpiReadWrite(rfAddress[i]);
255 2 }
256 1 SpiReadWrite(msgid); // An ACK contains only the ID and no data
257 1 CE = 0;
258 1 Delay100us(5); // Wait until finished transmitting delay100(3)
259 1 // 250K TO Delay delay100 (5) 08/08/2004
260 1 }
261
262
263 static unsigned char ReceiveBytes(unsigned char *pBuf)
264 {
265 1 unsigned char i, cmd;
266 1
267 1 SetRxMode();
268 1 CE = 1;
269 1 ResetTimer(1);
270 1 while(DR1 == 0)
271 1 {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -