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

RFID编程

开发平台:

C/C++

  1. #include <reg52.h>
  2. #include "rc500.h"
  3. char PcdAuthState(uchar auth_mode,uchar block,uchar *snr)
  4. {
  5.     char status=MI_OK;
  6.     uchar i;
  7.     idata struct TranSciveBuffer{uchar MfCommand;
  8.                                  uchar MfLength;
  9.                                  uchar MfData[6];
  10.                                 }MfComData;
  11.     struct TranSciveBuffer *pi;
  12.     pi=&MfComData;
  13.     WriteRC(RegChannelRedundancy,0x07);
  14.     if(status==MI_OK)
  15.     {
  16.         PcdSetTmo(106);
  17.         MfComData.MfCommand=PCD_AUTHENT1;
  18.         MfComData.MfLength=6;
  19.         MfComData.MfData[0]=auth_mode;
  20.         MfComData.MfData[1]=block;
  21.         for(i=0;i<4;i++)
  22.         {
  23.       MfComData.MfData[i+2]=*(snr+i);
  24.         }
  25.         if((status=PcdComTransceive(pi))==MI_OK)
  26.         {
  27.             if (ReadRC(RegSecondaryStatus)&0x07) 
  28.             {
  29.                 status = MI_BITCOUNTERR;
  30.             }
  31.             else
  32.             {
  33.                 MfComData.MfCommand=PCD_AUTHENT2;
  34.                 MfComData.MfLength=0;
  35.                 if((status=PcdComTransceive(pi))==MI_OK)
  36.                 {
  37.                     if(ReadRC(RegControl)&0x08)
  38.                         status=MI_OK;
  39.                     else
  40.                         status=MI_AUTHERR;
  41.                 }
  42.              }
  43.          }
  44.    }
  45.    return status;
  46. }