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

📄 rc500.lst

📁 RC500的全部操作,读卡
💻 LST
📖 第 1 页 / 共 4 页
字号:
C51 COMPILER V7.06   RC500                                                                 12/15/2008 16:23:27 PAGE 16  

 924              {
 925                  if (status & 0x40)           
 926                  {
 927                      status = MI_KEYERR;
 928                  }
 929                  else
 930                  {
 931                      status = MI_AUTHERR;    
 932                  }
 933              }
 934              else
 935              {
 936                  SerBuffer[0] = auth_mode;    
 937          
 938                  SerBuffer[1] = block;  
 939                  memcpy(SerBuffer + 2,snr,4); 
 940                  ResetInfo(MInfo);
 941                  MInfo.nBytesToSend = 6;
 942                  if ((status = M500PcdCmd(PCD_AUTHENT1,SerBuffer,&MInfo)) == MI_OK)
 943                  {
 944                      if (ReadIO(RegSecondaryStatus) & 0x07) 
 945                      {
 946                          status = MI_BITCOUNTERR;
 947                      }
 948                      else
 949                      {
 950                          ResetInfo(MInfo);
 951                          MInfo.nBytesToSend = 0;
 952                          if ((status = M500PcdCmd(PCD_AUTHENT2,
 953                                               SerBuffer,
 954                                               &MInfo)) == MI_OK) 
 955                          {
 956                              if ( ReadIO(RegControl) & 0x08 ) 
 957                              {
 958                                  status = MI_OK;
 959                              }
 960                              else
 961                              {
 962                                  status = MI_AUTHERR;
 963                              }
 964                          }
 965                      }
 966                  }
 967              }
 968              return status;
 969          }*/
 970          
 971          ////////////////////////////////////////////////////////////////
 972          // Read the mifare card
 973          // 读卡
 974          ////////////////////////////////////////////////////////////////
 975          /*char M500PiccRead(unsigned char addr,unsigned char *_data)
 976          {
 977              char idata status = MI_OK;
 978              char idata tmp    = 0;
 979          
 980              FlushFIFO();    
 981          
 982              M500PcdSetTmo(3);  
 983              WriteIO(RegChannelRedundancy,0x0F);
 984              ResetInfo(MInfo);   
 985              SerBuffer[0] = PICC_READ;   
C51 COMPILER V7.06   RC500                                                                 12/15/2008 16:23:27 PAGE 17  

 986              SerBuffer[1] = addr;
 987              MInfo.nBytesToSend   = 2;   
 988              status = M500PcdCmd(PCD_TRANSCEIVE,SerBuffer,&MInfo);
 989          
 990              if (status != MI_OK)
 991              {
 992                  if (status != MI_NOTAGERR ) 
 993                  {
 994                      if (MInfo.nBitsReceived == 4)  
 995                      {
 996                          SerBuffer[0] &= 0x0f;  
 997                          if ((SerBuffer[0] & 0x0a) == 0)
 998                          {
 999                              status = MI_NOTAUTHERR;
1000                          }
1001                          else
1002                          {
1003                              status = MI_CODEERR;
1004                          }
1005                      }
1006                  }
1007                  memcpy(_data,"0000000000000000",16); 
1008              }
1009              else                // Response Processing
1010              {
1011                  if (MInfo.nBytesReceived != 16)
1012                  {
1013                      status = MI_BYTECOUNTERR;
1014                      memcpy(_data,"0000000000000000",16);
1015                  }
1016                  else
1017                  {
1018                      memcpy(_data,SerBuffer,16);
1019                  }
1020              }
1021              M500PcdSetTmo(1);             
1022              return status; 
1023          }*/
1024          
1025          ////////////////////////////////////////////////////////////////
1026          // Write the mifare card
1027          // 写卡  下载密码
1028          ////////////////////////////////////////////////////////////////
1029          /*char M500PiccWrite( unsigned char addr,unsigned char *_data)
1030          {
1031              char idata status = MI_OK;
1032              
1033              ResetInfo(MInfo);   
1034              SerBuffer[0] = PICC_WRITE; 
1035              SerBuffer[1] = addr;            
1036              MInfo.nBytesToSend   = 2;
1037              status = M500PcdCmd(PCD_TRANSCEIVE,SerBuffer,&MInfo);
1038          
1039              if (status != MI_NOTAGERR)   
1040              {
1041                  if (MInfo.nBitsReceived != 4)  
1042                  {
1043                      status = MI_BITCOUNTERR;
1044                  }
1045                  else                     
1046                  {
1047                      SerBuffer[0] &= 0x0f; 
C51 COMPILER V7.06   RC500                                                                 12/15/2008 16:23:27 PAGE 18  

1048                      if ((SerBuffer[0] & 0x0a) == 0)
1049                      {
1050                          status = MI_NOTAUTHERR;                   
1051                      }
1052                      else
1053                      {
1054                          if (SerBuffer[0] == 0x0a)
1055                          {
1056                              status = MI_OK;
1057                          }
1058                          else 
1059                          {
1060                              status = MI_CODEERR;
1061                          }
1062                      }
1063                  }
1064              }
1065          
1066              if ( status == MI_OK)
1067              {
1068                  M500PcdSetTmo(3);    
1069          
1070                  ResetInfo(MInfo);   
1071                  memcpy(SerBuffer,_data,16);
1072                  MInfo.nBytesToSend   = 16;
1073                  status = M500PcdCmd(PCD_TRANSCEIVE,SerBuffer,&MInfo);
1074                  
1075                  if (status & 0x80)   
1076                  {
1077                      status = MI_NOTAGERR;
1078                  }
1079                  else
1080                  {
1081                      if (MInfo.nBitsReceived != 4) 
1082                      {
1083                          status = MI_BITCOUNTERR;
1084                      }
1085                      else                  
1086                      {
1087                          SerBuffer[0] &= 0x0f; 
1088                          if ((SerBuffer[0] & 0x0a) == 0)
1089                          {
1090                              status = MI_WRITEERR;
1091                          }
1092                          else
1093                          {
1094                              if (SerBuffer[0] == 0x0a)
1095                              {
1096                                  status = MI_OK;
1097                              }
1098                              else 
1099                              {
1100                                  status = MI_CODEERR;
1101                              }
1102                          }     
1103                      }
1104                  }        
1105                  M500PcdSetTmo(1);  
1106              }
1107              return status;
1108          }*/
1109          
C51 COMPILER V7.06   RC500                                                                 12/15/2008 16:23:27 PAGE 19  

