?? rc500.lst
字號(hào):
C51 COMPILER V7.06 RC500 12/15/2008 16:23:27 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE RC500
OBJECT MODULE PLACED IN RC500.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE RC500.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 #include <REGX52.H>
2
3 #include <absacc.h>
4 #include <string.h>
5
6 #include <RC500Err.h>
7 #include <RC500Reg.h>
8 #include <RC500.h>
9
10 typedef struct
11 {
12 unsigned char cmd;
13 char status;
14 unsigned char nBytesSent;
15 unsigned char nBytesToSend;
16 unsigned char nBytesReceived;
17 unsigned short nBitsReceived;
18 unsigned char irqSource;
19 unsigned char collPos;
20
21 } MfCmdInfo;
22 #define ResetInfo(info) \
24 info.status = MI_OK;\
25 info.irqSource = 0;\
26 info.nBytesSent = 0;\
27 info.nBytesToSend = 0;\
28 info.nBytesReceived = 0;\
29 info.nBitsReceived = 0;\
30 info.collPos = 0;
31
32 // 往一個(gè)地址寫一個(gè)數(shù)據(jù)
33 //void WriteRawIO(unsigned char Address,unsigned char value);
34 // 從一個(gè)地址讀出一個(gè)數(shù)據(jù)
35 //unsigned char ReadRawIO(unsigned char Address);
36 // 往一個(gè)地址寫一個(gè)數(shù)據(jù)(EEPROM)
37 //void WriteIO(unsigned char Address, unsigned char value);
38 // 從一個(gè)地址讀出一個(gè)數(shù)據(jù)(EEPROM)
39 // unsigned char ReadIO(unsigned char Address);
40 // 設(shè)置定時(shí)時(shí)間
41 void M500PcdSetTmo(unsigned char tmoLength);
42 // Request Command defined in ISO14443(Mifare)
43 char M500PcdCmd(unsigned char cmd,
44 volatile unsigned char data *rcv,
45 MfCmdInfo idata *info);
46 // 置一個(gè)bit
47 char SetBitMask(unsigned char reg,unsigned char mask);
48 // 清一個(gè)bit
49 char ClearBitMask(unsigned char reg,unsigned char mask);
50 //
51 void FlushFIFO(void);
52 // Value format operations for Mifare Standard card ICs
53 char M500PiccValue(unsigned char dd_mode,
54 unsigned char addr,
55 unsigned char *value,
C51 COMPILER V7.06 RC500 12/15/2008 16:23:27 PAGE 2
56 unsigned char trans_addr);
57 // Set card in HALT-state
58 // 終止卡的操作
59 char M500PiccHalt(void);
60 // Reset the MF RC500
61 //char M500PcdReset(void);
63 char M500PcdConfig(void);
64 // Key loading into the MF RC500's EEPROM
65 char M500PcdLoadKeyE2(unsigned char key_type,
66 unsigned char sector,
67 unsigned char *uncoded_keys);
68 // Write the MF RC500's EEPROM
69 char PcdWriteE2(unsigned int startaddr,
70 unsigned char length,
71 unsigned char* _data);
72 // Select Command defined in ISO14443(MIFARE)
73 char M500PcdMfOutSelect(unsigned char type);
74 // Request Command defined in ISO14443(MIFARE)
75 // Request,Anticoll,Select,return CardType(2 bytes)+CardSerialNo(4 bytes)
76 // 尋卡,防沖突,選擇卡 返回卡類型(2 bytes)+ 卡系列號(hào)(4 bytes)
77 char M500PiccCommonRequest(unsigned char req_code,unsigned char *atq);
78 // Cascaded Anti-Collision Command defined in ISO14443(MIFARE)
79 // 防沖突 讀卡的系列號(hào) MLastSelectedSnr
80 char M500PiccCascAnticoll (unsigned char bcnt,unsigned char *snr);
81 // Cascaded Select command defined in ISO14443(MIFARE)
82 // 選擇卡 Select Card
83 char M500PiccCascSelect(unsigned char *snr,unsigned char *sak);
84 // Key loading into the MF RC500's EEPROM
85 // 校驗(yàn)卡密碼(E2)
86 char M500PiccAuthE2( unsigned char auth_mode,unsigned char *snr,
87 unsigned char keynr,unsigned char block);
88 // Authentication key coding
89 char M500HostCodeKey( unsigned char *uncoded, unsigned char *coded);
90 // Authentication with direct key loading from the uC
91 // 直接校驗(yàn)密碼
92 //char M500PiccAuthKey( unsigned char auth_mode,
93 // unsigned char *snr,
94 // unsigned char *keys,
95 // unsigned char block);
96 //
97 char M500PiccAuthState( unsigned char auth_mode,unsigned char *snr,unsigned char block);
98 // Read the mifare card
99 // 讀卡
100 char M500PiccRead(unsigned char addr,unsigned char *_data);
101 // Write the mifare card
102 // 寫卡 下載密碼
103 char M500PiccWrite( unsigned char addr,unsigned char *_data);
104 // Reset Rf Card
105 char M500PcdRfReset(unsigned char ms);
106 // Config
107 char MfConfig(void);
108
109 static volatile MfCmdInfo idata MInfo;
110 //static volatile MfCmdInfo *MpIsrInfo = 0;
111 static volatile MfCmdInfo *MpIsrInfo;
112 //static volatile unsigned char *MpIsrOut = 0;
113 static volatile unsigned char *MpIsrOut;
114
115 unsigned char SerBuffer[20];
116
117 void delay_100us()
C51 COMPILER V7.06 RC500 12/15/2008 16:23:27 PAGE 3
118 {
119 1 unsigned char i=100;
120 1 while(i--);
121 1 }
122
123 void delay_ms(unsigned int ms)
124 {
125 1 unsigned char i;
126 1 while(ms--)
127 1 {
128 2 i=112;
129 2 while(i--);
130 2 }
131 1
132 1 }
133
134 ///////////////////////////////////////////////////////////////////////
135 // 往一個(gè)地址寫一個(gè)數(shù)據(jù)
136 ///////////////////////////////////////////////////////////////////////
137 void WriteRawIO(unsigned char Address,unsigned char value)
138 {
139 1 XBYTE[Address]=value;
140 1 }
141
142 ///////////////////////////////////////////////////////////////////////
143 // 從一個(gè)地址讀出一個(gè)數(shù)據(jù)
144 ///////////////////////////////////////////////////////////////////////
145 unsigned char ReadRawIO(unsigned char Address)
146 {
147 1 return XBYTE[Address];
148 1 }
149
150 ///////////////////////////////////////////////////////////////////////
151 // 往一個(gè)地址寫一個(gè)數(shù)據(jù)(EEPROM)
152 ///////////////////////////////////////////////////////////////////////
153 void WriteIO(unsigned char Address, unsigned char value)
154 {
155 1 WriteRawIO(0x00,GetRegPage(Address));
156 1 WriteRawIO(Address,value);
157 1 }
158
159 ///////////////////////////////////////////////////////////////////////
160 // 從一個(gè)地址讀出一個(gè)數(shù)據(jù)(EEPROM)
161 ///////////////////////////////////////////////////////////////////////
162 unsigned char ReadIO(unsigned char Address)
163 {
164 1 WriteRawIO(0x00,GetRegPage(Address));
165 1 return ReadRawIO(Address);
166 1 }
167
168 ///////////////////////////////////////////////////////////////////////
169 // 設(shè)置定時(shí)時(shí)間
170 ///////////////////////////////////////////////////////////////////////
171 void M500PcdSetTmo(unsigned char tmoLength)
172 {
173 1 switch(tmoLength)
174 1 {
175 2 case 1:
176 2 WriteIO(RegTimerClock,0x07);
177 2 WriteIO(RegTimerReload,0x6a);
178 2 break;
179 2 case 2:
C51 COMPILER V7.06 RC500 12/15/2008 16:23:27 PAGE 4
180 2 WriteIO(RegTimerClock,0x07);
181 2 WriteIO(RegTimerReload,0xa0);
182 2 break;
183 2 case 3:
184 2 WriteIO(RegTimerClock,0x09);
185 2 WriteIO(RegTimerReload,0xa0);
186 2 break;
187 2 case 4:
188 2 WriteIO(RegTimerClock,0x09);
189 2 WriteIO(RegTimerReload,0xff);
190 2 break;
191 2 case 5:
192 2 WriteIO(RegTimerClock,0x0b);
193 2 WriteIO(RegTimerReload,0xff);
194 2 break;
195 2 case 6:
196 2 WriteIO(RegTimerClock,0x0d);
197 2 WriteIO(RegTimerReload,0xff);
198 2 break;
199 2 case 7:
200 2 WriteIO(RegTimerClock,0x0f);
201 2 WriteIO(RegTimerReload,0xff);
202 2 break;
203 2 default:
204 2 WriteIO(RegTimerClock,0x07);
205 2 WriteIO(RegTimerReload,tmoLength);
206 2 break;
207 2 }
208 1 }
209
210 ///////////////////////////////////////////////////////////////////////
211 // Request Command defined in ISO14443(Mifare)
212 ///////////////////////////////////////////////////////////////////////
213 char M500PcdCmd(unsigned char cmd,
214 volatile unsigned char data *rcv,
215 MfCmdInfo idata *info)
216 {
217 1 char idata status = MI_OK;
218 1 char idata tmpStatus ;
219 1 unsigned char idata lastBits;
220 1 unsigned int idata timecnt = 0;
221 1 unsigned char idata irqEn = 0x00;
222 1 unsigned char idata waitFor = 0x00;
223 1 unsigned char idata timerCtl = 0x00;
224 1
225 1 WriteIO(RegInterruptEn,0x7F);
226 1 WriteIO(RegInterruptRq,0x7F);
227 1 WriteIO(RegCommand,PCD_IDLE);
228 1
229 1 FlushFIFO();
230 1 MpIsrInfo = info;
231 1 MpIsrOut = rcv;
232 1 info->irqSource = 0x00;
233 1 switch(cmd)
234 1 {
235 2 case PCD_IDLE:
236 2 irqEn = 0x00;
237 2 waitFor = 0x00;
238 2 break;
239 2 case PCD_WRITEE2:
240 2 irqEn = 0x11;
241 2 waitFor = 0x10;
C51 COMPILER V7.06 RC500 12/15/2008 16:23:27 PAGE 5
242 2 break;
243 2 case PCD_READE2:
244 2 irqEn = 0x07;
245 2 waitFor = 0x04;
246 2 break;
247 2 case PCD_LOADCONFIG:
248 2 case PCD_LOADKEYE2:
249 2 case PCD_AUTHENT1:
250 2 irqEn = 0x05;
251 2 waitFor = 0x04;
252 2 break;
253 2 case PCD_CALCCRC:
254 2 irqEn = 0x11;
255 2 waitFor = 0x10;
256 2 break;
257 2 case PCD_AUTHENT2:
258 2 irqEn = 0x04;
259 2 waitFor = 0x04;
260 2 break;
261 2 case PCD_RECEIVE:
262 2 info->nBitsReceived = -(ReadIO(RegBitFraming) >> 4);
263 2 irqEn = 0x06;
264 2 waitFor = 0x04;
265 2 break;
266 2 case PCD_LOADKEY:
267 2 irqEn = 0x05;
268 2 waitFor = 0x04;
269 2 break;
270 2 case PCD_TRANSMIT:
271 2 irqEn = 0x05;
272 2 waitFor = 0x04;
273 2 break;
274 2 case PCD_TRANSCEIVE:
275 2 info->nBitsReceived = -(ReadIO(RegBitFraming) >> 4);
276 2 irqEn = 0x3D;
277 2 waitFor = 0x04;
278 2 break;
279 2 default:
280 2 status = MI_UNKNOWN_COMMAND;
281 2 }
282 1 if (status == MI_OK)
283 1 {
284 2 irqEn |= 0x20;
285 2 waitFor |= 0x20;
286 2 timecnt=1000;
287 2 WriteIO(RegInterruptEn,irqEn | 0x80);
288 2 WriteIO(RegCommand,cmd);
289 2 while (!(MpIsrInfo->irqSource & waitFor||!(timecnt--)));
290 2 WriteIO(RegInterruptEn,0x7F);
291 2 WriteIO(RegInterruptRq,0x7F);
292 2 SetBitMask(RegControl,0x04);
293 2 WriteIO(RegCommand,PCD_IDLE);
294 2 if (!(MpIsrInfo->irqSource & waitFor))
295 2 {
296 3 status = MI_ACCESSTIMEOUT;
297 3 }
298 2 else
299 2 {
300 3 status = MpIsrInfo->status;
301 3 }
302 2 if (status == MI_OK)
303 2 {
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -