PcdRestore.c
上传用户:hbtfgg
上传日期:2021-12-10
资源大小:16k
文件大小:2k
源码类别:

RFID编程

开发平台:

C/C++

  1. #include<reg52.h>
  2. #include<rc500.h>
  3. char PcdRestore(uchar addr)
  4. {
  5.     char status;
  6.     idata struct TranSciveBuffer{uchar MfCommand;
  7.                                  uchar MfLength;
  8.                                  uchar MfData[4];
  9.                                 }MfComData;
  10.     struct TranSciveBuffer *pi;
  11.     pi=&MfComData;
  12.     PcdSetTmo(4);
  13.     MfComData.MfCommand=PCD_TRANSCEIVE;
  14.     MfComData.MfLength=2;
  15.     MfComData.MfData[0]=PICC_RESTORE;
  16.     MfComData.MfData[1]=addr;
  17.     status=PcdComTransceive(pi);
  18.     if(status!=MI_NOTAGERR)
  19.     {
  20.         if(MfComData.MfLength!=4)
  21.         {
  22.            status=MI_BITCOUNTERR;
  23.         }
  24.         else
  25.         {
  26.            MfComData.MfData[0]&=0x0f;
  27.            switch(MfComData.MfData[0])
  28.            {
  29.               case 0x00:
  30.                  status=MI_NOTAUTHERR;
  31.                  break;
  32.               case 0x0a:
  33.                  status=MI_OK;
  34.                  break;
  35.               case 0x01:
  36.                  status=MI_VALERR;
  37.                  break;
  38.               default:
  39.                  status=MI_CODEERR;
  40.                  break;
  41.            }
  42.         }
  43.      }
  44.      if(status==MI_OK)
  45.      {
  46.         PcdSetTmo(4);
  47.         MfComData.MfCommand=PCD_TRANSCEIVE;
  48.         MfComData.MfLength=4;
  49.         MfComData.MfData[0]=0;
  50.         MfComData.MfData[1]=0;
  51.         MfComData.MfData[2]=0;
  52.         MfComData.MfData[3]=0;
  53.         status=PcdComTransceive(pi);
  54.         if(status==MI_NOTAGERR)
  55.         {
  56.             status=MI_OK;
  57.         }
  58.      }
  59.      return status;
  60. }