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

RFID编程

开发平台:

C/C++

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