📄 m500auc.lst
字号:
830 1 else
831 1 {
832 2 SerBuffer[0] = auth_mode;
833 2
834 2 SerBuffer[1] = block;
835 2 memcpy(SerBuffer + 2,snr,4);
836 2 ResetInfo(MInfo);
837 2 MInfo.nBytesToSend = 6;
838 2 if ((status = M500PcdCmd(PCD_AUTHENT1,SerBuffer,&MInfo)) == MI_OK)
839 2 {
840 3 if (ReadIO(RegSecondaryStatus) & 0x07)
841 3 {
842 4 status = MI_BITCOUNTERR;
843 4 }
844 3 else
845 3 {
846 4 ResetInfo(MInfo);
847 4 MInfo.nBytesToSend = 0;
848 4 if ((status = M500PcdCmd(PCD_AUTHENT2,
849 4 SerBuffer,
850 4 &MInfo)) == MI_OK)
851 4 {
852 5 if ( ReadIO(RegControl) & 0x08 )
853 5 {
854 6 status = MI_OK;
855 6 }
856 5 else
857 5 {
858 6 status = MI_AUTHERR;
859 6 }
860 5 }
861 4 }
C51 COMPILER V7.06 M500AUC 03/16/2008 20:55:11 PAGE 15
862 3 }
863 2 }
864 1 return status;
865 1 }
866
867 ////////////////////////////////////////////////////////////////
868 // Read the mifare card
869 // 读卡
870 ////////////////////////////////////////////////////////////////
871 char M500PiccRead(unsigned char addr,unsigned char *_data)
872 {
873 1 char idata status = MI_OK;
874 1 char idata tmp = 0;
875 1
876 1 FlushFIFO();
877 1
878 1 M500PcdSetTmo(3);
879 1 WriteIO(RegChannelRedundancy,0x0F);
880 1 ResetInfo(MInfo);
881 1 SerBuffer[0] = PICC_READ;
882 1 SerBuffer[1] = addr;
883 1 MInfo.nBytesToSend = 2;
884 1 status = M500PcdCmd(PCD_TRANSCEIVE,SerBuffer,&MInfo);
885 1
886 1 if (status != MI_OK)
887 1 {
888 2 if (status != MI_NOTAGERR )
889 2 {
890 3 if (MInfo.nBitsReceived == 4)
891 3 {
892 4 SerBuffer[0] &= 0x0f;
893 4 if ((SerBuffer[0] & 0x0a) == 0)
894 4 {
895 5 status = MI_NOTAUTHERR;
896 5 }
897 4 else
898 4 {
899 5 status = MI_CODEERR;
900 5 }
901 4 }
902 3 }
903 2 memcpy(_data,"0000000000000000",16);
904 2 }
905 1 else // Response Processing
906 1 {
907 2 if (MInfo.nBytesReceived != 16)
908 2 {
909 3 status = MI_BYTECOUNTERR;
910 3 memcpy(_data,"0000000000000000",16);
911 3 }
912 2 else
913 2 {
914 3 memcpy(_data,SerBuffer,16);
915 3 }
916 2 }
917 1 M500PcdSetTmo(1);
918 1 return status;
919 1 }
920
921 ////////////////////////////////////////////////////////////////
922 // Write the mifare card
923 // 写卡 下载密码
C51 COMPILER V7.06 M500AUC 03/16/2008 20:55:11 PAGE 16
924 ////////////////////////////////////////////////////////////////
925 char M500PiccWrite( unsigned char addr,unsigned char *_data)
926 {
927 1 char idata status = MI_OK;
928 1
929 1 ResetInfo(MInfo);
930 1 SerBuffer[0] = PICC_WRITE;
931 1 SerBuffer[1] = addr;
932 1 MInfo.nBytesToSend = 2;
933 1 status = M500PcdCmd(PCD_TRANSCEIVE,SerBuffer,&MInfo);
934 1
935 1 if (status != MI_NOTAGERR)
936 1 {
937 2 if (MInfo.nBitsReceived != 4)
938 2 {
939 3 status = MI_BITCOUNTERR;
940 3 }
941 2 else
942 2 {
943 3 SerBuffer[0] &= 0x0f;
944 3 if ((SerBuffer[0] & 0x0a) == 0)
945 3 {
946 4 status = MI_NOTAUTHERR;
947 4 }
948 3 else
949 3 {
950 4 if (SerBuffer[0] == 0x0a)
951 4 {
952 5 status = MI_OK;
953 5 }
954 4 else
955 4 {
956 5 status = MI_CODEERR;
957 5 }
958 4 }
959 3 }
960 2 }
961 1
962 1 if ( status == MI_OK)
963 1 {
964 2 M500PcdSetTmo(3);
965 2
966 2 ResetInfo(MInfo);
967 2 memcpy(SerBuffer,_data,16);
968 2 MInfo.nBytesToSend = 16;
969 2 status = M500PcdCmd(PCD_TRANSCEIVE,SerBuffer,&MInfo);
970 2
971 2 if (status & 0x80)
972 2 {
973 3 status = MI_NOTAGERR;
974 3 }
975 2 else
976 2 {
977 3 if (MInfo.nBitsReceived != 4)
978 3 {
979 4 status = MI_BITCOUNTERR;
980 4 }
981 3 else
982 3 {
983 4 SerBuffer[0] &= 0x0f;
984 4 if ((SerBuffer[0] & 0x0a) == 0)
985 4 {
C51 COMPILER V7.06 M500AUC 03/16/2008 20:55:11 PAGE 17
986 5 status = MI_WRITEERR;
987 5 }
988 4 else
989 4 {
990 5 if (SerBuffer[0] == 0x0a)
991 5 {
992 6 status = MI_OK;
993 6 }
994 5 else
995 5 {
996 6 status = MI_CODEERR;
997 6 }
998 5 }
999 4 }
1000 3 }
1001 2 M500PcdSetTmo(1);
1002 2 }
1003 1 return status;
1004 1 }
1005
1006 ///////////////////////////////////////////////////////////////////////
1007 // Reset Rf Card
1008 ///////////////////////////////////////////////////////////////////////
1009 char M500PcdRfReset(unsigned char ms)
1010 {
1011 1 char idata status = MI_OK;
1012 1
1013 1 if(ms)
1014 1 {
1015 2 ClearBitMask(RegTxControl,0x03);
1016 2 delay_1ms(2);
1017 2 SetBitMask(RegTxControl,0x03);
1018 2 }
1019 1 else
1020 1 {
1021 2 ClearBitMask(RegTxControl,0x03);
1022 2 }
1023 1 return status;
1024 1 }
1025
1026 #pragma noaregs
1027
1028 ///////////////////////////////////////////////////////////////////////
1029 // Delay 50us
1030 ///////////////////////////////////////////////////////////////////////
1031 void delay_50us(unsigned char _50us)
1032 {
1033 1 while(_50us--)
1034 1 {
1035 2 _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
1036 2 _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
1037 2 _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
1038 2 _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
1039 2 _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
1040 2 _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
1041 2 _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
1042 2 _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
1043 2 }
1044 1 }
1045
1046 ///////////////////////////////////////////////////////////////////////
1047 // Delay 1ms
C51 COMPILER V7.06 M500AUC 03/16/2008 20:55:11 PAGE 18
1048 ///////////////////////////////////////////////////////////////////////
1049 void delay_1ms(unsigned char _1ms)
1050 {
1051 1 #ifndef NO_TIMER2
RCAP2LH = RCAP2_1ms;
T2LH = RCAP2_1ms;
TR2 = TRUE;
while (_1ms--)
{
while (!TF2);
TF2 = FALSE;
}
TR2 = FALSE;
#else
1063 1 while (_1ms--)
1064 1 {
1065 2 delay_50us(20);
1066 2 }
1067 1 #endif
1068 1 }
1069
1070 ///////////////////////////////////////////////////////////////////////
1071 // Delay 10ms
1072 ///////////////////////////////////////////////////////////////////////
1073 void delay_10ms(unsigned int _10ms)
1074 {
1075 1 #ifndef NO_TIMER2
RCAP2LH = RCAP2_10ms;
T2LH = RCAP2_10ms;
TR2 = TRUE;
while (_10ms--)
{
while (!TF2);
TF2 = FALSE;
}
TR2 = FALSE;
#else
1087 1 while (_10ms--)
1088 1 {
1089 2 delay_50us(19);
1090 2 if (CmdValid)
1091 2 return;
1092 2 delay_50us(20);
1093 2 if (CmdValid)
1094 2 return;
1095 2 delay_50us(20);
1096 2 if (CmdValid)
1097 2 return;
1098 2 delay_50us(20);
1099 2 if (CmdValid)
1100 2 return;
1101 2 delay_50us(20);
1102 2 if (CmdValid )
1103 2 return;
1104 2 delay_50us(20);
1105 2 if (CmdValid)
1106 2 return;
1107 2 delay_50us(20);
1108 2 if (CmdValid)
1109 2 return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -