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

RFID编程

开发平台:

C/C++

  1. #include<reg52.h>
  2. #include<rc500.h>
  3. char PcdValue(uchar dd_mode,uchar addr,uchar *value)
  4. {
  5.     char status;
  6.     uchar i;
  7.     idata struct TranSciveBuffer{uchar MfCommand;
  8.                                  uchar MfLength;
  9.                                  uchar MfData[4];
  10.                                 }MfComData;
  11.     struct TranSciveBuffer *pi;
  12.     pi=&MfComData;
  13.     PcdSetTmo(106);
  14.     MfComData.MfCommand=PCD_TRANSCEIVE;
  15.     MfComData.MfLength=2;
  16.     MfComData.MfData[0]=dd_mode;
  17.     MfComData.MfData[1]=addr;
  18.     status=PcdComTransceive(pi);
  19.     if(status!=MI_NOTAGERR)
  20.     {
  21.         if(MfComData.MfLength!=4)
  22.         {
  23.            status=MI_BITCOUNTERR;
  24.         }
  25.         else
  26.         {
  27.            MfComData.MfData[0]&=0x0f;
  28.            switch(MfComData.MfData[0])
  29.            {
  30.               case 0x00:
  31.                  status=MI_NOTAUTHERR;
  32.                  break;
  33.               case 0x0a:
  34.                  status=MI_OK;
  35.                  break;
  36.               case 0x01:
  37.                  status=MI_VALERR;
  38.                  break;
  39.               default:
  40.                  status=MI_CODEERR;
  41.                  break;
  42.            }
  43.         }
  44.      }
  45.      if(status==MI_OK)
  46.      {
  47.         PcdSetTmo(4);
  48.         MfComData.MfCommand=PCD_TRANSCEIVE;
  49.         MfComData.MfLength=4;
  50.         pi=&MfComData;
  51.         for(i=0;i<4;i++)
  52.         {
  53.             MfComData.MfData[i]=*(value+i);
  54.         }
  55.         status=PcdComTransceive(pi);
  56.         if(status==MI_OK||status==MI_NOTAGERR)
  57.         {
  58.            if(MfComData.MfLength!=4)
  59.            {
  60.               status = MI_BITCOUNTERR;
  61.            }
  62.            else
  63.            {
  64.               status=MI_OK;
  65.             }
  66.          }
  67.          else
  68.          {
  69.               status=MI_COM_ERR;
  70.           }
  71.      }
  72.      if(status==MI_OK)
  73.      {
  74.         MfComData.MfCommand=PCD_TRANSCEIVE;
  75.         MfComData.MfLength=2;
  76.         MfComData.MfData[0]=PICC_TRANSFER;
  77.         MfComData.MfData[1]=addr;
  78.         status=PcdComTransceive(pi);
  79.         if(status!=MI_NOTAGERR)
  80.         {
  81.             if(MfComData.MfLength!=4)
  82.             {
  83.                status=MI_BITCOUNTERR;
  84.             }
  85.             else
  86.             {
  87.                MfComData.MfData[0]&=0x0f;
  88.                switch(MfComData.MfData[0])
  89.                {
  90.                   case 0x00:
  91.                      status=MI_NOTAUTHERR;
  92.                      break;
  93.                   case 0x0a:
  94.                      status=MI_OK;
  95.                      break;
  96.                   case 0x01:
  97.                      status=MI_VALERR;
  98.                      break;
  99.                   default:
  100.                      status=MI_CODEERR;
  101.                      break;
  102.                }
  103.             }
  104.         }
  105.      }
  106.    return status;
  107. }