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

RFID编程

开发平台:

C/C++

  1. #include <reg52.h>
  2. #include "rc500.h"
  3. /*****************************************************************************
  4. *          复位并初始化RC500
  5. *注意:RC500上电后应延时500ms才能可靠初始化
  6. ******************************************************************************/
  7. char PcdReset()
  8. {
  9.    char status=MI_OK;
  10.    char n=0;
  11.    uint i=0x4000;
  12.    RC500_CE=0;
  13.    RC500_RST=1;
  14.    DelayMs(100);
  15.    RC500_RST=0;
  16.    while(i!=0&&n!=0x3f)
  17.    {
  18.       n=ReadRawRC(RegCommand);
  19.       i--;
  20.    }
  21.    while(i!=0&&n==0x3f)
  22.    {
  23.       n=ReadRawRC(RegCommand);
  24.       i--;
  25.    }
  26.    if(i!=0)
  27.    {
  28.       WriteRawRC(RegPage,0x80);
  29.       n=0x80;
  30.       while((i!=0)&&(n&0x80))
  31.       {
  32.           n=ReadRawRC(RegCommand);
  33.           i--;
  34.       }
  35.       if(i==0||(n&0xff))
  36.       {
  37.           status=MI_RESETERR;
  38.       }
  39.    }
  40.    else
  41.    {
  42.        status=MI_RESETERR;
  43.    }
  44.    if(status==MI_OK)
  45.    {
  46.      WriteRC(RegClockQControl,0x0);
  47.      WriteRC(RegClockQControl,0x40);
  48.      DelayUs(100);
  49.      ClearBitMask(RegClockQControl,0x40);
  50.      WriteRC(RegBitPhase,0xad);
  51.      WriteRC(RegRxThreshold,0xff);
  52.      WriteRC(RegRxControl2,01);
  53.      WriteRC(RegFIFOLevel,0x1a);
  54.      WriteRC(RegTimerControl,0x02);
  55.      WriteRC(RegIRqPinConfig,0x02);
  56.      WriteRC(RegTxControl,0x5b);
  57.    }
  58.    return status;
  59. }
  60. /*****************************************************************************
  61. *         延时
  62. *****************************************************************************/
  63. void DelayMS(uchar j)
  64. {
  65.    uchar i,n;
  66.    for(i=0;i<j;i++)
  67.    {   for(n=0;n<230;n++);
  68.    }
  69. }
  70. void DelayUs(uchar j)
  71. {
  72.    uchar i,n;
  73.    n=j/5;
  74.    for(i=0;i<n;i++);
  75. }