PcdWrite.c
资源名称:RC500.rar [点击查看]
上传用户:hbtfgg
上传日期:2021-12-10
资源大小:16k
文件大小:2k
源码类别:
RFID编程
开发平台:
C/C++
- #include<reg52.h>
- #include<rc500.h>
- extern char PcdWrite(uchar addr,uchar *writedata)
- {
- char status;
- uchar i;
- idata struct TranSciveBuffer{uchar MfCommand;
- uchar MfLength;
- uchar MfData[16];
- }MfComData;
- struct TranSciveBuffer *pi;
- pi=&MfComData;
- PcdSetTmo(4);
- WriteRC(RegChannelRedundancy,0x0F);
- MfComData.MfCommand=PCD_TRANSCEIVE;
- MfComData.MfLength=2;
- MfComData.MfData[0]=PICC_WRITE;
- MfComData.MfData[1]=addr;
- status=PcdComTransceive(pi);
- if(status!=MI_NOTAGERR)
- {
- if(MfComData.MfLength!=4)
- {
- status=MI_BITCOUNTERR;
- }
- else
- {
- MfComData.MfData[0]&=0x0f;
- switch(MfComData.MfData[0])
- {
- case 0x00:
- status=MI_NOTAUTHERR;
- break;
- case 0x0a:
- status=MI_OK;
- break;
- default:
- status=MI_CODEERR;
- break;
- }
- }
- }
- if(status==MI_OK)
- {
- PcdSetTmo(3);
- MfComData.MfCommand=PCD_TRANSCEIVE;
- MfComData.MfLength=16;
- for(i=0;i<16;i++)
- {
- MfComData.MfData[i]=*(writedata+i);
- }
- status=PcdComTransceive(pi);
- if(status!=MI_NOTAGERR)
- {
- MfComData.MfData[0]&=0x0f;
- switch(MfComData.MfData[0])
- {
- case 0x00:
- status=MI_WRITEERR;
- break;
- case 0x0a:
- status=MI_OK;
- break;
- default:
- status=MI_CODEERR;
- break;
- }
- }
- }
- return status;
- }