📄 m500auc.lst
字号:
C51 COMPILER V7.50 M500AUC 06/15/2005 09:19:43 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE M500AUC
OBJECT MODULE PLACED IN M500AuC.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE M500AuC.c BROWSE DEBUG OBJECTEXTEND
line level source
1 #define M500_GLOBALS
2
3 #include <string.h>
4 #include <stdio.h>
5 #include <absacc.h>
6 #include <intrins.h>
7
8 #include "Mfreg500.h"
9 #include "MfErrNo.h"
10 //#include "reg52.h"
11 #include "M500AuC.h"
12 #include "wiegand.h"
13
14 #define GetRegPage(addr) (0x80 | (addr>>3))
15 #define nocard 0
16 #define mifare1 1
17 #define mifarepro 2
18 #define mifarelight 3
19 #define unknowncard 4
20 #define NO_TIMER2 1
21 #define Debug
22
23 sbit SPEAKER = P1^7;
24 sbit GREEN = P1^4;
25 sbit RED = P1^3;
26 ///////////////////////////////////////////////////////////////////////
27 // 往一个地址写一个数据
28 ///////////////////////////////////////////////////////////////////////
29 void WriteRawIO(unsigned char Address,unsigned char value)
30 {
31 1 XBYTE[Address]=value;
32 1 }
33
34 ///////////////////////////////////////////////////////////////////////
35 // 从一个地址读出一个数据
36 ///////////////////////////////////////////////////////////////////////
37 unsigned char ReadRawIO(unsigned char Address)
38 {
39 1 return XBYTE[Address];
40 1 }
41
42 ///////////////////////////////////////////////////////////////////////
43 // 往一个地址写一个数据(EEPROM)
44 ///////////////////////////////////////////////////////////////////////
45 void WriteIO(unsigned char Address, unsigned char value)
46 {
47 1 WriteRawIO(0x00,GetRegPage(Address));
48 1 WriteRawIO(Address,value);
49 1 }
50
51 ///////////////////////////////////////////////////////////////////////
52 // 从一个地址读出一个数据(EEPROM)
53 ///////////////////////////////////////////////////////////////////////
54 unsigned char ReadIO(unsigned char Address)
55 {
C51 COMPILER V7.50 M500AUC 06/15/2005 09:19:43 PAGE 2
56 1 WriteRawIO(0x00,GetRegPage(Address));
57 1 return ReadRawIO(Address);
58 1 }
59
60 ///////////////////////////////////////////////////////////////////////
61 // 设置定时时间
62 ///////////////////////////////////////////////////////////////////////
63 void M500PcdSetTmo(unsigned char tmoLength)
64 {
65 1 switch(tmoLength)
66 1 {
67 2 case 1:
68 2 WriteIO(RegTimerClock,0x07);
69 2 WriteIO(RegTimerReload,0x6a);
70 2 break;
71 2 case 2:
72 2 WriteIO(RegTimerClock,0x07);
73 2 WriteIO(RegTimerReload,0xa0);
74 2 break;
75 2 case 3:
76 2 WriteIO(RegTimerClock,0x09);
77 2 WriteIO(RegTimerReload,0xa0);
78 2 break;
79 2 case 4:
80 2 WriteIO(RegTimerClock,0x09);
81 2 WriteIO(RegTimerReload,0xff);
82 2 break;
83 2 case 5:
84 2 WriteIO(RegTimerClock,0x0b);
85 2 WriteIO(RegTimerReload,0xff);
86 2 break;
87 2 case 6:
88 2 WriteIO(RegTimerClock,0x0d);
89 2 WriteIO(RegTimerReload,0xff);
90 2 break;
91 2 case 7:
92 2 WriteIO(RegTimerClock,0x0f);
93 2 WriteIO(RegTimerReload,0xff);
94 2 break;
95 2 default:
96 2 WriteIO(RegTimerClock,0x07);
97 2 WriteIO(RegTimerReload,tmoLength);
98 2 break;
99 2 }
100 1 }
101
102 ///////////////////////////////////////////////////////////////////////
103 // Request Command defined in ISO14443(Mifare)
104 ///////////////////////////////////////////////////////////////////////
105 char M500PcdCmd(unsigned char cmd,
106 volatile unsigned char data *rcv,
107 MfCmdInfo idata *info)
108 {
109 1 char idata status = MI_OK;
110 1 char idata tmpStatus ;
111 1 unsigned char idata lastBits;
112 1 unsigned int idata timecnt = 0;
113 1 unsigned char idata irqEn = 0x00;
114 1 unsigned char idata waitFor = 0x00;
115 1 unsigned char idata timerCtl = 0x00;
116 1
117 1 WriteIO(RegInterruptEn,0x7F);
C51 COMPILER V7.50 M500AUC 06/15/2005 09:19:43 PAGE 3
118 1 WriteIO(RegInterruptRq,0x7F);
119 1 WriteIO(RegCommand,PCD_IDLE);
120 1
121 1 FlushFIFO();
122 1 MpIsrInfo = info;
123 1 MpIsrOut = rcv;
124 1 info->irqSource = 0x00;
125 1 switch(cmd)
126 1 {
127 2 case PCD_IDLE:
128 2 irqEn = 0x00;
129 2 waitFor = 0x00;
130 2 break;
131 2 case PCD_WRITEE2:
132 2 irqEn = 0x11;
133 2 waitFor = 0x10;
134 2 break;
135 2 case PCD_READE2:
136 2 irqEn = 0x07;
137 2 waitFor = 0x04;
138 2 break;
139 2 case PCD_LOADCONFIG:
140 2 case PCD_LOADKEYE2:
141 2 case PCD_AUTHENT1:
142 2 irqEn = 0x05;
143 2 waitFor = 0x04;
144 2 break;
145 2 case PCD_CALCCRC:
146 2 irqEn = 0x11;
147 2 waitFor = 0x10;
148 2 break;
149 2 case PCD_AUTHENT2:
150 2 irqEn = 0x04;
151 2 waitFor = 0x04;
152 2 break;
153 2 case PCD_RECEIVE:
154 2 info->nBitsReceived = -(ReadIO(RegBitFraming) >> 4);
155 2 irqEn = 0x06;
156 2 waitFor = 0x04;
157 2 break;
158 2 case PCD_LOADKEY:
159 2 irqEn = 0x05;
160 2 waitFor = 0x04;
161 2 break;
162 2 case PCD_TRANSMIT:
163 2 irqEn = 0x05;
164 2 waitFor = 0x04;
165 2 break;
166 2 case PCD_TRANSCEIVE:
167 2 info->nBitsReceived = -(ReadIO(RegBitFraming) >> 4);
168 2 irqEn = 0x3D;
169 2 waitFor = 0x04;
170 2 break;
171 2 default:
172 2 status = MI_UNKNOWN_COMMAND;
173 2 }
174 1 if (status == MI_OK)
175 1 {
176 2 irqEn |= 0x20;
177 2 waitFor |= 0x20;
178 2 timecnt=1000;
179 2 WriteIO(RegInterruptEn,irqEn | 0x80);
C51 COMPILER V7.50 M500AUC 06/15/2005 09:19:43 PAGE 4
180 2 WriteIO(RegCommand,cmd);
181 2 while (!(MpIsrInfo->irqSource & waitFor||!(timecnt--)));
182 2 WriteIO(RegInterruptEn,0x7F);
183 2 WriteIO(RegInterruptRq,0x7F);
184 2 SetBitMask(RegControl,0x04);
185 2 WriteIO(RegCommand,PCD_IDLE);
186 2 if (!(MpIsrInfo->irqSource & waitFor))
187 2 {
188 3 status = MI_ACCESSTIMEOUT;
189 3 }
190 2 else
191 2 {
192 3 status = MpIsrInfo->status;
193 3 }
194 2 if (status == MI_OK)
195 2 {
196 3 if (tmpStatus = (ReadIO(RegErrorFlag) & 0x17))
197 3 {
198 4 if (tmpStatus & 0x01)
199 4 {
200 5 info->collPos = ReadIO(RegCollPos);
201 5 status = MI_COLLERR;
202 5 }
203 4 else
204 4 {
205 5 info->collPos = 0;
206 5 if (tmpStatus & 0x02)
207 5 {
208 6 status = MI_PARITYERR;
209 6 }
210 5 }
211 4 if (tmpStatus & 0x04)
212 4 {
213 5 status = MI_FRAMINGERR;
214 5 }
215 4 if (tmpStatus & 0x10)
216 4 {
217 5 FlushFIFO();
218 5 status = MI_OVFLERR;
219 5 }
220 4 if (tmpStatus & 0x08)
221 4 {
222 5 status = MI_CRCERR;
223 5 }
224 4 if (status == MI_OK)
225 4 status = MI_NY_IMPLEMENTED;
226 4 }
227 3 if (cmd == PCD_TRANSCEIVE)
228 3 {
229 4 lastBits = ReadIO(RegSecondaryStatus) & 0x07;
230 4 if (lastBits)
231 4 info->nBitsReceived += (info->nBytesReceived-1) * 8 + lastBits;
232 4 else
233 4 info->nBitsReceived += info->nBytesReceived * 8;
234 4 }
235 3 }
236 2 else
237 2 {
238 3 info->collPos = 0x00;
239 3 }
240 2 }
241 1 MpIsrInfo = 0;
C51 COMPILER V7.50 M500AUC 06/15/2005 09:19:43 PAGE 5
242 1 MpIsrOut = 0;
243 1 return status;
244 1 }
245
246 ///////////////////////////////////////////////////////////////////////
247 // 置一个bit
248 ///////////////////////////////////////////////////////////////////////
249 char SetBitMask(unsigned char reg,unsigned char mask)
250 {
251 1 char idata tmp = 0x00;
252 1
253 1 tmp = ReadIO(reg);
254 1 WriteIO(reg,tmp | mask); // set bit mask
255 1 return 0x00;
256 1 }
257
258 ///////////////////////////////////////////////////////////////////////
259 // 清一个bit
260 ///////////////////////////////////////////////////////////////////////
261 char ClearBitMask(unsigned char reg,unsigned char mask)
262 {
263 1 char idata tmp = 0x00;
264 1
265 1 tmp = ReadIO(reg);
266 1 WriteIO(reg,tmp & ~mask); // clear bit mask
267 1 return 0x00;
268 1 }
269
270 ///////////////////////////////////////////////////////////////////////
271 ///////////////////////////////////////////////////////////////////////
272 void FlushFIFO(void)
273 {
274 1 SetBitMask(RegControl,0x01);
275 1 }
276
277 ///////////////////////////////////////////////////////////////////////
278 // Set card in HALT-state
279 // 终止卡的操作
280 ///////////////////////////////////////////////////////////////////////
281 char M500PiccHalt(void)
282 {
283 1 char idata status = MI_CODEERR;
284 1
285 1 // ************* Cmd Sequence **********************************
286 1 ResetInfo(MInfo);
287 1 SerBuffer[0] = PICC_HALT ; // Halt command code
288 1 SerBuffer[1] = 0x00; // dummy address
289 1 MInfo.nBytesToSend = 2;
290 1 status = M500PcdCmd(PCD_TRANSCEIVE,
291 1 SerBuffer,
292 1 &MInfo);
293 1 if (status)
294 1 {
295 2 // timeout error ==> no NAK received ==> OK
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -