📄 typeb.lst
字号:
C51 COMPILER V7.50 TYPEB 07/17/2008 22:58:13 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE TYPEB
OBJECT MODULE PLACED IN typeb.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE typeb.c BROWSE DEBUG OBJECTEXTEND
line level source
1 #include <REGX52.H>
2 #include <main.h>
3 #include <function.h>
4 #include <typeb.h>
5 #include <string.h>
6 /***************************
7 *变量定义
8 ***************************/
9 static idata unsigned char g_cFWI;
10 static idata unsigned char TYPE;
11 static volatile struct TranSciveBuffer{unsigned char MfCommand;
12 unsigned int MfLength;
13 unsigned char MfData[64];
14 };
15 /****************************
16 *MFRC500 复位程序
17 *返回1 ->复位不成功
18 *返回0 ->复位成功
19 ************************/
20 uchar M500PcdReset(void)
21 {
22 1 uchar timecount;
23 1
24 1 CLR_RC500RST(); //起动复位引脚
25 1 Delay(25); //延时
26 1 SET_RC500RST(); //进行复位
27 1 Delay(20); //延时
28 1 CLR_RC500RST(); //复位完成
29 1 Delay(10); //延时待MFRC500进行数据进行复制
30 1
31 1 timecount=250; //置数超时计数器
32 1
33 1 while((ReadIO(RegCommand)&0x3f)&(timecount--)); //判断 MFRC500复位完毕没有与是否超时
34 1
35 1 if(!timecount)return 1; //如果超时了就返回1
36 1
37 1 if(ReadIO(RegCommand)!=0x00)return 1; //如果MFRC500复位完后的值不是0X00,表明出现异常,返回1
38 1 return 0; //复位成功则返回0
39 1
40 1 }
41
42 /****************************
43 *清除位
44 *
45 *
46 ************************/
47 void ClearBitMask(uchar reg,uchar mask)
48 {
49 1 uchar temp;
50 1
51 1 temp=ReadIO(reg); //读取寄存器
52 1 WriteIO(reg,(temp&(~mask)));//清除相应的位
53 1
54 1 }
55
C51 COMPILER V7.50 TYPEB 07/17/2008 22:58:13 PAGE 2
56 /****************************
57 *置位
58 *
59 *
60 ************************/
61 void SetBitMask(uchar reg,uchar mask)
62 {
63 1 uchar temp;
64 1
65 1 temp=ReadIO(reg); //读取寄存器的值
66 1 WriteIO(reg,(temp|mask));//置位相应的位
67 1
68 1 }
69 //////////////////////////////////////////////////////////////////////
70 //REQUEST B
71 //////////////////////////////////////////////////////////////////////
72 char M531PiccRequestB(unsigned char req_code,
73 unsigned char AFI,
74 unsigned char N,
75 unsigned char *ATQB)
76 {
77 1 char status;
78 1 struct TranSciveBuffer MfComData;
79 1 struct TranSciveBuffer *pi;
80 1 pi=&MfComData;
81 1
82 1 ClearBitMask(RegControl,0x08); // disable crypto 1 unit
83 1
84 1 // SetBitMask(RegTxControl,0x03); // Tx2RF-En, Tx1RF-En enable
85 1
86 1 PcdSetTmo(5);
87 1 MfComData.MfCommand = PCD_TRANSCEIVE;
88 1 MfComData.MfLength = 3;
89 1 MfComData.MfData[0] = ISO14443B_ANTICOLLISION; // APf code
90 1 MfComData.MfData[1] = AFI; //
91 1 MfComData.MfData[2] = ((req_code<<3)&0x08) | (N&0x07); // PARAM
92 1
93 1 status = PcdComTransceive(pi);
94 1
95 1 if (status!=MI_OK && status!=MI_NOTAGERR)
96 1 { status = MI_COLLERR; }
97 1
98 1 if (MfComData.MfLength != 96)
99 1 { status = MI_COM_ERR; }
100 1
101 1 if (status == MI_OK)
102 1 {
103 2 memcpy(ATQB, &MfComData.MfData[0], 16);
104 2 PcdSetTmo(ATQB[11]>>4); // set FWT
105 2 }
106 1 return status;
107 1 }
108
109 void PcdSetTmo(uchar tmoLength)
110 {
111 1 switch(tmoLength)
112 1 {
113 2 case 1: // short timeout (1,0 ms)
114 2 WriteIO(RegTimerClock,0x07); // TAutoRestart=0,TPrescale=128
115 2 WriteIO(RegTimerReload,0x6a); // TReloadVal = 'h6a =106(dec)
116 2 break;
117 2 case 2: // medium timeout (1,5 ms)
C51 COMPILER V7.50 TYPEB 07/17/2008 22:58:13 PAGE 3
118 2 WriteIO(RegTimerClock,0x07); // TAutoRestart=0,TPrescale=128
119 2 WriteIO(RegTimerReload,0xa0); // TReloadVal = 'ha0 =160(dec)
120 2 break;
121 2 case 3: // long timeout (6 ms)
122 2 WriteIO(RegTimerClock,0x09); // TAutoRestart=0,TPrescale=4*128
123 2 WriteIO(RegTimerReload,0xa0); // TReloadVal = 'ha0 =160(dec)
124 2 break;
125 2 case 4: // long timeout (9.6 ms)
126 2 WriteIO(RegTimerClock,0x09); // TAutoRestart=0,TPrescale=4*128
127 2 WriteIO(RegTimerReload,0xff); // TReloadVal = 'ff =255(dec)
128 2 break;
129 2 default: // short timeout (1,0 ms)
130 2 WriteIO(RegTimerClock,0x07); // TAutoRestart=0,TPrescale=128
131 2 WriteIO(RegTimerReload,tmoLength);// TReloadVal = tmoLength
132 2 break;
133 2 }
134 1 WriteIO(RegTimerControl,0X06);
135 1 }
136
137 /******************************************************
138 *发送指令
139 ***************************************************/
140 unsigned char PcdComTransceive(struct TranSciveBuffer *pi)
141 {
142 1 bit recebyte = 0;
143 1 char status;
144 1 unsigned char irqEn = 0x00;
145 1 unsigned char waitFor = 0x00;
146 1 unsigned char lastBits;
147 1 unsigned char n;
148 1 unsigned int i;
149 1 switch (pi->MfCommand)
150 1 {
151 2 case PCD_IDLE:
152 2 irqEn = 0x00;
153 2 waitFor = 0x00;
154 2 break;
155 2 case PCD_WRITEE2:
156 2 irqEn = 0x11;
157 2 waitFor = 0x10;
158 2 break;
159 2 case PCD_READE2:
160 2 irqEn = 0x07;
161 2 waitFor = 0x04;
162 2 recebyte=1;
163 2 break;
164 2 case PCD_LOADCONFIG:
165 2 case PCD_LOADKEYE2:
166 2 case PCD_AUTHENT1:
167 2 irqEn = 0x05;
168 2 waitFor = 0x04;
169 2 break;
170 2 case PCD_CALCCRC:
171 2 irqEn = 0x11;
172 2 waitFor = 0x10;
173 2 break;
174 2 case PCD_AUTHENT2:
175 2 irqEn = 0x04;
176 2 waitFor = 0x04;
177 2 break;
178 2 case PCD_RECEIVE:
179 2 irqEn = 0x06;
C51 COMPILER V7.50 TYPEB 07/17/2008 22:58:13 PAGE 4
180 2 waitFor = 0x04;
181 2 recebyte=1;
182 2 break;
183 2 case PCD_LOADKEY:
184 2 irqEn = 0x05;
185 2 waitFor = 0x04;
186 2 break;
187 2 case PCD_TRANSMIT:
188 2 irqEn = 0x05;
189 2 waitFor = 0x04;
190 2 break;
191 2 case PCD_TRANSCEIVE:
192 2 irqEn = 0x3D;
193 2 waitFor = 0x04;
194 2 recebyte=1;
195 2 break;
196 2 default:
197 2 pi->MfCommand = MI_UNKNOWN_COMMAND;
198 2 break;
199 2 }
200 1
201 1 if (pi->MfCommand != MI_UNKNOWN_COMMAND)
202 1 {
203 2 WriteIO(RegPage,0x00);
204 2 WriteIO(RegInterruptEn,0x7F);
205 2 WriteIO(RegInterruptRq,0x7F);
206 2 WriteIO(RegCommand,PCD_IDLE);
207 2 SetBitMask(RegControl,0x01);
208 2 WriteIO(RegInterruptEn,irqEn|0x80);
209 2 for (i=0; i<pi->MfLength; i++)
210 2 {
211 3 WriteIO(RegFIFOData, pi->MfData[i]);
212 3 }
213 2 WriteIO(RegCommand, pi->MfCommand);
214 2 i = 0x3500;
215 2 do
216 2 {
217 3 n = ReadIO(RegInterruptRq);
218 3 i--;
219 3 }
220 2 while ((i!=0) && !(n&irqEn&0x20) && !(n&waitFor));
221 2 status = MI_COM_ERR;
222 2 if ((i!=0) && !(n&irqEn&0x20))
223 2 {
224 3 if (!(ReadIO(RegErrorFlag)&0x17))
225 3 {
226 4 status = MI_OK;
227 4 if (recebyte)
228 4 {
229 5 n = ReadIO(RegFIFOLength);
230 5 lastBits = ReadIO(RegSecondaryStatus) & 0x07;
231 5 if (lastBits)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -