📄 rc500.lst
字号:
C51 COMPILER V6.00i RC500 01/15/2004 10:42:47 PAGE 1
C51 COMPILER 6.00i, COMPILATION OF MODULE RC500
OBJECT MODULE PLACED IN Rc500.OBJ
COMPILER INVOKED BY: E:\cygnal单片机\CYGNAL\IDEfiles\C51\BIN\C51.EXE Rc500.c DB OE
stmt level source
1
2 #include "c8051F020.h"
3 #include "absacc.h"
4 #include "string.h"
5 #include "stdio.h"
6 #include "intrins.h"
7 #include <MfRcuC.h>
8 #include <MfRc500R.h>
9 #include <MfErrNo.h>
10
11 //******************************************************************
12 #define STX 0x7E //通讯开始
13 #define ETX 0x7F //通讯结束
14
15 #define BUFF_LEN 30 //接收缓冲区长度
16
17 //串口中断接收缓存区定义
18 unsigned char xdata RECEIVEBUFFER[BUFF_LEN],*RECEIVEBUFFERPOINT; // UART0 RECEIVE buffer
19 unsigned char xdata Receive_Num=0;
20 bit START_FLAG=0,END_FLAG=0;
21 //********************************************************************
22 #define unchar unsigned char
23 //********************************************************************
24 unsigned char xdata MLastSelectedSnr[5];
25 unsigned char xdata Returnval,status=0;
26 unsigned char xdata MRcvBuffer[64] ,MSndBuffer[16]; //
27 static MfCmdInfo MInfo;
28
29 //********************************************
30 bit haveset=0;
31 sbit PReset=P1^7;
32 /********************************************
33 void Delay(unsigned int );
34 ********************************************/
35 void Delay(unsigned int j)
36 {
37 1 unsigned int i;
38 1 for(i=0;i<j;i++)
39 1 {
40 2 _nop_();
41 2 _nop_();
42 2 _nop_();
43 2 _nop_();
44 2 _nop_();
45 2 _nop_();
46 2 _nop_();
47 2 _nop_();
48 2 _nop_();
49 2 _nop_();
50 2 _nop_();
51 2 _nop_();
52 2 _nop_();
53 2 _nop_();
54 2 _nop_();
55 2 _nop_();
C51 COMPILER V6.00i RC500 01/15/2004 10:42:47 PAGE 2
56 2 _nop_();
57 2 _nop_();
58 2 _nop_();
59 2 _nop_();
60 2 _nop_();
61 2 _nop_();
62 2 _nop_();
63 2 _nop_();
64 2 _nop_();
65 2 _nop_();
66 2 }
67 1 }
68
69 /****************************************************************************
70 * *
71 * Function: main *
72 * *
73 * Input: - *
74 * Output: - *
75 * *
76 * Description: *
77 ****************************************************************************/
78 void main(void)
79 {
80 1 unsigned char idata i;
81 1 unsigned char xdata catq[2],csn[5];
82 1 unsigned char xdata rbuf[16]={0};
83 1 unsigned char xdata keybuf[6],keycodebuf[12],temp_buf[17];
84 1 unsigned char idata sector_num; //扇区绝对号
85 1 unsigned char idata selec_abkey; //key a b selector
86 1 unsigned char idata block_num; //块绝对号
87 1 unsigned char idata e2key_secotor;
88 1 unsigned short idata rc500_e2addr;
89 1 unsigned short delay;
90 1
91 1
92 1 OSCXCN = 0x67; // Enable external crystal
93 1 WDTCN = 0xDE; // disable watchdog timer
94 1 WDTCN = 0xAD;
95 1
96 1 EMI0CF = 0x07; // Set External Memory Configuration Register,
97 1 //使用片内 4K 和片外存储器低端口,地址数据复用
98 1 //因为地址与数据复用,所以应将XBR2.1设为高电平,以使交叉开关
99 1 //跳过ALE,RD,WR
100 1
101 1 XBR0 = 0X04; //SET UART0
102 1 XBR1 = 0x10; // Set INT1
103 1 XBR2 = 0x46; // Set UART1,Enable XBAR,Enable EMFILE
104 1
105 1 P0MDOUT = 0xe1; //Output configuration for P0
106 1 //ALE,RD,WR,TXD配置为推挽输出,RXD,INT1配置为漏级开路
107 1 P1MDOUT = 0xff; // Output configuration for P1
108 1 //复位脚配置为推挽输出
109 1 P2MDOUT = 0xff; // Output configuration for P2
110 1 P3MDOUT = 0xff; // Output configuration for P3
111 1
112 1 P0|=0x12; //set RX0,INT1为输入
113 1
114 1
115 1 delay=256; // Delay >1 ms before polling XTLVLD.
116 1 while(delay--);
117 1
C51 COMPILER V6.00i RC500 01/15/2004 10:42:47 PAGE 3
118 1 while (!(OSCXCN & 0x80)); // Wait until external crystal has // started.
119 1 OSCICN = 0x0C; // Switch to external oscillator
120 1 OSCICN = 0x88; // Disable internal oscillator; enable
121 1 // missing clock detector.
122 1 while (!(OSCXCN & 0x80)); // Wait until external crystal has // started.
123 1 OSCICN = 0x08; // Switch to external oscillator
124 1
125 1 ///////////////////////////////////////////////////
126 1
127 1 // 初始化UART0、TIMER2
128 1 Baudrate_Init(); // 初始化串口0的波特率
129 1
130 1 IT1=1; // 外部中断1设为沿触发
131 1
132 1 ES0=1; //允许串口0中断
133 1 EX1=1; //外部中断1开放
134 1 EA=1; //
135 1 ///////////////////////////////////////////////////////////////////////////////////////
136 1 SendEnter();
137 1 SendData("通讯成功");
138 1 status=Mf500PcdConfig(); //配置RC500内部寄存器函数
139 1 SendData("售卡机终端工作"); //显示上电成功
140 1 memset(RECEIVEBUFFER,0,BUFF_LEN);
141 1 status=Mf500PiccHalt();
142 1 while(1) //while(1)
143 1 {
144 2 if(END_FLAG==1){//接收成功
145 3 END_FLAG=0;
146 3 SendData("Send:");
147 3 for(i=0;i<Receive_Num;i++)
148 3 SendHex(RECEIVEBUFFER[i]); //接收的内容发回去
149 3 SendEnter();
150 3 SendData("Rece:");
-
151 3 switch(RECEIVEBUFFER[1]){ //run command
152 4 case 0x4f: //择卡并发挥卡信息
153 4 do{
154 5 status=Mf500PiccRequest(PICC_REQALL,catq);
-
155 5 status=Mf500PiccAnticoll(0,csn); //csn 为返回的卡序列号SN
156 5
157 5 status=Mf500PiccSelect(csn,catq); //选择这张卡
-
158 5
-
159 5 }while(status);
160 4
161 4 if(catq[0]==0x08) // MIFARE I 卡
162 4 SendData("Mifare 1");
163 4 else
164 4 SendData("非法卡片");
165 4 SendData("卡号:");
166 4 for(i=0;i<5;i++) //seril
167 4 SendHex(csn[i]);
168 4 SendEnter();
169 4 SendData("select ok"); //显示选择卡成功
170 4 break;
171 4
172 4 case 0x4c: //直接验证
173 4
174 4 sector_num=RECEIVEBUFFER[3]*4+3;//算出密钥所在的扇区
175 4 memmove(keybuf,RECEIVEBUFFER+6,6);
C51 COMPILER V6.00i RC500 01/15/2004 10:42:47 PAGE 4
176 4 status=Mf500HostCodeKey(keybuf,keycodebuf);//将密钥转换成RC500格式
177 4 if(RECEIVEBUFFER[5]==0x0A)
178 4 selec_abkey=PICC_AUTHENT1A;
179 4 if(RECEIVEBUFFER[5]==0x0B)
180 4 selec_abkey=PICC_AUTHENT1B;
-
181 4 status=Mf500PiccAuthKey(selec_abkey,csn,keycodebuf,sector_num);
-
182 4 if(status==0)
183 4 SendData("auth ok");
184 4
185 4 else
186 4 SendData("auth lose");
187 4 break;
188 4 case 0x0B: //间接验证
189 4 sector_num=RECEIVEBUFFER[3]*4+3;//算出密钥所在的扇区
190 4 if(RECEIVEBUFFER[5]==0x0A)
191 4 selec_abkey=PICC_AUTHENT1A;
192 4 if(RECEIVEBUFFER[5]==0x0B)
193 4 selec_abkey=PICC_AUTHENT1B;
194 4 e2key_secotor=RECEIVEBUFFER[6];
195 4
196 4 status= Mf500PiccAuthE2(selec_abkey,csn,e2key_secotor,sector_num);
197 4 // 参数e2key_secotor 0 <= e2key_sector <= 15此为e2rom的扇区号
-
198 4 // 参数sector_num为卡的扇区0 block 0 <= block <= 15 即为认证的卡的扇区
199 4
200 4 if(status==0)
201 4 SendData("Auth ok");//显示写成功
202 4 else
203 4 SendData("Auth lose");
204 4 break;
205 4
206 4 case 0x01: //loadkeye2 将密钥装入RC500的密钥存贮区
207 4
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -