📄 main.lst
字号:
242 3 Login(); //
243 3 break;
244 3 case 0x83 :
245 3 Disable();
246 3 break;
247 3 case 0x84 :
248 3 PCLinkReader(); //PC要求与读卡器连接
249 3 break;
250 3 case 0x85 :
251 3 //DefaultRead(); //
252 3 break;
253 3 case 0x86 :
254 3 Readonly_autodetection(); //只读,自动检测,可读4100,配置4469,读4469
255 3 break;
256 3 case 0xFB :
257 3 GetReaderConfiguration(); //读取读卡器的配置参数
258 3 break;
259 3 case 0xFC :
260 3 SetReaderConfiguration(); //设置读卡器的配置参数
261 3 break;
262 3 case 0xFD :
263 3 ReadStatusToPC(); //读卡
264 3 break;
265 3 case 0xFE :
266 3 FieldSwitch();
267 3 break;
268 3 case 0xF0:
269 3 FieldReset();
270 3 break;
271 3 case 0x10:
272 3 Read4100ID();
273 3 break;
274 3 default :
275 3 break;
276 3 }
277 2 }
278 1 }
279
280 //读卡数据,区地址=rx_buff[3],发送到PC,本版本支持的PC演示软件可以看到相应的数据
281 void ReadWordToPC(void)
282 {
283 1 uchar fwd_bit_count;
284 1 fwd_bit_count = Prepare_Cmd( FWD_CMD_READ );
285 1 fwd_bit_count += Prepare_Addr(rx_buff[3]);
286 1 SendForward(fwd_bit_count);
287 1 Wait(tpp_period);
288 1 maxCaptureTimeLow = maxTRead; //=3880
289 1 maxCaptureTimeHi = 0;
290 1 ManchesterRead();
291 1 tx_buff[0]=0x02; //帧头
292 1 tx_buff[1]=0x09; //帧信息长度,从tx_buff[2]开始计算,到tx_buff[10]=0x03结束
293 1 tx_buff[2]=0x80; //命令字
294 1 tx_buff[3]=check_stat;
295 1 tx_buff[4]=rx_buff[3]; //地址
296 1 tx_buff[5]=capture_data[0]; //数据
297 1 tx_buff[6]=capture_data[1]; //数据
298 1 tx_buff[7]=capture_data[2]; //数据
299 1 tx_buff[8]=capture_data[3]; //数据
300 1 tx_buff[9]=(tx_buff[1]^tx_buff[2]^tx_buff[3]^tx_buff[4]^tx_buff[5]^tx_buff[6]^tx_buff[7]^tx_buff[8]);
301 1 //tx_buff[9]是校验和
302 1 tx_buff[10]=0x03; //帧结束标志
C51 COMPILER V7.50 MAIN 06/07/2006 18:04:04 PAGE 6
303 1 trace(tx_buff,11); //发送到PC 11个字节
304 1 }
305
306 //写PC传过来的数据到ID卡上
307 void WriteWordtoCard(void)
308 {
309 1 uchar fwd_bit_count;
310 1
311 1 fwd_bit_count = Prepare_Cmd( FWD_CMD_WRITE );
312 1 fwd_bit_count += Prepare_Addr(rx_buff[3]);
313 1 fwd_bit_count += Prepare_Data(( ((uint)rx_buff[5] << 8) + rx_buff[4]), ( ((uint)rx_buff[7] << 8) + rx_b
-uff[6]));
314 1 if (rx_buff[3] == 0x04)
315 1 { //32位配置字
316 2
317 2 halfDataRate = 32;// datarate = RF/64
318 2 MaxCaptureHalfDateRate = halfDataRate + (halfDataRate >> 1); //=48
319 2 MaxCaptureDateRate = halfDataRate + halfDataRate + (halfDataRate >> 1); //=80
320 2 lwr = config_lwr;
321 2 delayed = config_delayed;
322 2 raw = config_raw;
323 2 //forward_link_type = 0x01;
324 2 maxTLogin = 4 + (4 + 9) * 2 * (uint)halfDataRate;
325 2 maxTWrite = 1144 + (4 + 8) * 2 * (uint)halfDataRate;
326 2 maxTWriteRaw = 1144 + (4 + 5 + 54) * 2 * (uint)halfDataRate;
327 2 maxTRead = (100) + 4 + (5 + 54) * 2 * (uint)halfDataRate;
328 2 maxTDisable = maxTLogin;
329 2 maxTDefaultRead = 2*((lwr-4)*4*8)*2*((uint32)halfDataRate);
330 2 tpp_period = 4 + 2 * (uint)halfDataRate - 4;
331 2 twr_period = (68 + 64 + 896 + 116) + 2 * (uint)halfDataRate - 4;
332 2 }
333 1
334 1 SendForward(fwd_bit_count);
335 1 Wait(twr_period);
336 1 maxCaptureTimeHi = 0;
337 1 maxCaptureTimeLow = maxTWrite;
338 1
339 1 ManchesterWrite();
340 1
341 1 tx_buff[0]=0x02;
342 1 tx_buff[1]=0x04;
343 1 tx_buff[2]=0x81;
344 1 tx_buff[3]=check_stat;
345 1 tx_buff[4]=(tx_buff[1]^tx_buff[2]^tx_buff[3]);
346 1 tx_buff[5]=0x03;
347 1 trace(tx_buff,6);
348 1 }
349
350 //控制天线命令
351 void FieldSwitch(void)
352 {
353 1 if (rx_buff[3] & 1 )
354 1 {
355 2 SHD=0; //打开天线
356 2 }
357 1 else
358 1 {
359 2 SHD=1; // 关闭天线
360 2 }
361 1 tx_buff[0]=0x02; //帧头
362 1 tx_buff[1]=0x04; //长度
363 1 tx_buff[2]=0xfe; //命令
C51 COMPILER V7.50 MAIN 06/07/2006 18:04:04 PAGE 7
364 1 tx_buff[3]=0;
365 1 tx_buff[4]=(tx_buff[1]^tx_buff[2]^tx_buff[3]); //检验和
366 1 tx_buff[5]=0x03; //帧结束
367 1 trace(tx_buff,6);
368 1 }
369
370 //不可用,匹配PC演示程序,直接返回 设置成功
371 void SetReaderConfiguration(void)
372 {
373 1 tx_buff[0]=0x02;
374 1 tx_buff[1]=0x04;
375 1 tx_buff[2]=0xfc;
376 1 tx_buff[3]=0;
377 1 tx_buff[4]=(tx_buff[1]^tx_buff[2]^tx_buff[3]);
378 1 tx_buff[5]=0x03;
379 1 trace(tx_buff,6);
380 1 }
381
382 //读取DEMO读卡器的配置参数
383 void GetReaderConfiguration(void)
384 {
385 1 uchar q;
386 1 q = 1;
387 1 get_settings_low = (q<<6) | (halfDataRate - 1);
388 1 q = (q >> 2) | (delayed << 4) | ((lwr & 3) << 6);
389 1 get_settings_low |= (uint)q << 8;
390 1 get_settings_hi = ((raw << 6) | (lwr >> 2));// | (forward_link_type >> 1);
391 1
392 1 tx_buff[0]=0x02;
393 1 tx_buff[1]=0x08;
394 1 tx_buff[2]=0xfb;
395 1 tx_buff[3]=0;
396 1 tx_buff[4]=(uchar)get_settings_low;
397 1 tx_buff[5]=get_settings_low>>8;
398 1 tx_buff[6]=(uchar)get_settings_hi;
399 1 tx_buff[7]=get_settings_hi>>8;
400 1 tx_buff[8]=(tx_buff[1]^tx_buff[2]^tx_buff[3]^tx_buff[4]^tx_buff[5]^tx_buff[6]^tx_buff[7]);
401 1 tx_buff[9]=0x03;
402 1 trace(tx_buff,10);
403 1 }
404
405 void Disable(void)
406 {
407 1 uchar fwd_bit_count;
408 1 fwd_bit_count = Prepare_Cmd( FWD_CMD_DISABLE );
409 1 fwd_bit_count += Prepare_Data( 0xFFFF, 0xFFFF );
410 1 SendForward(fwd_bit_count);
411 1 Wait(tpp_period);
412 1 maxCaptureTimeLow = maxTDisable;
413 1 maxCaptureTimeHi = 0;
414 1
415 1 ManchesterRead();
416 1
417 1 tx_buff[0]=0x02;
418 1 tx_buff[1]=0x04;
419 1 tx_buff[2]=0x83;
420 1 tx_buff[3]=check_stat;
421 1 tx_buff[4]=(tx_buff[1]^tx_buff[2]^tx_buff[3]);
422 1 tx_buff[5]=0x03;
423 1 trace(tx_buff,6);
424 1 }
425
C51 COMPILER V7.50 MAIN 06/07/2006 18:04:04 PAGE 8
426 void Login(void)
427 {
428 1 uchar fwd_bit_count;
429 1 fwd_bit_count = Prepare_Cmd( FWD_CMD_LOGIN );
430 1 fwd_bit_count += Prepare_Data(( ((uint)rx_buff[4] << 8) + rx_buff[3]), ( ((uint)rx_buff[6] << 8) + rx_buf
-f[5]));
431 1 SendForward(fwd_bit_count);
432 1 Wait(tpp_period);
433 1 maxCaptureTimeLow = maxTLogin;
434 1 maxCaptureTimeHi = 0;
435 1 ManchesterWrite();
436 1 tx_buff[0]=0x02;
437 1 tx_buff[1]=0x04;
438 1 tx_buff[2]=0x82;
439 1 tx_buff[3]=check_stat;
440 1 tx_buff[4]=(tx_buff[1]^tx_buff[2]^tx_buff[3]);
441 1 tx_buff[5]=0x03;
442 1 trace(tx_buff,6);
443 1 }
444
445
446 void PCLinkReader(void)
447 {
448 1 tx_buff[3]=UART_MESSAGE_OK;
449 1 tx_buff[0]=0x02;
450 1 tx_buff[1]=0x04;
451 1 tx_buff[2]=0x84;
452 1 tx_buff[4]=(tx_buff[1]^tx_buff[2]^tx_buff[3]);
453 1 tx_buff[5]=0x03;
454 1 trace(tx_buff,6);
455 1 speak_on();
456 1 }
457
458 void Readonly_autodetection(void)
459 {
460 1 uchar i,j,k,l;
461 1
462 1 uchar idata autodection_data[32];
463 1 uchar array_subscript; //小标
464 1 uchar bit_subscript;
465 1 uint capt;
466 1 uint icr;
467 1 bit flag_RO_last_capt_half=0;
468 1 uchar count_autodection_bit=0;
469 1 bit flag_header_found=0;
470 1 bit flag_stop_found=0;
471 1 bit flag_line_check=0;
472 1 bit flag_column_check=0;
473 1 uchar check=0;
474 1 uchar custID=0;
475 1 uchar idata DataItem[4]={0,0,0,0};
476 1 uchar bit_number;
477 1 bit flag_tag_datarate_bigger;
478 1 bit flag_invalid_edge_manchester;
479 1 uchar times_capture_manchester;
480 1
481 1 //halfDataRate = 32;//config_data_rate+1;
482 1 MaxCaptureHalfDateRate = 48;//halfDataRate+(halfDataRate>>1);
483 1 MaxCaptureDateRate = 80;//halfDataRate+halfDataRate+(halfDataRate>>1);
484 1 //lwr = 7;//config_lwr;
485 1 //maxTDefaultRead = 0x3000;//2*((lwr-4)*4*8)*2*((uint32)halfDataRate);
486 1 maxCaptureTimeLow = 0x3000;//(uint)maxTDefaultRead;
C51 COMPILER V7.50 MAIN 06/07/2006 18:04:04 PAGE 9
487 1 maxCaptureTimeHi = 0x30;//(uchar)(maxTDefaultRead >> 16);
488 1 last_capture = 0xcfff;//~maxCaptureTimeLow;
489 1 TF2 = 0;
490 1 TR2 = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -