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

📄 iso14443a.lst

📁 RC500可用的程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.06   ISO14443A                                                             05/01/2009 01:52:11 PAGE 1   


C51 COMPILER V7.06, COMPILATION OF MODULE ISO14443A
OBJECT MODULE PLACED IN ISO14443A.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ISO14443A.C ROM(COMPACT) BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          #include "reg52.h"
   2          #include <intrins.h>
   3          #include <string.h>
   4          #include <absacc.h>
   5          #include "main.h"
   6          #include "slrc500.h" 
   7          #include "iso14443a.h"
   8          #define FSD 64              //RC500 FIFO BUFFER SIZE
   9          extern struct TranSciveBuffer{unsigned char MfCommand;
  10                                        unsigned int  MfLength;
  11                                        unsigned char MfData[64];
  12                                       };
  13                                        
  14          /////////////////////////////////////////////////////////////////////
  15          //功    能:寻卡
  16          //参数说明: req_code[IN]:寻卡方式
  17          //                0x52 = 寻感应区内所有符合14443A标准的卡
  18          //                0x26 = 寻未进入休眠状态的卡
  19          //         pTagType[OUT]:卡片类型代码
  20          //                0x0A= Mifare_UltraLight
  21          //                0x04 = Mifare_One(S50)
  22          //                0x02 = Mifare_One(S70)
  23          //                0x08 = Mifare_Pro
  24          //返    回: 成功返回MI_OK
  25          /////////////////////////////////////////////////////////////////////
  26          char PcdRequest(unsigned char req_code,unsigned char *pTagType)
  27          {
  28   1         char status;   
  29   1         struct TranSciveBuffer MfComData;
  30   1         struct TranSciveBuffer *pi;
  31   1         pi = &MfComData;
  32   1      
  33   1         WriteRawRC(RegChannelRedundancy,0x03);       //无CRC,单独产生或者出现奇数的奇偶校验,
  34   1         //奇偶校验位在每个字节后插入发送数据流中并会出现在接收数据流的每个字节后
  35   1         ClearBitMask(RegControl,0x08);                       //该位指示Crypto1 单元关闭因此与卡的所有数据通信都不被加密
  36   1         WriteRawRC(RegBitFraming,0x07);                      //TxLastBits 用于位方式帧的发送TxLastBits 
  37   1         //定义要发送的最后一个字节的位数目000指示最后字节的所有位都要发送在发送之后TxLastBits 自动清零
  38   1         SetBitMask(RegTxControl,0x03);                       //关闭天线
  39   1         PcdSetTmo(4);
  40   1         MfComData.MfCommand = PCD_TRANSCEIVE;
  41   1         MfComData.MfLength  = 1;
  42   1         MfComData.MfData[0] = req_code;
  43   1      
  44   1         status = PcdComTransceive(pi);
  45   1         
  46   1         if (!status)
  47   1         {    
  48   2              if (MfComData.MfLength != 0x10)
  49   2              {   status = MI_BITCOUNTERR;   }
  50   2         }
  51   1         *pTagType     = MfComData.MfData[0];
  52   1         return status;
  53   1      }
  54          
  55          /////////////////////////////////////////////////////////////////////
C51 COMPILER V7.06   ISO14443A                                                             05/01/2009 01:52:11 PAGE 2   

  56          //防冲撞
  57          //input: g_cSNR=存放序列号(4byte)的内存单元首地址
  58          //output:status=MI_OK:成功
  59          //       得到的序列号放入指定单元
  60          /////////////////////////////////////////////////////////////////////
  61          char PcdAnticoll(unsigned char *pSnr)
  62          {
  63   1          char status ;
  64   1          unsigned char i;
  65   1          unsigned char ucBits;
  66   1          unsigned char ucBytes;
  67   1          unsigned char snr_check = 0;
  68   1          unsigned char ucCollPosition = 0;
  69   1          unsigned char ucTemp;
  70   1          unsigned char idata ucSNR[5] = {0, 0, 0, 0 ,0};
  71   1          struct TranSciveBuffer MfComData;
  72   1          struct TranSciveBuffer *pi;
  73   1          pi = &MfComData;
  74   1      
  75   1          WriteRawRC(RegDecoderControl,0x28);
  76   1          ClearBitMask(RegControl,0x08);
  77   1          WriteRawRC(RegChannelRedundancy,0x03);
  78   1          PcdSetTmo(4);
  79   1          
  80   1      
  81   1          do
  82   1          {
  83   2              ucBits = (ucCollPosition) % 8;
  84   2              if (ucBits != 0)
  85   2              {
  86   3                   ucBytes = ucCollPosition / 8 + 1;
  87   3                   WriteRawRC(RegBitFraming, (ucBits << 4) + ucBits);
  88   3              }
  89   2              else
  90   2              {
  91   3                   ucBytes = ucCollPosition / 8;
  92   3              }
  93   2              
  94   2              MfComData.MfCommand = PCD_TRANSCEIVE;
  95   2              MfComData.MfData[0] = PICC_ANTICOLL1;
  96   2              MfComData.MfData[1] = 0x20 + ((ucCollPosition / 8) << 4) + (ucBits & 0x0F);
  97   2              for (i=0; i<ucBytes; i++)
  98   2                  {
  99   3                      MfComData.MfData[i + 2] = ucSNR[i];
 100   3                  }
 101   2                  MfComData.MfLength = ucBytes + 2;
 102   2              
 103   2                  status = PcdComTransceive(pi);
 104   2              
 105   2                  ucTemp = ucSNR[(ucCollPosition / 8)];
 106   2                  if (status == MI_COLLERR)
 107   2                  {
 108   3                      for (i=0; i < 5 - (ucCollPosition / 8); i++)
 109   3                      {
 110   4                               ucSNR[i + (ucCollPosition / 8)] = MfComData.MfData[i+1];
 111   4                      }
 112   3                      ucSNR[(ucCollPosition / 8)] |= ucTemp;
 113   3                      ucCollPosition = MfComData.MfData[0];
 114   3              }
 115   2              else if (status == MI_OK)
 116   2              {
 117   3                  for (i=0; i < (MfComData.MfLength / 8); i++)
C51 COMPILER V7.06   ISO14443A                                                             05/01/2009 01:52:11 PAGE 3   

 118   3                  {
 119   4                       ucSNR[4 - i] = MfComData.MfData[MfComData.MfLength/8 - i - 1];
 120   4                  }
 121   3                  ucSNR[(ucCollPosition / 8)] |= ucTemp;
 122   3              }
 123   2          } while (status == MI_COLLERR);
 124   1                              
 125   1                              
 126   1          if (status == MI_OK)
 127   1          {
 128   2               for (i=0; i<4; i++)
 129   2               {   
 130   3                   *(pSnr+i)  = ucSNR[i];
 131   3                   snr_check ^= ucSNR[i];
 132   3               }
 133   2               if (snr_check != ucSNR[i])
 134   2               {   status = MI_COM_ERR;    }
 135   2          }
 136   1          
 137   1          ClearBitMask(RegDecoderControl,0x20);
 138   1          return status;
 139   1      }
 140          
 141          /////////////////////////////////////////////////////////////////////
 142          //选定一张卡
 143          //input:g_cSNR=序列号
 144          /////////////////////////////////////////////////////////////////////
 145          char PcdSelect(unsigned char *pSnr,unsigned char *pSize)
 146          {
 147   1          unsigned char i;
 148   1          char status;
 149   1          unsigned char snr_check = 0;
 150   1          struct TranSciveBuffer MfComData;
 151   1          struct TranSciveBuffer *pi;
 152   1          pi = &MfComData;
 153   1      
 154   1          WriteRawRC(RegChannelRedundancy,0x0F);
 155   1          ClearBitMask(RegControl,0x08);
 156   1          PcdSetTmo(4);
 157   1          
 158   1          MfComData.MfCommand = PCD_TRANSCEIVE;
 159   1          MfComData.MfLength  = 7;
 160   1          MfComData.MfData[0] = PICC_ANTICOLL1;
 161   1          MfComData.MfData[1] = 0x70;
 162   1          for (i=0; i<4; i++)
 163   1          {
 164   2              snr_check ^= *(pSnr+i);
 165   2              MfComData.MfData[i+2] = *(pSnr+i);
 166   2          }
 167   1          MfComData.MfData[6] = snr_check;
 168   1      
 169   1          status = PcdComTransceive(pi);
 170   1          
 171   1          if (status == MI_OK)
 172   1          {
 173   2              if (MfComData.MfLength != 0x8)
 174   2              {   status = MI_BITCOUNTERR;   }
 175   2              else
 176   2              {  *pSize = MfComData.MfData[0];  }
 177   2          }
 178   1      
 179   1          return status;
C51 COMPILER V7.06   ISO14443A                                                             05/01/2009 01:52:11 PAGE 4   

 180   1      }
 181          
 182          
 183          ///////////////////////////////////////////////////////////////
 184          // Key loading into the MF RC500's EEPROM
 185          ///////////////////////////////////////////////////////////////                     
 186          char M500PcdLoadKeyE2(unsigned char key_type,
 187                                 unsigned char sector,
 188                                 unsigned char *uncoded_keys)
 189          {
 190   1          signed char status = MI_OK;
 191   1          unsigned int e2addr = 0x80 + sector * 0x18;
 192   1          unsigned char idata coded_keys[12];
 193   1      
 194   1          if (key_type == PICC_AUTHENT1B)
 195   1          {
 196   2              e2addr += 12;           // key B offset
 197   2          }
 198   1          if ((status = ChangeCodeKey(uncoded_keys,coded_keys)) == MI_OK)
 199   1          {
 200   2              status = PcdWriteE2(e2addr,12,coded_keys);
 201   2          }
 202   1          return status;
 203   1      }
 204          
 205          
 206          /////////////////////////////////////////////////////////////////////
 207          //将Mifare_One卡密钥转换为RC500接收格式
 208          //input: uncoded=6字节未转换的密钥
 209          //output:coded=12字节转换后的密钥
 210          /////////////////////////////////////////////////////////////////////
 211          char ChangeCodeKey(unsigned char *pUncoded,unsigned char *pCoded)
 212          {
 213   1         unsigned char cnt=0;
 214   1         unsigned char ln=0;
 215   1         unsigned char hn=0;
 216   1      
 217   1         for (cnt=0; cnt<6; cnt++)
 218   1         {
 219   2            ln = pUncoded[cnt] & 0x0F;
 220   2            hn = pUncoded[cnt] >> 4;
 221   2            pCoded[cnt*2+1] = (~ln<<4) | ln;
 222   2            pCoded[cnt*2]   = (~hn<<4) | hn;
 223   2         }
 224   1         return MI_OK;
 225   1      }
 226          
 227          /*
 228          ///////////////////////////////////////////////////////////////////////
 229          // Key loading into the MF RC500's EEPROM
 230          // 校验卡密码(E2)
 231          ///////////////////////////////////////////////////////////////////////
 232          char M500PiccAuthE2( unsigned char idata auth_mode,unsigned char idata *snr,      
 233                               unsigned char idata keynr,unsigned char idata block)     
 234                                                        
 235          {
 236              char idata status = MI_OK;
 237              unsigned int e2addr = 0x80 + keynr * 0x18;
 238              if (auth_mode == PICC_AUTHENT1B)
 239              {
 240                  e2addr += 12; 
 241              }
C51 COMPILER V7.06   ISO14443A                                                             05/01/2009 01:52:11 PAGE 5   

 242          
 243                   status=PcdLoadKeyE2(e2addr);
 244              return status;
 245          } 
 246          */                       
 247          
 248          /////////////////////////////////////////////////////////////////////
 249          //将存在RC500的EEPROM中的密钥匙调入RC500的FIFO
 250          //input: startaddr=EEPROM地址
 251          /////////////////////////////////////////////////////////////////////
 252          char PcdLoadKeyE2( unsigned char idata auth_mode,unsigned char idata keynr)
 253          {
 254   1          char status;
 255   1          struct TranSciveBuffer MfComData;
 256   1          struct TranSciveBuffer *pi;
 257   1              unsigned char *e2addrbuf;
 258   1              unsigned int e2addr = 0x80 + keynr * 0x18;
 259   1              e2addrbuf = (unsigned char *)&e2addr;
 260   1              pi = &MfComData;
 261   1          if (auth_mode == PICC_AUTHENT1B)
 262   1          {
 263   2              e2addr += 12; 
 264   2          }
 265   1          
 266   1              memcpy(MfComData.MfData,e2addrbuf,2); 
 267   1          MfComData.MfData[2] = MfComData.MfData[0];      
 268   1          MfComData.MfData[0] = MfComData.MfData[1]; 
 269   1          MfComData.MfData[1] = MfComData.MfData[2];
 270   1      
 271   1          MfComData.MfCommand = PCD_LOADKEYE2;
 272   1          MfComData.MfLength  = 2;
 273   1      //    MfComData.MfData[0] = startaddr & 0xFF;
 274   1      //    MfComData.MfData[1] = (startaddr >> 8) & 0xFF;
 275   1          
 276   1          status = PcdComTransceive(pi);
 277   1          
 278   1          return status;
 279   1      }
 280          
 281          
 282          
 283          /////////////////////////////////////////////////////////////////////
 284          //功能:将已转换格式后的密钥送到RC500的FIFO中
 285          //input:keys=密钥
 286          /////////////////////////////////////////////////////////////////////
 287          char PcdAuthKey(unsigned char *pKeys)
 288          {
 289   1          char status;
 290   1          struct TranSciveBuffer MfComData;
 291   1          struct TranSciveBuffer *pi;
 292   1          pi = &MfComData;
 293   1      
 294   1          PcdSetTmo(4);

⌨️ 快捷键说明

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