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

📄 main.lst

📁 20086238534741.rar
💻 LST
📖 第 1 页 / 共 5 页
字号:
1066   1          
1067   1          e2addrbuf = (uchar *)&e2addr;
1068   1          if (auth_mode == PICC_AUTHENT1B)
1069   1          {
1070   2              e2addr += 12; 
1071   2          }
1072   1          FlushFIFO();    
1073   1          ResetInfo(MInfo);
1074   1      
1075   1          memcpy(SerBuffer,e2addrbuf,2); 
1076   1          SerBuffer[2] = SerBuffer[0];      
1077   1          SerBuffer[0] = SerBuffer[1]; 
1078   1          SerBuffer[1] = SerBuffer[2];
1079   1          MInfo.nBytesToSend   = 2;
1080   1          if ((status=M500PcdCmd(PCD_LOADKEYE2,SerBuffer,&MInfo)) == MI_OK)
1081   1          {  
1082   2              status = M500PiccAuthState(auth_mode,snr,block);  
1083   2          }
1084   1          return status;
1085   1      }                        
1086          
1087          ///////////////////////////////////////////////////////////////////////
1088          // Authentication key coding
1089          ///////////////////////////////////////////////////////////////////////
1090          char M500HostCodeKey(  uchar *uncoded, uchar *coded)   
1091          {
1092   1          char idata status = MI_OK;
1093   1          uchar idata cnt = 0;
1094   1          uchar idata ln  = 0;     
1095   1          uchar idata hn  = 0;      
1096   1          for (cnt = 0; cnt < 6; cnt++)
1097   1          {
1098   2              ln = uncoded[cnt] & 0x0F;
1099   2              hn = uncoded[cnt] >> 4;
1100   2              coded[cnt * 2 + 1] = (~ln << 4) | ln;
1101   2              coded[cnt * 2 ] = (~hn << 4) | hn;
1102   2          }
1103   1          return MI_OK;
1104   1      }
1105          
1106          ///////////////////////////////////////////////////////////////////////
1107          //校验状态
1108          ///////////////////////////////////////////////////////////////////////
1109          char M500PiccAuthState( uchar auth_mode,uchar *snr,uchar block)
C51 COMPILER V6.23a  MAIN                                                                  08/14/2006 14:40:24 PAGE 19  

1110          {
1111   1          char idata status = MI_OK;
1112   1          uchar idata i = 0;
1113   1         
1114   1          status = ReadIO(RegErrorFlag);                                     
1115   1          if (status != MI_OK)
1116   1          {
1117   2              if (status & 0x40)           
1118   2              {
1119   3                  status = MI_KEYERR;
1120   3              }
1121   2              else
1122   2              {
1123   3                  status = MI_AUTHERR;    
1124   3              }
1125   2          }
1126   1          else
1127   1          {
1128   2              SerBuffer[0] = auth_mode;    
1129   2      
1130   2              SerBuffer[1] = block;  
1131   2              memcpy(SerBuffer + 2,snr,4); 
1132   2              ResetInfo(MInfo);
1133   2              MInfo.nBytesToSend = 6;
1134   2              if ((status = M500PcdCmd(PCD_AUTHENT1,SerBuffer,&MInfo)) == MI_OK)
1135   2              {
1136   3                  if (ReadIO(RegSecondaryStatus) & 0x07) 
1137   3                  {
1138   4                      status = MI_BITCOUNTERR;
1139   4                  }
1140   3                  else
1141   3                  {
1142   4                      ResetInfo(MInfo);
1143   4                      MInfo.nBytesToSend = 0;
1144   4                      if ((status = M500PcdCmd(PCD_AUTHENT2,
1145   4                                           SerBuffer,
1146   4                                           &MInfo)) == MI_OK) 
1147   4                      {
1148   5                          if ( ReadIO(RegControl) & 0x08 ) 
1149   5                          {
1150   6                              status = MI_OK;
1151   6                          }
1152   5                          else
1153   5                          {
1154   6                              status = MI_AUTHERR;
1155   6                          }
1156   5                      }
1157   4                  }
1158   3              }
1159   2          }
1160   1          return status;
1161   1      }
1162          
1163          ////////////////////////////////////////////////////////////////
1164          // Read the mifare card
1165          // 读卡
1166          ////////////////////////////////////////////////////////////////
1167          char M500PiccRead(uchar addr,uchar *_data)
1168          {
1169   1          char idata status = MI_OK;
1170   1          char idata tmp    = 0;
1171   1      
C51 COMPILER V6.23a  MAIN                                                                  08/14/2006 14:40:24 PAGE 20  

1172   1          FlushFIFO();    
1173   1      
1174   1          M500PcdSetTmo(3);  
1175   1          WriteIO(RegChannelRedundancy,0x0F);
1176   1          ResetInfo(MInfo);   
1177   1          SerBuffer[0] = PICC_READ;   
1178   1          SerBuffer[1] = addr;
1179   1          MInfo.nBytesToSend   = 2;   
1180   1          status = M500PcdCmd(PCD_TRANSCEIVE,SerBuffer,&MInfo);
1181   1      
1182   1          if (status != MI_OK)
1183   1          {
1184   2              if (status != MI_NOTAGERR ) 
1185   2              {
1186   3                  if (MInfo.nBitsReceived == 4)  
1187   3                  {
1188   4                      SerBuffer[0] &= 0x0f;  
1189   4                      if ((SerBuffer[0] & 0x0a) == 0)
1190   4                      {
1191   5                          status = MI_NOTAUTHERR;
1192   5                      }
1193   4                      else
1194   4                      {
1195   5                          status = MI_CODEERR;
1196   5                      }
1197   4                  }
1198   3              }
1199   2              memcpy(_data,"0000000000000000",16); 
1200   2          }
1201   1          else                // Response Processing
1202   1          {
1203   2              if (MInfo.nBytesReceived != 16)
1204   2              {
1205   3                  status = MI_BYTECOUNTERR;
1206   3                  memcpy(_data,"0000000000000000",16);
1207   3              }
1208   2              else
1209   2              {
1210   3                  memcpy(_data,SerBuffer,16);
1211   3              }
1212   2          }
1213   1          M500PcdSetTmo(1);             
1214   1          return status; 
1215   1      }
1216          
1217          ////////////////////////////////////////////////////////////////
1218          // Write the mifare card
1219          // 写卡  下载密码
1220          ////////////////////////////////////////////////////////////////
1221          char M500PiccWrite( uchar addr,uchar *_data)
1222          {
1223   1          char idata status = MI_OK;
1224   1          
1225   1          ResetInfo(MInfo);   
1226   1          SerBuffer[0] = PICC_WRITE; 
1227   1          SerBuffer[1] = addr;            
1228   1          MInfo.nBytesToSend   = 2;
1229   1          status = M500PcdCmd(PCD_TRANSCEIVE,SerBuffer,&MInfo);
1230   1      
1231   1          if (status != MI_NOTAGERR)   
1232   1          {
1233   2              if (MInfo.nBitsReceived != 4)  
C51 COMPILER V6.23a  MAIN                                                                  08/14/2006 14:40:24 PAGE 21  

1234   2              {
1235   3                  status = MI_BITCOUNTERR;
1236   3              }
1237   2              else                     
1238   2              {
1239   3                  SerBuffer[0] &= 0x0f; 
1240   3                  if ((SerBuffer[0] & 0x0a) == 0)
1241   3                  {
1242   4                      status = MI_NOTAUTHERR;                   
1243   4                  }
1244   3                  else
1245   3                  {
1246   4                      if (SerBuffer[0] == 0x0a)
1247   4                      {
1248   5                          status = MI_OK;
1249   5                      }
1250   4                      else 
1251   4                      {
1252   5                          status = MI_CODEERR;
1253   5                      }
1254   4                  }
1255   3              }
1256   2          }
1257   1      
1258   1          if ( status == MI_OK)
1259   1          {
1260   2              M500PcdSetTmo(3);    
1261   2      
1262   2              ResetInfo(MInfo);   
1263   2              memcpy(SerBuffer,_data,16);
1264   2              MInfo.nBytesToSend   = 16;
1265   2              status = M500PcdCmd(PCD_TRANSCEIVE,SerBuffer,&MInfo);
1266   2              
1267   2              if (status & 0x80)   
1268   2              {
1269   3                  status = MI_NOTAGERR;
1270   3              }
1271   2              else
1272   2              {
1273   3                  if (MInfo.nBitsReceived != 4) 
1274   3                  {
1275   4                      status = MI_BITCOUNTERR;
1276   4                  }
1277   3                  else                  
1278   3                  {
1279   4                      SerBuffer[0] &= 0x0f; 
1280   4                      if ((SerBuffer[0] & 0x0a) == 0)
1281   4                      {
1282   5                          status = MI_WRITEERR;
1283   5                      }
1284   4                      else
1285   4                      {
1286   5                          if (SerBuffer[0] == 0x0a)
1287   5                          {
1288   6                              status = MI_OK;
1289   6                          }
1290   5                          else 
1291   5                          {
1292   6                              status = MI_CODEERR;
1293   6                          }
1294   5                      }     
1295   4                  }
C51 COMPILER V6.23a  MAIN                                                                  08/14/2006 14:40:24 PAGE 22  

1296   3              }        
1297   2              M500PcdSetTmo(1);  
1298   2          }
1299   1          return status;
1300   1      }
1301          
1302          ///////////////////////////////////////////////////////////////////////
1303          // Reset Rf Card
1304          ///////////////////////////////////////////////////////////////////////
1305          char M500PcdRfReset(uchar ms)
1306          {
1307   1          char idata status = MI_OK;
1308   1              
1309   1          if(ms)
1310   1          {
1311   2              ClearBitMask(RegTxControl,0x03); 
1312   2              delay_1ms(2);                
1313   2              SetBitMask(RegTxControl,0x03); 
1314   2          }
1315   1          else
1316   1          {
1317   2              ClearBitMask(RegTxControl,0x03);  
1318   2          }
1319   1          return status;
1320   1      }
1321          
1322          #pragma noaregs
1323          
1324          ///////////////////////////////////////////////////////////////////////
1325          // Delay 50us
1326          ///////////////////////////////////////////////////////////////////////
1327          void delay_50us(uchar _50us)
1328          {
1329   1        RCAP2LH = RCAP2_50us;
1330   1        T2LH    = RCAP2_50us;
1331   1        ET2 = 0;      // Disable timer2 interrupt
1332   1

⌨️ 快捷键说明

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