📄 main.lst
字号:
C51 COMPILER V9.00 MAIN 05/16/2011 22:31:41 PAGE 1
C51 COMPILER V9.00, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN main.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE main.c LARGE WARNINGLEVEL(0) BROWSE INCDIR(D:\UsefulDocument\Mifare\MF RC50
-0\MFRC500 Demo Reader\RC500\For Test) DEBUG OBJECTEXTEND
line level source
1 /****************************************************************************
2 * *
3 * File: MAIN.C *
4 * *
5 * Version: 1.0 *
6 * *
7 * Created: 21.06.2002 *
8 * Last Change: 22.06.2002 *
9 * *
10 * Author: Steven Jiang Chang *
11 * *
12 * Compiler: KEIL C51 uVision2 V2.23 *
13 * *
14 * Description: 89C52RD2-Firmware for MFRC500 Demo Serial Reader *
15 * *
16 ****************************************************************************/
17
18 #define __SRC
19 #include "main.h"
20 #undef __SRC
21
22 #include <string.h>
23 #include <intrins.h>
24 #include <stdio.h>
25 #include <m500a.h>
26 #include <p89c51rx.h>
27
28 #define MIS_CHK_OK (0)
29 #define MIS_CHK_FAILED (-1)
30 #define MIS_CHK_COMPERR (-2)
31
32 // Function: mifs_request
33 #define IDLE 0x00
34 #define ALL 0x01
35
36 sbit RC500RST = P3^5;
37 sbit RC500_CS = P2^7;
38 sbit LED = P3^4;
39 //sbit LED = P3^4;
40
41 // Release Number of the Firmware
42 uchar code SW_Rel[] = "\n\r MFRC500 V1.0 22.06.02 \n\r";
43
44 // Serial Number of the MFRC500
45 uchar Snr_RC500[4];
46
47 static uint Crc;
48
49 // Local Prototypes
50 void init(void);
51
52
53 code Nkey_a[6] = {0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5};
54 code Nkey_b[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
C51 COMPILER V9.00 MAIN 05/16/2011 22:31:41 PAGE 2
55
56
57 /****************************************************************************
58 * *
59 * Function: main *
60 * *
61 * Input: - *
62 * Output: - *
63 * *
64 * Description: *
65 * *
66 * *
67 ****************************************************************************/
68 void main (void)
69 {
70 1 unsigned char counter,counter2;
71 1 unsigned char mfout=2;//readbuf[16];
72 1 unsigned char tt1[2];
73 1 unsigned char status1;
74 1 unsigned char cardserialno[4];
75 1 unsigned char *sak1;
76 1 unsigned char blockdata[16];
77 1 init();
78 1 M500PcdConfig(); // Initialise the RC500
79 1 // must be call in the initialisation
80 1 PcdReadE2(8,4,Snr_RC500); // Read out the MFRC500 serial number and store it
81 1 M500PcdMfOutSelect(mfout);
82 1
83 1 for (counter=0;counter<20;counter++)
84 1 {
85 2 status1 = M500PiccRequest(PICC_REQALL, tt1);
86 2 if (status1==MI_OK)
87 2 status1=M500PiccAnticoll(0,cardserialno);
88 2 if (status1==MI_OK)
89 2 status1=M500PiccSelect(cardserialno,sak1);
90 2 if (status1==MI_OK)
91 2 status1 = M500PiccAuth(PICC_AUTHENT1A, cardserialno, 1, 4);
92 2 if (status1 ==MI_OK)
93 2 status1=M500PiccRead(4, blockdata);
94 2 for ( counter2=0;counter2<16;counter2++)
95 2 blockdata[counter2]=counter;
96 2 if (status1 ==MI_OK)
97 2 status1 = M500PiccWrite(4,blockdata);
98 2
99 2 }
100 1 }
101
102
103 /****************************************************************************
104 * *
105 * Function: init *
106 * *
107 * Input: - *
108 * Output: - *
109 * *
110 * Description: *
111 * *
112 * *
113 ****************************************************************************/
114
115 void init(void)
116 {
C51 COMPILER V9.00 MAIN 05/16/2011 22:31:41 PAGE 3
117 1 RC500RST = FALSE;
118 1 RC500_CS = TRUE; // Enable the CS for RC500
119 1
120 1 CmdReceived = FALSE;
121 1 CmdValid = FALSE;
122 1 Quit = FALSE;
123 1 LLfReady = TRUE;
124 1 SendReady = TRUE;
125 1 Idle = TRUE;
126 1
127 1 RepCnt = 0;
128 1
129 1 RecvState = RECV_STX;
130 1
131 1 EnableTransferCmd = FALSE;
132 1
133 1 CheckByteCnt = BCC_CHECKBYTECNT;
134 1
135 1 #ifdef AUTODELAY
136 1 DelayRate = 0;
137 1 DelayRateLocked = TRUE;
138 1 #endif
139 1
140 1 PCON = 0x80; // SMOD = 1;
141 1 SCON = 0x50; // Mode 1, 8-bit UART, enable receiption
142 1
143 1 AutoBaud = TRUE;
144 1 TMOD = 0x20; // Timer 1, mode 2, 8-bit auto reload,
145 1 // Timer 0, mode 0, 13-bit counter
146 1 Capt_L = 0;
147 1 Capt_H = 0;
148 1
149 1 LED = OFF;
150 1 delay_10ms(50);
151 1 LED = ON;
152 1
153 1 IT0 = 1; // Config ext0 as edge trigger for RC500
154 1 EX0 = 1; // Enable ext0 interrupt for RC500
155 1
156 1 EA = TRUE; // Enable all interrupts
157 1
158 1 }
159
160 void auto_baud (void)
161 {
162 1 //int temp;
163 1
164 1 if (AutoBaud && !RXD) // If autobaud is enable and RXD pin is low
165 1 {
166 2 TR0 = TRUE; // Start timer0
167 2
168 2 do
169 2 {
170 3 if (RXD) // When RXD pin is high
171 3 {
172 4 Capt_L = TL0;
173 4 Capt_H = TH0;
174 4
175 4 do
176 4 {
177 5 if (!RXD)
178 5 {
C51 COMPILER V9.00 MAIN 05/16/2011 22:31:41 PAGE 4
179 6 break;
180 6 }
181 5 } while (!TF0);
182 4 }
183 3 } while (!TF0);
184 2
185 2 TR0 = FALSE;
186 2 TF0 = FALSE;
187 2
188 2 Capt = ((uint)Capt_H << 5) | ((uint)Capt_L & 0x001F);
189 2
190 2 for (BaudRate = BAUD_CNT; BaudRate >= 0; BaudRate--)
191 2 {
192 3 if (Capt >= CmpTable[BaudRate])
193 3 {
194 4 break;
195 4 }
196 3 }
197 2
198 2 if (BaudRate < 0 || BaudRate == BAUD_CNT) // Error baud count
199 2 {
200 3 TH0 = 0;
201 3 TL0 = 0;
202 3 Capt_L = 0;
203 3 Capt_H = 0;
204 3 return;
205 3 }
206 2
207 2 TMOD = 0x21; // Timer 0, mode 1, 16-bit counter
208 2 TH1 = BaudRateTable[BaudRate];
209 2 TL1 = TH1;
210 2 TR1 = TRUE;
211 2
212 2 TH0 = 0xE0;
213 2 TL0 = 0;
214 2 TR0 = TRUE;
215 2 while (!TF0); // Wait 4.4 ms
216 2 TR0 = FALSE;
217 2 TF0 = FALSE;
218 2 ET0 = TRUE;
219 2
220 2 AutoBaud = FALSE; // Baudrate had been choose, disable Autobaud
221 2
222 2 SBUF = NAK;
223 2 while (!TI);
224 2 TI = FALSE;
225 2 RI = FALSE;
226 2 ES = TRUE;
227 2 }
228 1 }
229
230
231 /****************************************************************************
232 * *
233 * Function: delay_50us *
234 * *
235 * Input: _50us *
236 * Output: - *
237 * *
238 * Description: *
239 * *
240 * Time delay with a resolution of 50 us. *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -