📄 m101(2)x_test.lst
字号:
C51 COMPILER V7.07 M101_2_X_TEST 07/31/2008 19:29:08 PAGE 1
C51 COMPILER V7.07, COMPILATION OF MODULE M101_2_X_TEST
OBJECT MODULE PLACED IN M101(2)X_Test.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE M101(2)X_Test.C BROWSE DEBUG OBJECTEXTEND
stmt level source
1 /*******************************************************************************
2
3 I2C协议
4 模块I2C地址为0xA0
5 通讯速率为:400K。
6 发送数据格式:
7 模块地址+W/R 长度字 命令字 数据域 校验字
8 模块地址+W/R:
9 模块地址为:0xA0,写bit0为0,则写指令为:0xA0 + 0x0 = 0xA0
10 模块地址为:0xA0,读bit0为1,则读指令为:0xA0 + 0x1 = 0xA1
11 长度字:指明从长度字到数据域最后一字节的字节数。
12 命令字:本条命令的含义。
13 数据域:此项可以为空。
14 校验字:从长度字到数据域最后一字节的逐字节异或值(最后一字节)。
15 返回数据格式:
16 成功: 长度字 接收到的命令字+数据域 校验字
17 失败: 长度字 接收到的命令字取反 校验字
18 *******************************************************************************/
19
20 #include "main.h"
21
22 unsigned char WRITE_M101XX;// 0xb0
23 #define READ_M101XX (WRITE_M101XX + 1)
24
25
26
27 unsigned char g_cReceBuf[43]; //接收缓冲区
28 unsigned char g_cReceNum; //接收字节计数
29 bit g_bReceCommandOk; //接收命令正确标志
30 bit g_bCard; //卡片进入射频场标志
31
32
33 unsigned char ComSet[]
34 = {0x03,
35 COMM_CONTROL_ANTENNA,
36 0x11};
37 //设置打开天线和关闭自动循卡
38 unsigned char code ComSearchCard[]
39 = {0x03,
40 COMM_MIFARE_SEARCH_CARD,
41 0x00};
42 //循卡后读出卡号
43 unsigned char cReadBlock[13]
44 = {0x0A,
45 COMM_READ_BLOCK,
46 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
47 //读块No.4
48 unsigned char code ComReadBlock4[]
49 = {0x0A,
50 COMM_READ_BLOCK,
51 0x00, 0x04, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
52 //读块No.6
53 unsigned char code ComReadBlock6[]
54 = {0x0A,
55 COMM_READ_BLOCK,
C51 COMPILER V7.07 M101_2_X_TEST 07/31/2008 19:29:08 PAGE 2
56 0x00, 0x06, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
57 //写块No.4
58 unsigned char code ComWriteBlock4[]
59 = {0X1A,
60 COMM_WRITE_BLOCK,
61 0x00, 0x04, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
62 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
63 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};
64 //初始化钱包No.5 的值为0x12345678
65 unsigned char code ComIntiPurse5[]
66 = {0x0E,
67 COMM_INIT_PURSE,
68 0x00, 0x05, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff , 0x78, 0x56, 0x34, 0x12};
69 //读钱包的值No.6
70 unsigned char code ComReadPurse6[]
71 = {0x0A,
72 COMM_READ_PURSE,
73 0x00, 0x06, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
74 //钱包值加2
75 unsigned char code ComIncrPurse5[]
76 = {0x0E,
77 COMM_INC_VALUE,
78 0x00, 0x05, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x02, 0x00, 0x00, 0x00};
79 //钱包值减1
80 unsigned char code ComDecrPurse5[]
81 = {0x0E,
82 COMM_DEC_VALUE,
83 0x00, 0x05, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00};
84 // restore purse in block No.5 to block No.6
85 unsigned char code ComBakPurse56[]
86 = {0x0B,
87 COMM_BAK_PURSE,
88 0x00, 0x05, 0x06, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
89 // 卡片休眠
90 unsigned char code ComHaltCard[]
91 = {0x02,
92 COMM_CARD_HALT,
93 };
94 unsigned char code ComHaltMCU[]
95 = {0x02,
96 COMM_SET_MCU_IDLE,
97 };
98 // 钱包在 INC & DEC 后的结果
99 unsigned char code pursevalue[]
100 = {0x79,0x56,0x34, 0x12};
101
102
103
104 void Delay100uS(unsigned int i)
105 {
106 1 unsigned char m;
107 1 while(i--)
108 1 {
109 2 for(m = 0; m < 88; m++)
110 2 {
111 3 LED_zhishi = CARDPIN;
112 3 }
113 2 }
114 1 } /*****************************************************************************
115 系统初始化
116 *****************************************************************************/
117 void InitializeSystem()
C51 COMPILER V7.07 M101_2_X_TEST 07/31/2008 19:29:08 PAGE 3
118 {
119 1
120 1
121 1 IDLE_CLK=0;
122 1 }
123 void main()
124 {
125 1 unsigned char i;
126 1 unsigned char cStatus;
127 1 InitializeSystem();
128 1 i=7;
129 1 P1 = 0XFF;
130 1 P3 = 0XFF;
131 1 WRITE_M101XX = 0xa0;
132 1 while(i--)
133 1 {
134 2 LED_ok = ~LED_ok;
135 2 Delay100uS(400);
136 2 }
137 1 WRITE_M101XX=0xA0;
138 1 LED_ok = 1;
139 1 LED_UART = 1;
140 1 LED_error = 1;
141 1 LED_zhishi = 1;
142 1
143 1
144 1 while (1)
145 1 {
146 2 g_bCard = !CARDPIN;
147 2 LED_zhishi = CARDPIN;
148 2 ES = 0;
149 2 cStatus = IicTesting(); // do IIC testing by AutoSearchCard
150 2 if (SUCCESS != cStatus) // if did not success, alarm error and show error code
151 2 {
152 3 Delay100uS(500);
153 3 g_bCard = !CARDPIN;
154 3 LED_zhishi = CARDPIN;
155 3 ShowError(cStatus);
156 3 continue;
157 3 }
158 2 LED_ok = 0; //测试成功
159 2 Delay100uS(2000);
160 2 CARDPIN = 0;
161 2 Delay100uS(200);
162 2 CARDPIN = 1;
163 2 LED_ok = 1;
164 2 g_bCard = !CARDPIN;
165 2 LED_zhishi = CARDPIN;
166 2 i++;
167 2 }
168 1 }
169 unsigned char IicTesting(void)
170 {
171 1
172 1 unsigned char cReadBlock[10]={0x0a, 0x21, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
173 1 unsigned char *cPa, *cPb;
174 1 unsigned char i;
175 1 unsigned char cStatus;
176 1 Send_IIC_Command(ComSet);
177 1 cStatus = Read_Iic_Data(g_cReceBuf);
178 1 if ((g_cReceBuf[1] != ComSet[1]) || cStatus != SUCCESS)
179 1 {
C51 COMPILER V7.07 M101_2_X_TEST 07/31/2008 19:29:08 PAGE 4
180 2 return 1;
181 2 }
182 1 //寻卡
183 1 cPa = ComSearchCard;
184 1 Send_IIC_Command(cPa);
185 1 cStatus = Read_Iic_Data(g_cReceBuf);
186 1 if ((g_cReceBuf[1] != cPa[1]) || cStatus != SUCCESS)
187 1 {
188 2 return 2;
189 2 }
190 1 cPa = ComSearchCard;
191 1 Send_IIC_Command(cPa);
192 1 cStatus = Read_Iic_Data(g_cReceBuf);
193 1 if ((g_cReceBuf[1] != cPa[1]) || cStatus != SUCCESS)
194 1 {
195 2 return 2;
196 2 }
197 1
198 1 //依次读出s50卡片中的16个扇区,64块的数据
199 1 for(i=0; i<64 ;i++)
200 1 {
201 2 cReadBlock[3] = i;
202 2 cPa = cReadBlock;
203 2 Send_IIC_Command(cPa);
204 2 cStatus = Read_Iic_Data(g_cReceBuf);
205 2 if ((g_cReceBuf[1] != cPa[1]) || cStatus != SUCCESS)
206 2 {
207 3 return 3;
208 3 }
209 2 Delay100uS(50);
210 2 }
211 1
212 1 //写块No.4
213 1 cPa = ComWriteBlock4;
214 1 Send_IIC_Command(cPa);
215 1 cStatus = Read_Iic_Data(g_cReceBuf);
216 1 if ((g_cReceBuf[1] != cPa[1]) || cStatus != SUCCESS)
217 1 {
218 2 return 4;
219 2 }
220 1
221 1 //读块No.4
222 1 cPa = ComReadBlock4;
223 1 Send_IIC_Command(cPa);
224 1 cStatus = Read_Iic_Data(g_cReceBuf);
225 1 if ((g_cReceBuf[1] != cPa[1]) || cStatus != SUCCESS)
226 1 {
227 2 return 5;
228 2 }
229 1 //比较数据
230 1 cPa = &ComWriteBlock4[10];
231 1 cPb = &g_cReceBuf[2];
232 1 if (memcmp(cPa, cPb, 16) != 0)
233 1 {
234 2 return 6;
235 2 }
236 1 //初始化No.5 作为钱包初值为0x12345678
237 1 cPa = ComIntiPurse5;
238 1 Send_IIC_Command(cPa);
239 1 cStatus = Read_Iic_Data(g_cReceBuf);
240 1 if ((g_cReceBuf[1] != cPa[1]) || cStatus != SUCCESS)
241 1 {
C51 COMPILER V7.07 M101_2_X_TEST 07/31/2008 19:29:08 PAGE 5
242 2 return 7;
243 2 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -