⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 m500auc.lst

📁 奥尔斯公司pxa270试验箱射频卡读写器相关资料
💻 LST
📖 第 1 页 / 共 5 页
字号:
 848          */
 849          ///////////////////////////////////////////////////////////////////////
 850          //
 851          ///////////////////////////////////////////////////////////////////////
 852          char M500PiccAuthState( unsigned char auth_mode,unsigned char *snr,unsigned char block)
 853          {
 854   1          char idata status = MI_OK;
 855   1          unsigned char idata i = 0;
 856   1      
 857   1          status = ReadIO(RegErrorFlag);
 858   1          if (status != MI_OK)
 859   1          {
 860   2              if (status & 0x40)
 861   2              {
C51 COMPILER V6.02  M500AUC                                                                02/09/2006 13:25:02 PAGE 15  

 862   3                  status = MI_KEYERR;
 863   3              }
 864   2              else
 865   2              {
 866   3                  status = MI_AUTHERR;
 867   3              }
 868   2          }
 869   1          else
 870   1          {
 871   2              SerBuffer[0] = auth_mode;
 872   2      
 873   2              SerBuffer[1] = block;
 874   2              memcpy(SerBuffer + 2,snr,4);
 875   2              ResetInfo(MInfo);
 876   2              MInfo.nBytesToSend = 6;
 877   2              if ((status = M500PcdCmd(PCD_AUTHENT1,SerBuffer,&MInfo)) == MI_OK)
 878   2              {
 879   3                  if (ReadIO(RegSecondaryStatus) & 0x07)
 880   3                  {
 881   4                      status = MI_BITCOUNTERR;
 882   4                  }
 883   3                  else
 884   3                  {
 885   4                      ResetInfo(MInfo);
 886   4                      MInfo.nBytesToSend = 0;
 887   4                      if ((status = M500PcdCmd(PCD_AUTHENT2,
 888   4                                           SerBuffer,
 889   4                                           &MInfo)) == MI_OK)
 890   4                      {
 891   5                          if ( ReadIO(RegControl) & 0x08 )
 892   5                          {
 893   6                              status = MI_OK;
 894   6                          }
 895   5                          else
 896   5                          {
 897   6                              status = MI_AUTHERR;
 898   6                          }
 899   5                      }
 900   4                  }
 901   3              }
 902   2          }
 903   1          return status;
 904   1      }
 905          
 906          ////////////////////////////////////////////////////////////////
 907          // Read the mifare card
 908          // 读卡
 909          // addr: 所读目标数据的地址
 910          // data: 读出数据所存放的地址
 911          ////////////////////////////////////////////////////////////////
 912          char M500PiccRead(unsigned char addr,unsigned char *_data)
 913          {
 914   1          char idata status = MI_OK;
 915   1          char idata tmp    = 0;
 916   1      
 917   1          FlushFIFO();
 918   1      
 919   1          M500PcdSetTmo(3);
 920   1          WriteIO(RegChannelRedundancy,0x0F);
 921   1          ResetInfo(MInfo);
 922   1          SerBuffer[0] = PICC_READ;
 923   1          SerBuffer[1] = addr;
C51 COMPILER V6.02  M500AUC                                                                02/09/2006 13:25:02 PAGE 16  

 924   1          MInfo.nBytesToSend   = 2;
 925   1          status = M500PcdCmd(PCD_TRANSCEIVE,SerBuffer,&MInfo);
 926   1      
 927   1          if (status != MI_OK)
 928   1          {
 929   2              if (status != MI_NOTAGERR )
 930   2              {
 931   3                  if (MInfo.nBitsReceived == 4)
 932   3                  {
 933   4                      SerBuffer[0] &= 0x0f;
 934   4                      if ((SerBuffer[0] & 0x0a) == 0)
 935   4                      {
 936   5                          status = MI_NOTAUTHERR;
 937   5                      }
 938   4                      else
 939   4                      {
 940   5                          status = MI_CODEERR;
 941   5                      }
 942   4                  }
 943   3              }
 944   2              memcpy(_data,"0000000000000000",16);
 945   2          }
 946   1          else                // Response Processing
 947   1          {
 948   2              if (MInfo.nBytesReceived != 16)
 949   2              {
 950   3                  status = MI_BYTECOUNTERR;
 951   3                  memcpy(_data,"0000000000000000",16);
 952   3              }
 953   2              else
 954   2              {
 955   3                  memcpy(_data,SerBuffer,16);
 956   3              }
 957   2          }
 958   1          M500PcdSetTmo(1);
 959   1          return status;
 960   1      }
 961          
 962          ////////////////////////////////////////////////////////////////
 963          // Write the mifare card
 964          // 写卡  下载密码
 965          // addr: 所写的 卡的地址
 966          // data: 所写数据的地址
 967          ////////////////////////////////////////////////////////////////
 968          /*
 969          char M500PiccWrite( unsigned char addr,unsigned char *_data)
 970          {
 971              char idata status = MI_OK;
 972          
 973              ResetInfo(MInfo);
 974              SerBuffer[0] = PICC_WRITE;
 975              SerBuffer[1] = addr;
 976              MInfo.nBytesToSend   = 2;
 977              status = M500PcdCmd(PCD_TRANSCEIVE,SerBuffer,&MInfo);
 978          
 979              if (status != MI_NOTAGERR)
 980              {
 981                  if (MInfo.nBitsReceived != 4)
 982                  {
 983                      status = MI_BITCOUNTERR;
 984                  }
 985                  else
C51 COMPILER V6.02  M500AUC                                                                02/09/2006 13:25:02 PAGE 17  

 986                  {
 987                      SerBuffer[0] &= 0x0f;
 988                      if ((SerBuffer[0] & 0x0a) == 0)
 989                      {
 990                          status = MI_NOTAUTHERR;
 991                      }
 992                      else
 993                      {
 994                          if (SerBuffer[0] == 0x0a)
 995                          {
 996                              status = MI_OK;
 997                          }
 998                          else
 999                          {
1000                              status = MI_CODEERR;
1001                          }
1002                      }
1003                  }
1004              }
1005          
1006              if ( status == MI_OK)
1007              {
1008                  M500PcdSetTmo(3);
1009          
1010                  ResetInfo(MInfo);
1011                  memcpy(SerBuffer,_data,16);
1012                  MInfo.nBytesToSend   = 16;
1013                  status = M500PcdCmd(PCD_TRANSCEIVE,SerBuffer,&MInfo);
1014          
1015                  if (status & 0x80)
1016                  {
1017                      status = MI_NOTAGERR;
1018                  }
1019                  else
1020                  {
1021                      if (MInfo.nBitsReceived != 4)
1022                      {
1023                          status = MI_BITCOUNTERR;
1024                      }
1025                      else
1026                      {
1027                          SerBuffer[0] &= 0x0f;
1028                          if ((SerBuffer[0] & 0x0a) == 0)
1029                          {
1030                              status = MI_WRITEERR;
1031                          }
1032                          else
1033                          {
1034                              if (SerBuffer[0] == 0x0a)
1035                              {
1036                                  status = MI_OK;
1037                              }
1038                              else
1039                              {
1040                                  status = MI_CODEERR;
1041                              }
1042                          }
1043                      }
1044                  }
1045                  M500PcdSetTmo(1);
1046              }
1047              return status;
C51 COMPILER V6.02  M500AUC                                                                02/09/2006 13:25:02 PAGE 18  

1048          }
1049          */
1050          ///////////////////////////////////////////////////////////////////////
1051          // Reset Rf Card
1052          // ms: RF电路重启的时间
1053          ///////////////////////////////////////////////////////////////////////
1054          
1055          char M500PcdRfReset(unsigned char ms)
1056          {
1057   1          char idata status = MI_OK;
1058   1      
1059   1          if(ms)
1060   1          {
1061   2              ClearBitMask(RegTxControl,0x03);
1062   2              delay_1ms(2);
1063   2              SetBitMask(RegTxControl,0x03);
1064   2          }
1065   1          else
1066   1          {
1067   2              ClearBitMask(RegTxControl,0x03);
1068   2          }
1069   1          return status;
1070   1      }
1071          
1072          #pragma noaregs
1073          
1074          ///////////////////////////////////////////////////////////////////////
1075          // Delay 50us
1076          ///////////////////////////////////////////////////////////////////////
1077          void delay_50us(unsigned char _50us)
1078          {
1079   1          while(_50us--)
1080   1      	{
1081   2      	    _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
1082   2      	    _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
1083   2      	    _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
1084   2      	    _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
1085   2      	    _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
1086   2      	    _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
1087   2      	    _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
1088   2      	    _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
1089   2          }
1090   1      }
1091          
1092          ///////////////////////////////////////////////////////////////////////
1093          // Delay 1ms
1094          ///////////////////////////////////////////////////////////////////////
1095          void delay_1ms(unsigned char _1ms)
1096          {
1097   1      #ifndef NO_TIMER2
                  RCAP2LH = RCAP2_1ms;
                  T2LH    = RCAP2_1ms;
              
                  TR2 = TRUE;
                  while (_1ms--)
                  {
              	    while (!TF2);
              	    TF2 = FALSE;
                  }
                  TR2 = FALSE;
              #else
1109   1          while (_1ms--)
C51 COMPILER V6.02  M500AUC                                                                02/09/2006 13:25:02 PAGE 19  

1110   1          {
1111   2      	    delay_50us(20);
1112   2          }
1113   1      #endif
1114   1      }
1115          
1116          ///////////////////////////////////////////////////////////////////////
1117          // Delay 10ms
1118          ///////////////////////////////////////////////////////////////////////
1119          void delay_10ms(unsigned int _10ms)
1120          {
1121   1      #ifndef NO_TIMER2
                  RCAP2LH = RCAP2_10ms;
                  T2LH    = RCAP2_10ms;
              
                  TR2 = TRUE;
                  while (_10ms--)
                  {
              	    while (!TF2);
              	    TF2 = FALSE;
                  }
                  TR2 = FALSE;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -