RC500RST.C
资源名称:RC500.rar [点击查看]
上传用户:hbtfgg
上传日期:2021-12-10
资源大小:16k
文件大小:2k
源码类别:
RFID编程
开发平台:
C/C++
- #include <reg52.h>
- #include "rc500.h"
- /*****************************************************************************
- * 复位并初始化RC500
- *注意:RC500上电后应延时500ms才能可靠初始化
- ******************************************************************************/
- char PcdReset()
- {
- char status=MI_OK;
- char n=0;
- uint i=0x4000;
- RC500_CE=0;
- RC500_RST=1;
- DelayMs(100);
- RC500_RST=0;
- while(i!=0&&n!=0x3f)
- {
- n=ReadRawRC(RegCommand);
- i--;
- }
- while(i!=0&&n==0x3f)
- {
- n=ReadRawRC(RegCommand);
- i--;
- }
- if(i!=0)
- {
- WriteRawRC(RegPage,0x80);
- n=0x80;
- while((i!=0)&&(n&0x80))
- {
- n=ReadRawRC(RegCommand);
- i--;
- }
- if(i==0||(n&0xff))
- {
- status=MI_RESETERR;
- }
- }
- else
- {
- status=MI_RESETERR;
- }
- if(status==MI_OK)
- {
- WriteRC(RegClockQControl,0x0);
- WriteRC(RegClockQControl,0x40);
- DelayUs(100);
- ClearBitMask(RegClockQControl,0x40);
- WriteRC(RegBitPhase,0xad);
- WriteRC(RegRxThreshold,0xff);
- WriteRC(RegRxControl2,01);
- WriteRC(RegFIFOLevel,0x1a);
- WriteRC(RegTimerControl,0x02);
- WriteRC(RegIRqPinConfig,0x02);
- WriteRC(RegTxControl,0x5b);
- }
- return status;
- }
- /*****************************************************************************
- * 延时
- *****************************************************************************/
- void DelayMS(uchar j)
- {
- uchar i,n;
- for(i=0;i<j;i++)
- { for(n=0;n<230;n++);
- }
- }
- void DelayUs(uchar j)
- {
- uchar i,n;
- n=j/5;
- for(i=0;i<n;i++);
- }