📄 main.lst
字号:
C51 COMPILER V7.06 MAIN 03/21/2005 16:36:23 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN main.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE main.c LARGE OPTIMIZE(2,SPEED) BROWSE DEBUG OBJECTEXTEND
stmt level source
1 /****************************************************************************
2 * *
3 * File: MAIN.C *
4 * *
5 * Version: V1.0 *
6 * *
7 * Created: 2003/10/11 *
8 * Last Change: 2005/01/12 *
9 * *
10 * Author: DavidQi *
11 * *
12 * Compiler: KEIL C51 V6.23A *
13 * *
14 * Description: 该程序用于Phiplips RC500 RC530 *
15 * *
16 ****************************************************************************/
17 #pragma large
18 #define __SRC
19
20 #include <main.h>
21 #undef __SRC
22
23
24 #include <string.h>
25 #include <intrins.h>
26
27
28 #include <stdio.h>
29 #include <m500a.h>
30 #include "w77e58.h"
31 #include <rdio.h>
32
33 #define MIS_CHK_OK (0)
34 #define MIS_CHK_FAILED (-1)
35 #define MIS_CHK_COMPERR (-2)
36
37 // Function: mifs_request
38 #define IDLE 0x00
39 #define ALL 0x01
40
41
42 // PC Debug Data: 02 30 31 32 03 33 checksum =33 (30^31^32)
43 // Release Number of the Firmware
44 uchar code SW_Rel[] = "\n\r MFRC500 V1.0 8.03.2003 \n\r";
45 uchar code ms[4][2] = {{0x0,0x0},{0x0,0x0},{0x0,0x0},{0x0,0x0}};
46
47 // Serial Number of the MFRC500
48 //uchar Snr_RC500[4];
49 uchar xdata Snr_RC500[4];
50 //static uint Crc;
51
52 // Local Prototypes
53 void init(void);
54 void cmd_execution(void);
55
C51 COMPILER V7.06 MAIN 03/21/2005 16:36:23 PAGE 2
56 // Interrupt Service Routines
57 void isr_timer0(void);
58 void isr_UART(void);
59
60 //uchar card_snr[4];
61 uchar xdata card_snr[4];
62 char xdata ErrNum;
63
64 unsigned char code CmdData_1[]={0x7f,0x40,0x05,0x0,0x0,0x0,0x0};
65
66 unsigned char code CmdData_2[]={0x7f,0x42,0x08,0x0,0x0,0x0,0x0,0x0};
67
68 uchar xdata SectorNum, BlockNum,CommandNum,Key[6],CardData[16],KeyData[6];
69
70 uchar data ComeCard = 0,GoCard = 0;ChkSum1 = 0;
71 void main (void)
72 {
73 1 init();
74 1
75 1 test();
76 1
77 1 WDTC = WDTC|0x01; // start WDT
78 1
79 1 M500PcdConfig(); // Initialise the RC500
80 1 // must be call in the initialization
81 1
82 1 // RC500 E2PROM 0x00--0x0f Product Information Field
83 1 // 0x08--0x0b Product Serical Number
84 1
85 1 PcdReadE2(8,4,Snr_RC500); // Read out the MFRC500 serial number and store it
86 1
87 1 RingOn();
88 1
89 1 while(1)
90 1 {
91 2 LED = OFF;
92 2
93 2 // 检测是否有MIFARE卡在读头感应区,等待POS 终端发送命令
94 2
95 2 M500PcdConfig();
96 2
97 2 ChkSum = 0;
98 2
99 2 while(!FrameOk)
100 2 {
101 3
102 3 // memcpy(SerBuffer,CmdData_1,7);
103 3
104 3 SerBuffer[1] = 0x40;
105 3 cmd_execution();
106 3
107 3 if(AccOk )
108 3 {
109 4 ComeCard++;
110 4 if(ComeCard == 3)
111 4 {
112 5 P1_6 = 1;
113 5 ComeCard = 0;
114 5 }
115 4
116 4 AccOk = FALSE ;
117 4 GoCard = 0;
C51 COMPILER V7.06 MAIN 03/21/2005 16:36:23 PAGE 3
118 4 }
119 3 else
120 3 {
121 4 GoCard++;
122 4 if(GoCard == 3)
123 4 {
124 5 P1_6 = 0;
125 5 GoCard = 0;
126 5 }
127 4 ComeCard = 0;
128 4
129 4 }
130 3
131 3 SerBuffer[1] = 0x45;
132 3 cmd_execution();
133 3 delay_10ms(5);
134 3
135 3 WDTC = WDTC|0x02; // refresh watchdog timer
136 3 WDTD = 0x0a0; // 3s Reload timer
137 3
138 3 }
139 2
140 2 WDTC = WDTC|0x02; // refresh watchdog timer
141 2 WDTD = 0x0a0; // 3s Reload timer
142 2 // SerBuffer[1] = 0x45;
143 2 // cmd_execution();
144 2 // RingOn();
145 2
146 2 TransData(PcData,SerBuffer,DataLen);//SerBuffer: PC 与MCU交互数据缓冲区
147 2
148 2
149 2 M500PcdConfig();
150 2
151 2 /*
152 2 cmd_execution() 命令执行程序
153 2 命令码: 命令功能:
154 2 0x40: // PICC_REQALL
155 2 0x41: // Request
156 2 0x42: // Anticoll
157 2 0x43: // Select
158 2 0x44: // Authentication
159 2 0x45: // Halt
160 2 0x46: // Read
161 2 0x47: // Write
162 2 0x48: // Increment
163 2 0x49: // Decrement
164 2 0x4A: // Restore
165 2 0x4B: // Transfer
166 2 0x4C: // Load Key
167 2 0x4D: // comm check char
168 2 0x4E: // Reset
169 2 0x4F: // Get Info
170 2 0x50: // Set Control Bit
171 2 0x51: // Clr Control Bit
172 2 0x52: // Config
173 2 0x53: // Check Write
174 2 0x54: // Set Port
175 2 0x55: // Get Port
176 2 0x56: // Authentication2
177 2 0x57: // Decrement+Transfer
178 2 */
179 2 CommandNum = SerBuffer[0]; //命令码
C51 COMPILER V7.06 MAIN 03/21/2005 16:36:23 PAGE 4
180 2 SectorNum = SerBuffer[1]; //mifare1卡:扇区号
181 2 BlockNum = SerBuffer[2]; //mifare1卡:块号
182 2 memcpy(KeyData,&SerBuffer[3],6);//mifare1卡:块密码6字节
183 2 memcpy(CardData,&SerBuffer[3],16);//mifare1卡:待写的16字节数据
184 2 if(CommandNum == 0x47)
185 2 {
186 3 //RingOn();
187 3 ;
188 3
189 3 }
190 2 FrameOk = 0;
191 2 if(CommandNum == 0x4c)
192 2 {
193 3
194 3 SerBuffer[1] = 0x4c;
195 3 SerBuffer[MODE] = PICC_AUTHENT1A; //MODE = 3
196 3 SerBuffer[SECNR] = SectorNum; //SECNR = 4
197 3 memcpy(&SerBuffer[13],KeyData,6);
198 3 cmd_execution();
199 3 if(!ErrNum)
200 3 {
201 4 SerBuffer[3] = 0x0;
202 4 TransHexAsi(&SerBuffer[3],SendBuffer,1);
203 4 SendDataToPc(SendBuffer,2);
204 4 RingOn();
205 4 }
206 3
207 3 }
208 2
209 2 else
210 2 {
211 3 //memcpy(SerBuffer,CmdData_1,7); //命令码:0x40 执行PICC_REQALL 返回卡型2字节
212 3
213 3 SerBuffer[1] = 0x40;
214 3 cmd_execution();
215 3
216 3 if(!ErrNum)
217 3 {
218 4
219 4 // memcpy(SerBuffer,CmdData_2,8);
220 4 SerBuffer[1] = 0x42;
221 4 SerBuffer[3] = 0;
222 4
223 4 cmd_execution();//命令码:0x42: 执行 Anticoll 返回序列号
224 4
225 4 AccOk = FALSE ;
226 4
227 4 if(!ErrNum)
228 4 {
229 5 SerBuffer[1] = 0x43;
230 5
231 5 cmd_execution();// 命令码: 0x43: 选择卡片 返回卡片的 SIZE 字节 0x88h
232 5
233 5 AccOk = FALSE ;
234 5
235 5 SerBuffer[1] = 0x44;
236 5 SerBuffer[2] = BlockNum;
237 5
238 5 SerBuffer[3] = 0 ;
239 5
240 5 SerBuffer[4] = SectorNum; //卡扇区号(0-15):= 2(含块8,9,10)
241 5
C51 COMPILER V7.06 MAIN 03/21/2005 16:36:23 PAGE 5
242 5 cmd_execution();//命令码:0x44: 密码认证操作
243 5
244 5 if(!ErrNum)
245 5 {
246 6 if(AuthOk == 0)
247 6 {
248 7 switch (CommandNum)
249 7 {
250 8 case 0x46:
251 8 SerBuffer[1] = 0x46; //读卡命令
252 8 SerBuffer[3] = BlockNum ; //卡块号(0-63): =8(8,9,10)
253 8 cmd_execution();
254 8 TransHexAsi(&SerBuffer[3],SendBuffer,16);
255 8 SendDataToPc(SendBuffer,32);
256 8 break;
257 8
258 8 case 0x47:
259 8 SerBuffer[1] = 0x47; //写卡命令
260 8 SerBuffer[3] = BlockNum ; //卡块号
261 8
262 8 memcpy(&SerBuffer[4],CardData,16);// 16字节 写卡数据
263 8
264 8 cmd_execution();
265 8 if(!ErrNum)
266 8 {
267 9 SerBuffer[3] = 0x0;
268 9 TransHexAsi(&SerBuffer[3],SendBuffer,1);
269 9 SendDataToPc(SendBuffer,2);
270 9 RingOn();
271 9 }
272 8 break;
273 8
274 8 default:
275 8 break;
276 8
277 8 }
278 7
279 7 }
280 6
281 6 }
282 5
283 5 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -