-
Notifications
You must be signed in to change notification settings - Fork 0
/
MAIN.LST
254 lines (243 loc) · 9.56 KB
/
MAIN.LST
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
C51 COMPILER V9.00 MAIN 10/11/2019 10:20:02 PAGE 1
C51 COMPILER V9.00, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN MAIN.OBJ
COMPILER INVOKED BY: D:\MDK5\C51\BIN\C51.EXE MAIN.C COMPACT OPTIMIZE(8,SPEED) BROWSE DEBUG OBJECTEXTEND TABS(2)
line level source
1 /**********************RC522实验开发板例程************************
2 * CPU:STC89C52RC
3 * 晶振:11.0592MHZ
4 ------------------------------------------------*/
5 #include <REGX52.H>
6 #include <STDIO.H>
7 #include <string.h>
8 #include "main.h"
9 #include "mfrc522.h"
10
11 sbit s = P1^0;
12 sbit beep = P1^3;
13 sbit open1 = P1^7;
14 sbit open2 = P1^6;
15 sbit open3 = P1^5;
16
17 unsigned char code data1[16] = {0x12,0x34,0x56,0x78,0xED,0xCB,0xA9,0x87,0x12,0x34,0x56,0x78,0x01,0xFE,0x01
-,0xFE};
18 //M1卡的某一块写为如下格式,则该块为钱包,可接收扣款和充值命令
19 //4字节金额(低字节在前)+4字节金额取反+4字节金额+1字节块地址+1字节块地址取反+1字节块地址+1字节块地�
-啡》�
20 unsigned char code data2[4] = {0,0,0,0x01};
21 unsigned char code DefaultKey[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
22
23 unsigned char g_ucTempbuf[20];
24 unsigned int card_id[4];
25 int id1[4]={41,9,167,110}; //蓝色卡
26 int id2[4]={89,165,99,184}; //我的IPHONE上海公交卡
27 int id3[4]={54,58,231,238}; //我的水卡
28 int id4[4]={158,151,44,201}; //谢利森水卡
29 int id5[4]={19,139,139,123}; //毛泽光水卡
30 int p1=0;
31 int p2=0;
32 int p3=0;
33 int p4=0;
34 int p5=0;
35
36 void Delay100us() //@11.0592MHz
37 {
38 1 unsigned char i;
39 1
40 1 i = 43;
41 1 while (--i);
42 1 }
43
44
45 void delay1(unsigned int z)
46 {
47 1 unsigned int x,y;
48 1 for(x=z;x>0;x--)
49 1 for(y=110;y>0;y--);
50 1 }
51
52
53 void main( )
C51 COMPILER V9.00 MAIN 10/11/2019 10:20:02 PAGE 2
54 {
55 1 unsigned char status,i,j;
56 1 unsigned int temp;
57 1 InitializeSystem( );
58 1 PcdReset();
59 1 PcdAntennaOff();
60 1 PcdAntennaOn();
61 1 while ( 1 )
62 1 {
63 2 if(open1==1 || open2==1 || open3==1){
64 3 delay1(700);
65 3 if(open1==1 || open2==1 || open3==1){
66 4 int x,y;
67 4 beep=1;
68 4 for(y=0;y<100;y++){
69 5 for(x=0;x<14;x++){s=1;Delay100us();}
70 5 for(x=0;x<186;x++){s=0;Delay100us();}
71 5 }
72 4 delay1(500);
73 4
74 4 for(y=0;y<150;y++){
75 5 for(x=0;x<5;x++){s=1;Delay100us();}
76 5 for(x=0;x<195;x++){s=0;Delay100us();}
77 5 }
78 4 }
79 3 }
80 2 status = PcdRequest(PICC_REQALL, g_ucTempbuf);//寻卡
81 2 if (status != MI_OK)
82 2 {
83 3 InitializeSystem( );
84 3 PcdReset();
85 3 PcdAntennaOff();
86 3 PcdAntennaOn();
87 3 P0=0x00;
88 3 continue;
89 3 }
90 2
91 2 /*printf("卡的类型:");
92 2 for(i=0;i<2;i++)
93 2 {
94 2 temp=g_ucTempbuf[i];
95 2 printf("%X",temp);
96 2
97 2 }*/
98 2
99 2 status = PcdAnticoll(g_ucTempbuf);//防冲撞
100 2 if (status != MI_OK)
101 2 { continue; }
102 2
103 2
104 2 ////////以下为串口助手打印出的内容////////////////////////
105 2
106 2 //printf("卡序列号:"); //超级终端显示,
107 2 for(i=0;i<4;i++)
108 2 {
109 3 temp=g_ucTempbuf[i];
110 3 card_id[i]=g_ucTempbuf[i];
111 3 //printf("%X",temp);
112 3 printf("%d",card_id[i]);
113 3 printf(";");
114 3
115 3 }
C51 COMPILER V9.00 MAIN 10/11/2019 10:20:02 PAGE 3
116 2
117 2 printf("\n");
118 2
119 2 for(i=0;i<4;i++){ //验证第1个人
120 3 if(card_id[i]==id1[i]){p1=1;}
121 3 else{p1=0;break;}
122 3 }
123 2
124 2 for(i=0;i<4;i++){ //验证第2个人
125 3 if(card_id[i]==id2[i]){p2=1;}
126 3 else{p2=0;break;}
127 3 }
128 2
129 2 for(i=0;i<4;i++){ //验证第3个人
130 3 if(card_id[i]==id3[i]){p3=1;}
131 3 else{p3=0;break;}
132 3 }
133 2
134 2 for(i=0;i<4;i++){ //验证第4个人
135 3 if(card_id[i]==id4[i]){p4=1;}
136 3 else{p4=0;break;}
137 3 }
138 2
139 2 for(i=0;i<4;i++){ //验证第5个人
140 3 if(card_id[i]==id5[i]){p5=1;}
141 3 else{p5=0;break;}
142 3 }
143 2
144 2 ///////////////////////////开门操作////////////////////////
145 2
146 2 if(p1==1||p2==1||p3==1||p4==1||p5==1){
147 3
148 3 int x,y;
149 3 beep=1;
150 3
151 3 for(y=0;y<100;y++){
152 4 for(x=0;x<14;x++){s=1;Delay100us();}
153 4 for(x=0;x<186;x++){s=0;Delay100us();}
154 4 }
155 3 delay1(500);
156 3
157 3 for(y=0;y<150;y++){
158 4 for(x=0;x<5;x++){s=1;Delay100us();}
159 4 for(x=0;x<195;x++){s=0;Delay100us();}
160 4 }
161 3
162 3 p1=0;p2=0;p3=0;p4=0;p5=0; //复位
163 3
164 3 }
165 2
166 2
167 2
168 2 //////////////////////////////////////////////////////////
169 2
170 2
171 2 status = PcdSelect(g_ucTempbuf);//选定卡片
172 2 if (status != MI_OK)
173 2 { continue; }
174 2
175 2 status = PcdAuthState(PICC_AUTHENT1A, 1, DefaultKey, g_ucTempbuf);//验证卡片密码
176 2 if (status != MI_OK)
177 2 { continue; }
C51 COMPILER V9.00 MAIN 10/11/2019 10:20:02 PAGE 4
178 2
179 2 status = PcdWrite(1, data1);//写块
180 2 if (status != MI_OK)
181 2 { continue; }
182 2
183 2 }
184 1 }
*** WARNING C280 IN LINE 55 OF MAIN.C: 'j': unreferenced local variable
185
186
187 /////////////////////////////////////////////////////////////////////
188 //系统初始化
189 /////////////////////////////////////////////////////////////////////
190 void InitializeSystem()
191 {
192 1 /* P0M1 = 0x0; P0M2 = 0x0;
193 1 P1M1 = 0x0; P1M2 = 0x0;
194 1 P3M1 = 0x0; P3M2 = 0xFF;
195 1 */
196 1
197 1 P0 = 0xff; P1 = 0x00; P3 = 0xFF;P2 = 0xFE;
198 1
199 1 TMOD=0x21; //设T0为方式1,GATE=1;
200 1 SCON=0x50;
201 1 TH1=0xF4; //波特率为2400bps
202 1 TL1=0xF4;
203 1 TH0=0;
204 1 TL0=0;
205 1 TR0=1;
206 1 ET0=1; //允许T0中断
207 1 TR1=1; //开启定时器
208 1 TI=1;
209 1 EA=1; //开启总中断
210 1
211 1 ES = 1;
212 1 RI = 1;
213 1
214 1
215 1
216 1 }
217
218
219
220
221
222
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1130 ----
CONSTANT SIZE = 33 ----
XDATA SIZE = ---- ----
PDATA SIZE = 78 9
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 1 WARNING(S), 0 ERROR(S)