1110          ///////////////////////////////////////////////////////////////////////
1111          // Reset Rf Card
1112          ///////////////////////////////////////////////////////////////////////
1113          char M500PcdRfReset(unsigned char ms)
1114          {
1115   1          char idata status = MI_OK;
1116   1              
1117   1          if(ms)
1118   1          {
1119   2              ClearBitMask(RegTxControl,0x03); 
1120   2              delay_ms(2);                
1121   2              SetBitMask(RegTxControl,0x03); 
1122   2          }
1123   1          else
1124   1          {
1125   2              ClearBitMask(RegTxControl,0x03);  
1126   2          }
1127   1          return status;
1128   1      }
1129          
1130          ///////////////////////////////////////////////////////////////////////
1131          // MF RC500 Config
1132          ///////////////////////////////////////////////////////////////////////
1133          char MfConfig(void)
1134          {
1135   1              char status=MI_OK;
1136   1              
1137   1              EX0=1;
1138   1              IT0 = 1;        
1139   1      
1140   1              M500PcdConfig();
1141   1              M500PcdMfOutSelect(2);
1142   1              return status;
1143   1      }
1144          
1145          ///////////////////////////////////////////////////////////////////////
1146          //外中断0
1147          //RC500中断请求
1148          ///////////////////////////////////////////////////////////////////////
1149          void RC500ISR (void) interrupt 0 using 1    
1150          {
1151   1          static unsigned char idata irqBits;
1152   1          static unsigned char idata irqMask;            
1153   1          static unsigned char idata nbytes;
1154   1          static unsigned char idata cnt;
1155   1              
1156   1          IE0 = 0;    
1157   1          WriteRawIO(0,0x80);         //选择寄存器页0
1158   1          if (MpIsrInfo && MpIsrOut)
1159   1          {
1160   2                      //PrimaryStatus 寄存器,读取接收器、发送器和FIFO 缓冲区状态标志
1161   2              while( ReadRawIO(RegPrimaryStatus) & 0x08)      //test IRQ 
1162   2              {
1163   3                  irqMask = ReadRawIO(RegInterruptEn);        //使能和禁止中断请求通过的控制位
1164   3                  irqBits = ReadRawIO(RegInterruptRq) & irqMask;      //中断请求标志
1165   3                  MpIsrInfo->irqSource |= irqBits; 
1166   3                  if (irqBits & 0x01)   
1167   3                  {  
1168   4                      nbytes = 64 - ReadRawIO(RegFIFOLength);         //FIFO 中的缓冲字节数
1169   4                      if ((MpIsrInfo->nBytesToSend - MpIsrInfo->nBytesSent) <= nbytes)
1170   4                      {
1171   5                          nbytes = MpIsrInfo->nBytesToSend - MpIsrInfo->nBytesSent;
C51 COMPILER V7.06   RC500                                                                 12/15/2008 16:23:27 PAGE 20  

1172   5                          WriteRawIO(RegInterruptEn,0x01);    //允许将LoAlert中断请求传递给脚IRQ
1173   5                      }   
1174   4                      for ( cnt = 0;cnt < nbytes;cnt++)
1175   4                      {
1176   5                          WriteRawIO(RegFIFOData,MpIsrOut[MpIsrInfo->nBytesSent]);    //FIFO 缓冲区
1177   5                          MpIsrInfo->nBytesSent++;
1178   5                      }
1179   4                      WriteRawIO(RegInterruptRq,0x01);        //中断请求标志
1180   4                  }      
1181   3                  if (irqBits & 0x10)    
1182   3                  {
1183   4                      WriteRawIO(RegInterruptRq,0x10);    
1184   4                      WriteRawIO(RegInterruptEn,0x82);   
1185   4                      if (MpIsrInfo->cmd == PICC_ANTICOLL1)   
1186   4                          {                                        
1187   5                          WriteIO(RegChannelRedundancy,0x02); //选择RF 信道上数据完整性检测的类型和模式
1188   5                          WriteRawIO(0,0x80);
1189   5                          }   
1190   4                  }
1191   3                  if (irqBits & 0x0E) 
1192   3                  {
1193   4                      nbytes = ReadRawIO(RegFIFOLength);
1194   4                      for ( cnt = 0; cnt < nbytes; cnt++)               
1195   4                      {
1196   5                          MpIsrOut[MpIsrInfo->nBytesReceived] = ReadRawIO(RegFIFOData);
1197   5                          MpIsrInfo->nBytesReceived++;
1198   5                      }
1199   4                      WriteRawIO(RegInterruptRq,0x0A & irqBits); 
1200   4                  }   
1201   3                  if (irqBits & 0x04) 
1202   3                  {
1203   4                      WriteRawIO(RegInterruptEn,0x20); 
1204   4                      WriteRawIO(RegInterruptRq,0x20); 
1205   4                      irqBits &= ~0x20; 
1206   4                      MpIsrInfo->irqSource &= ~0x20;
1207   4                      WriteRawIO(RegInterruptRq,0x04);
1208   4                  }
1209   3                  if (irqBits & 0x20)     
1210   3                  {
1211   4                      WriteRawIO(RegInterruptRq,0x20); 
1212   4                      MpIsrInfo->status = MI_NOTAGERR; 
1213   4                  }
1214   3              }
1215   2          }
1216   1      }
1217          
1218          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   2482    ----
   CONSTANT SIZE    =      5    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     26      20
   IDATA SIZE       =     13      28
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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