📄 main.lst
字号:
418 2
419 2 case 0x12: // Idle the card //卡休眠
420 2
421 2 for(cnt=0;cnt<3;cnt++)
422 2 {
423 3 cStatus =SPI_Write(CardHalt);
424 3 delay_10ms(2); // 延时等待模块执行命令
425 3 cStatus =SPI_Read(cp); // 保存到数组cP
426 3 if((cStatus==SUCCESS)&&(cp[1]==HALT_CARD))
427 3 {
C51 COMPILER V8.02 MAIN 12/27/2006 08:14:28 PAGE 8
428 4 SendBuffer[0]=0x02;
429 4 SendBuffer[1]=cmd;
430 4 cnt=5; //exit loop
431 4
432 4 }
433 3
434 3 else
435 3 {
436 4 SendBuffer[0]=0x02;
437 4 SendBuffer[1]=~cmd;
438 4 }
439 3 }
440 2 break;
441 2
442 2 case 0x13: // 自动寻卡 ,1字节数据,0x01 开启自动寻卡,0x00关闭
443 2 if(g_cReceBuf[2]==0x01)
444 2 {
445 3 for(cnt=0;cnt<3;cnt++)
446 3 {
447 4 cStatus =SPI_Write(AutoCard); // 发送命令
448 4 delay_10ms(2); // 延时等待模块执行命令
449 4 cStatus =SPI_Read(cp); // 读取并存入到cP
450 4 if((cStatus==SUCCESS)&&(cp[1]==AUTOSEARCH))
451 4 {
452 5 SendBuffer[0]=0x02;
453 5 SendBuffer[1]=cmd;
454 5 cnt=5;
455 5
456 5 cStatus=0;
457 5 }
458 4 else
459 4 {
460 5 SendBuffer[0]=0x02;
461 5 SendBuffer[1]=~cmd;
462 5 cStatus=1;
463 5 }
464 4 }
465 3 }
466 2
467 2 else if(g_cReceBuf[2]==0)
468 2 {
469 3 for(cnt=0;cnt<3;cnt++)
470 3 {
471 4 cStatus =SPI_Write(AutoOff); // 发送命令
472 4 delay_10ms(2); // 延时等待模块执行命令
473 4 cStatus =SPI_Read(cp); // 读取并存入到cP
474 4 if((cStatus==SUCCESS)&&(cp[1]==AUTOSEARCH))
475 4 {
476 5 SendBuffer[0]=0x02;
477 5 SendBuffer[1]=cmd;
478 5 cnt=5;
479 5
480 5 cStatus=0;
481 5 }
482 4 else
483 4 {
484 5 SendBuffer[0]=0x02;
485 5 SendBuffer[1]=~cmd;
486 5 cStatus=1;
487 5 }
488 4 }
489 3
C51 COMPILER V8.02 MAIN 12/27/2006 08:14:28 PAGE 9
490 3 }
491 2 else
492 2 {
493 3 SendBuffer[0]=0x02;
494 3 SendBuffer[1]=~cmd;
495 3 cStatus=1;
496 3 }
497 2 break;
498 2
499 2
500 2 case 0x14: // 蜂鸣器操作 ,1字节数据,0x1y 开启并使蜂鸣器响y声,0x0y关闭
501 2 g_cBeeps=g_cReceBuf[2];
502 2 SendBuffer[0]=0x02;
503 2 SendBuffer[1]=cmd;
504 2 break;
505 2
506 2 case 0x15: // 蜂鸣器操作 ,设置蜂鸣器间隔,1字节数据 ,0.01s
507 2 sp_freq=~g_cReceBuf[2];
508 2 SendBuffer[0]=0x02;
509 2 SendBuffer[1]=cmd;
510 2 break;
511 2
512 2
513 2 case 0x19://读卡类型 //无数据 返回卡类型(2 bytes)
514 2
515 2 for(cnt=0;cnt<3;cnt++)
516 2 {
517 3 cStatus =SPI_Write(ComCardType); // 发送命令
518 3 delay_10ms(2); // 延时等待模块执行命令
519 3 cStatus =SPI_Read(cp); // 读取并存入到cP
520 3 if((cStatus==SUCCESS)&&(cp[1]==CARD_TYPE))
521 3 {
522 4 SendBuffer[0]=4;
523 4 SendBuffer[1]=cmd;
524 4 SendBuffer[2]=cp[2];
525 4 SendBuffer[3]=cp[3];
526 4
527 4 cnt=5;
528 4 }
529 3
530 3 else
531 3 {
532 4 SendBuffer[0]=0x02;
533 4 SendBuffer[1]=~cmd;
534 4 cStatus=1;
535 4 }
536 3 }
537 2 break;
538 2
539 2
540 2 case 0x20: // Request,Anticoll,Select,return CardSerialNo(4 bytes)
541 2 // 寻卡,防冲突,选择卡 返回卡系列号(4 bytes)
542 2 for(cnt=0;cnt<3;cnt++)
543 2 {
544 3 cStatus =SPI_Write(ComSearchCard); // 发送寻卡命令
545 3 delay_10ms(1); // 延时等待模块执行命令
546 3 cStatus =SPI_Read(cp); // 读取卡号并存入到cP
547 3 if((cStatus==SUCCESS)&&(cp[1]==CARD_SN))
548 3 {
549 4 SendBuffer[0]=6;
550 4 SendBuffer[1]=cmd;
551 4 memcpy(&SendBuffer[2],&cp[2],4);
C51 COMPILER V8.02 MAIN 12/27/2006 08:14:28 PAGE 10
552 4
553 4 cnt=5; //exit loop
554 4
555 4 }
556 3
557 3 else
558 3 {
559 4 SendBuffer[0]=0x02;
560 4 SendBuffer[1]=~cmd;
561 4 cStatus=1;
562 4 }
563 3 }
564 2 break;
565 2
566 2 case 0x21: //读块 读写块时建议关闭自动寻卡功能可以提高读写的成功率!
567 2 //数据内容 1 字节密钥标识+1 块号+6 字节密钥
568 2
569 2 for(cnt=0;cnt<3;cnt++) //
570 2 {
571 3 cStatus =SPI_Write(g_cReceBuf); // 发送命令
572 3 delay_10ms(2); // 延时等待模块执行命令
573 3 cStatus =SPI_Read(cp); // 读取并存入到cP
574 3 if((cStatus==SUCCESS)&&(cp[1]==READ_BLOCK))
575 3 {
576 4 SendBuffer[0]=0x12;
577 4 SendBuffer[1]=cmd;
578 4 memcpy(&SendBuffer[2],&cp[2],16);
579 4 cnt=5;
580 4
581 4 }
582 3
583 3 else
584 3 {
585 4 SendBuffer[0]=0x02;
586 4 SendBuffer[1]=~cmd;
587 4 cStatus=1;
588 4 }
589 3 }
590 2
591 2 break;
592 2
593 2 case 0x22 : //写块
594 2 //1 字节密钥标识+1 块号+6 字节密钥+16 字节写入数据
595 2
596 2 for(cnt=0;cnt<3;cnt++)
597 2 {
598 3 cStatus =SPI_Write(g_cReceBuf); // 发送命令
599 3 delay_10ms(2); // 延时等待模块执行命令
600 3 cStatus =SPI_Read(cp); // 读取并存入到cP
601 3 if((cStatus==SUCCESS)&&(cp[1]==WRITE_BLOCK))
602 3 {
603 4 SendBuffer[0]=0x02;
604 4 SendBuffer[1]=cmd;
605 4 cnt=5;
606 4
607 4 }
608 3
609 3 else
610 3 {
611 4 SendBuffer[0]=0x02;
612 4 SendBuffer[1]=~cmd;
613 4 cStatus=1;
C51 COMPILER V8.02 MAIN 12/27/2006 08:14:28 PAGE 11
614 4 }
615 3 }
616 2
617 2 break;
618 2
619 2 case 0x23 : //初始化钱包
620 2 //数据内容“1 字节密钥标识+1 块号+6 字节密钥+4 字节钱包”
621 2
622 2 for(cnt=0;cnt<3;cnt++)
623 2 {
624 3 cStatus =SPI_Write(g_cReceBuf); // 发送命令
625 3 delay_10ms(2); // 延时等待模块执行命令
626 3 cStatus =SPI_Read(cp); // 读取并存入到cP
627 3 if((cStatus==SUCCESS)&&(cp[1]==INIT_PURSE))
628 3 {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -