📄 main.lst
字号:
C51 COMPILER V7.06 MAIN 12/04/2007 19:24:45 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 WARNINGLEVEL(0) BROWSE INCDIR(D:\UsefulDocument\Mifare\MF RC50
-0\MFRC500 Demo Reader\RC500\For Test) DEBUG OBJECTEXTEND
stmt level source
1 /****************************************************************************
2 * *
3 * File: MAIN.C *
4 * *
5 * Version: 1.0 *
6 * *
7 * Created: 2007.11.30 *
8 * Last Change: 2007 *
9 * *
10 * Author: HeXing *
11 * QQ: 271885846 *
12 * EMail: 271885846@qq.com *
13 * Compiler: KEIL C51 uVision2 V2.23 *
14 * *
15 * Description: 89C52-Firmware for MFRC500 Demo Serial Reader *
16 * *
17 ****************************************************************************/
18
19 #define __SRC
20 #include "main.h"
21 #undef __SRC
22
23 #include <string.h>
24 #include <intrins.h>
25 #include <stdio.h>
26 #include <m500a.h>
27 #include <p89c51rx.h>
28
29 #define MIS_CHK_OK (0)
30 #define MIS_CHK_FAILED (-1)
31 #define MIS_CHK_COMPERR (-2)
32
33 // Function: mifs_request
34 #define IDLE 0x00
35 #define ALL 0x01
36
37 sbit RC500RST = P3^5; //RC500复位端口
38 sbit RC500_CS = P2^7; //RC500选通端口 Chip Select
39 sbit LED = P1^1; //LED 显示
40 sbit BEEP = P1^0;//蜂鸣器
41
42 uint AbsoluteBlock = 8; //对绝对块8进行操作, 取值范围为 0 <= AbsoluteBlock < 64
43
44 // Release Number of the Firmware
45 //uchar code SW_Rel[] = "\n\r MFRC500 V1.0 22.06.02 \n\r";
46
47 // Serial Number of the MFRC500
48 uchar Snr_RC500[4];
49
50 static uint Crc;
51
52 // Local Prototypes
53 void init(void);
54
C51 COMPILER V7.06 MAIN 12/04/2007 19:24:45 PAGE 2
55
56 code Nkey_a[6] = {0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5};
57 code Nkey_b[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
58
59 /*
60 存储结构
61 1、 M1卡分为16个扇区,每个扇区由4块(块0、块1、块2、块3)组成,
62 (我们也将16个扇区的64个块按绝对地址编号为0~63,
63 2、 第0扇区的块0(即绝对地址0块),它用于存放厂商代码,已经固化,不可更改。
64 3、 每个扇区的块0、块1、块2为数据块,可用于存贮数据。
65 数据块可作两种应用:
66 ★ 用作一般的数据保存,可以进行读、写操作。
67 ★ 用作数据值,可以进行初始化值、加值、减值、读值操作。
68 4、 每个扇区的块3为控制块,包括了密码A、存取控制、密码B。
69 5、 每个扇区的密码和存取控制都是独立的,
70 可以根据实际需要设定各自的密码及存取控制。
71 存取控制为4个字节,共32位,扇区中的每个块(包括数据块和控制块)
72 的存取条件是由密码和存取控制共同决定的,在存取控制中每个块都有相应的三个控制位,
73 定义如下:
74
75 块0: C10 C20 C30
76 块1: C11 C21 C31
77 块2: C12 C22 C32
78 块3: C13 C23 C33
79 */
80
81 /****************************************************************************
82 * *
83 * Function: main *
84 * *
85 * Input: - *
86 * Output: - *
87 * *
88 * Description: *
89 * *
90 * *
91 ****************************************************************************/
92 void main (void)
93 {
94 1 unsigned char counter,counter2;
95 1 unsigned char mfout=2;//readbuf[16];
96 1 unsigned char tt1[2];
97 1 unsigned char status1;
98 1 unsigned char cardserialno[4];
99 1 unsigned char *sak1;
100 1 unsigned char blockdata[16];
101 1 int i;
102 1
103 1 init();
104 1 M500PcdConfig(); // Initialise the RC500 初始化RC500,寄存器
105 1 // must be call in the initialisation
106 1 PcdReadE2(8,4,Snr_RC500); // 读RC500芯片的序列号,保存到Snr_RC500. Read out the MFRC500 serial number and
- store it
107 1
108 1 printf("RC500的序列号:0x");
109 1 for(counter=0;counter<4;counter++)
110 1 {
111 2 i = Snr_RC500[counter]<<4>>4;//因为printf(%x) 只可以16进制显示整数,所以必须把uchar左移4位再右移4位,下同
112 2 printf("%X", i);
113 2 }
114 1 printf("\r\n");
115 1
C51 COMPILER V7.06 MAIN 12/04/2007 19:24:45 PAGE 3
116 1 M500PcdMfOutSelect(mfout); // Route serial output to pin, for test
117 1
118 1 printf("进入轮循, 等待读卡...\r\n");
119 1
120 1 while(1)//for (counter=0;counter<20;counter++)
121 1 {
122 2
123 2 status1 = M500PiccRequest(PICC_REQALL, tt1);//寻卡
124 2 if (status1==MI_OK)//如果找到卡
125 2 {
126 3 if(tt1[0]==2)
127 3 printf("发现Mifare Pro 卡!\r\n");//type = 0;MifareProCard; // Mifare Pro 卡
128 3 else if(tt1[0]==4)
129 3 printf("发现Mifare One 卡!\r\n");//type= 1;//MifareOneCard; // Mifare One 卡
130 3 else if(tt1[0]==16)
131 3 printf("发现Mifare Light卡!\r\n");//type= 2;//MifareLightCard; // Mifare Light 卡
132 3 else
133 3 return; //未知
134 3
135 3
136 3 status1=M500PiccAnticoll(0,cardserialno);//
137 3
138 3 printf("卡号:0x");
139 3 for(counter=0;counter<4;counter++)
140 3 {
141 4 i = cardserialno[counter]<<4>>4;//因为printf(%x) 只可以16进制显示整数,所以必须把uchar左移4位再右移4位,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -