📄 fm1715.lst
字号:
536 2 temp=temp&0x01;
537 2 if(temp==0x00)
538 2 {
539 3 temp=Check_UID();
540 3 if(temp==FALSE)
541 3 {
542 4 return(FM1715_SERNRERR);
543 4 }
544 3 return(FM1715_OK);
545 3 }
546 2 else
547 2 {
548 3 temp=CollPos; //read collision register
549 3 row=temp/8;
550 3 col=temp%8;
551 3 buffer[0]=RF_CMD_ANTICOL; //set the count that the data to be sent
C51 COMPILER V7.09 FM1715 07/26/2005 17:00:30 PAGE 10
552 3 pre_row=pre_row+row;
553 3 for(i=0;i<pre_row+1;i++)
554 3 {
555 4 buffer[i+2]=UID[i];
556 4 }
557 3 if(col!=0x00)
558 3 {
559 4 row=pre_row+1;
560 4 }
561 3 else
562 3 {
563 4 row=pre_row;
564 4 }
565 3 temp=Command_Send(row+2,buffer,Transceive);
566 3 }
567 2 }
568 1 }
569
570 //********************************************************************
571 //name: Select_Card
572 //function: Select the card in FM1715 control range
573 //input: N/A
574 //output: FM1715_NOTAGERR:no card
575 // FM1715_PARITYERR:parity error
576 // FM1715_CRCERR: CRC verify error
577 // FM1715_BTECOUNTERR: Receive byte error
578 // FM1715_OK: ack succeed
579 // FM1715_SELERR: select error
580 //*********************************************************************
581 uchar Select_Card(void)
582 {
583 1 uchar temp,i;
584 1
585 1 CRCPresetLSB=0x63;
586 1 CWConductance=0x3f;
587 1 buffer[0]=RF_CMD_SELECT;
588 1 buffer[1]=0x70;
589 1 for(i=0;i<5;i++)
590 1 {
591 2 buffer[i+2]=UID[i];
592 2 }
593 1 ChannelRedundancy=0x0f;
594 1 temp=Command_Send(7,buffer,Transceive);
595 1
596 1 if(temp==FALSE)
597 1 {
598 2 return(FM1715_NOTAGERR);
599 2 }
600 1 else
601 1 {
602 2 temp=ErrorFlag;
603 2 if((temp&0x02)==0x02)
604 2 return(FM1715_PARITYERR);
605 2 if((temp&0x04)==0x04)
606 2 return(FM1715_FRAMINGERR);
607 2 if((temp&0x08)==0x08)
608 2 return(FM1715_CRCERR);
609 2
610 2 temp=FIFO_Length;
611 2 if(temp!=1)
612 2 return(FM1715_BYTECOUNTERR);
613 2 Read_FIFO(buffer); //Read FIFO information
C51 COMPILER V7.09 FM1715 07/26/2005 17:00:30 PAGE 11
614 2 temp=*buffer;
615 2 if(temp!=0) //check ack signal
616 2 return(FM1715_OK);
617 2 else
618 2 return(FM1715_SELERR);
619 2 }
620 1 }
621
622 //*************************************************************************
623 //name:Authentication
624 //function: password autherntication
625 //input: UID: card serial address
626 // SecNR: sector number
627 // mode: mode
628 //output: FM1715_NOTAGERR: no card
629 // FM1715_PARITYERR:parity error
630 // FM1715_CRCERR: CRC error
631 // FM1715_OK: ack succeed
632 // FM1715_AUTHERR: authentication error
633 //**************************************************************************
634 uchar Authentication(uchar idata *UID,uchar SecNR, uchar mode)
635 {
636 1 uchar idata i;
637 1 uchar idata temp,temp1;
638 1
639 1 CRCPresetLSB=0x63;
640 1 CWConductance=0x3f;
641 1 ModConductance=0x3f;
642 1 temp1=Control;
643 1 temp1=temp1&0xf7;
644 1 Control=temp1;
645 1
646 1 if(mode==1) //authentication
647 1 buffer[0]=RF_CMD_AUTH_LB;
648 1 else
649 1 buffer[0]=RF_CMD_AUTH_LA;
650 1 buffer[1]=SecNR*4 +3;
651 1 for(i=0;i<4;i++)
652 1 {
653 2 buffer[2+i]=UID[i];
654 2 }
655 1 ChannelRedundancy=0x0f; //start crc,parity verify
656 1 temp=Command_Send(6,buffer,Authent1);
657 1 if(temp==FALSE)
658 1 {
659 2 return FM1715_NOTAGERR;
660 2 }
661 1 temp=ErrorFlag;
662 1 if((temp&0x02)==0x02)
663 1 return FM1715_PARITYERR;
664 1 if((temp&0x04)==0x04)
665 1 return FM1715_FRAMINGERR;
666 1 if((temp&0x08)==0x08)
667 1 return FM1715_CRCERR;
668 1
669 1 temp=Command_Send(0,buffer,Authent2); //Authent2
670 1 if(temp==FALSE)
671 1 {
672 2 return FM1715_NOTAGERR;
673 2 }
674 1 temp=ErrorFlag;
675 1 if((temp&0x02)==0x02)
C51 COMPILER V7.09 FM1715 07/26/2005 17:00:30 PAGE 12
676 1 return FM1715_PARITYERR;
677 1 if((temp&0x04)==0x04)
678 1 return FM1715_FRAMINGERR;
679 1 if((temp&0x08)==0x08)
680 1 return FM1715_CRCERR;
681 1 temp1=Control;
682 1 temp1=temp1&0x08;
683 1 if(temp1==0x08)
684 1 {
685 2 return FM1715_OK;
686 2 }
687 1 return FM1715_AUTHERR;
688 1 }
689
690 //*********************************************************************
691 //name:MIF_Read
692 //fucntion: read Mifare card block value
693 //input:buff: buffer headaddress
694 // Block_Adr: Block address
695 //output: FM1715_NOTAGERR: no card
696 // FM1715_PARITYERR: parity error
697 // FM1715_CRCERR: CRC verify error
698 // FM1715_BYTECOUNTERR: receive error
699 // FM1715_OK: Ack succeed
700 //**********************************************************************
701 uchar MIF_READ(uchar idata *buff,uchar Block_Adr)
702 {
703 1 uchar idata temp;
704 1
705 1 CRCPresetLSB=0x63;
706 1 CWConductance=0x3f;
707 1 ModConductance=0x3f; //FM1702无此register
708 1 ChannelRedundancy=0x0f;
709 1 //Int_Req=0x7f;
710 1
711 1 buff[0]=RF_CMD_READ;
712 1 buff[1]=Block_Adr;
713 1 temp=Command_Send(2,buff,Transceive);
714 1 if(temp==0)
715 1 {
716 2 return FM1715_NOTAGERR;
717 2 }
718 1 temp=ErrorFlag;
719 1 if((temp&0x02)==0x02) return FM1715_PARITYERR;
720 1 if((temp&0x04)==0x04) return FM1715_FRAMINGERR;
721 1 if((temp&0x08)==0x08) return FM1715_CRCERR;
722 1 temp=FIFO_Length;
723 1 if(temp==0x10) //8k card read data length is 16
724 1 {
725 2 Read_FIFO(buff);
726 2 return FM1715_OK;
727 2 }
728 1 else if(temp==0x04) //Token card read data length is 16
729 1 {
730 2 Read_FIFO(buff);
731 2 return FM1715_OK;
732 2 }
733 1 else
734 1 {
735 2 return FM1715_BYTECOUNTERR;
736 2 }
737 1 }
C51 COMPILER V7.09 FM1715 07/26/2005 17:00:30 PAGE 13
738
739
740 /****************************************************************/
741 /*名称: MIF_Write */
742 /*功能: 该函数实现写 MIFARE 卡块的数值 */
743 /*输入: buff: 缓冲区首地址
744 */
745 /* Block_Adr: 块地址
746 */
747 /*输出: FM1715_NOTAGERR: 无卡 */
748 /* FM1715_BYTECOUNTERR: 接收字节错误 */
749 /* FM1715_NOTAUTHERR: 未经权威认证 */
750 /* FM1715_EMPTY: 数据溢出错误 */
751 /* FM1715_CRCERR: CRC 校验错 */
752 /* FM1715_PARITYERR: 奇偶校验错 */
753 /* FM1715_WRITEERR: 写卡块数据出错 */
754 /* FM1715_OK: 应答正确
755 */
756 /****************************************************************/
757 uchar MIF_Write(uchar idata *buff,uchar Block_Adr)
758 {
759 1 uchar idata temp;
760 1 uchar idata *F_buff; CRCPresetLSB = 0x63; CWConductance = 0x3f; F_buff =
761 1 buff + 0x10; ChannelRedundancy = 0x07;
762 1 *F_buff = RF_CMD_WRITE;
763 1 *(F_buff + 1) = Block_Adr;
764 1 temp = Command_Send(2, F_buff, Transceive);
765 1 if (temp == FALSE)
766 1 {
767 2 return(FM1715_NOTAGERR);
768 2 }
769 1 temp = FIFO_Length;
770 1 if (temp == 0)
771 1 {
772 2 return(FM1715_BYTECOUNTERR);
773 2 }
774 1 Read_FIFO(F_buff);
775 1 temp = *F_buff;
776 1 switch (temp)
777 1 {
778 2 case 0x00 :
779 2 return(FM1715_NOTAUTHERR); //暂时屏蔽掉写错误
780 2 case 0x04:
781 2 return(FM1715_EMPTY);
782 2 case 0x0a:
783 2 break;
784 2 case 0x01:
785 2 return(FM1715_CRCERR);
786 2 case 0x05:
787 2 return(FM1715_PARITYERR);
788 2 default:
789 2 return(FM1715_WRITEERR);
790 2 }
791 1 temp = Command_Send(16, buff, Transceive);
792 1 if (temp == TRUE)
793 1 {
794 2 return(FM1715_OK);
795 2 }
796 1 else
797 1 {
798 2 temp = ErrorFlag;
799 2 if ((temp & 0x02)==0x02)
C51 COMPILER V7.09 FM1715 07/26/2005 17:00:30 PAGE 14
800 2 return(FM1715_PARITYERR);
801 2 else if((temp & 0x04)==0x04)
802 2 return(FM1715_FRAMINGERR);
803 2 else if ((temp & 0x08)==0x08)
804 2 return(FM1715_CRCERR);
805 2 else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -