|
发表于 2016-1-11 11:23:41
|
显示全部楼层
RC500源码
char M500PiccW40(void)
{
char status = MI_OK;
WriteRawIO(RegBitFraming,0x07); // set TxLastBits to 7
WriteRawIO(RegChannelRedundancy,0x03);
ResetInfo(MInfo);
MSndBuffer[0] = 0x40;
MInfo.nBytesToSend = 1;
status = M500PcdCmd(PCD_TRANSCEIVE,
MSndBuffer,
MRcvBuffer,
&MInfo);
if (status!=MI_OK) // error occured
{
return status;
}
if (MInfo.nBitsReceived != 4||(MRcvBuffer[0]&0x0f)!=0x0a) // 4 bit expected
{
status = MI_BITCOUNTERR;
}
else
{
status = MI_OK;
}
return status;
}
char M500PiccW43(void)
{
char status = MI_OK;
ResetInfo(MInfo);
MSndBuffer[0] = 0x43;
MInfo.nBytesToSend = 1;
status = M500PcdCmd(PCD_TRANSCEIVE,
MSndBuffer,
MRcvBuffer,
&MInfo);
if (status!=MI_OK) // error occured
{
return status;
}
if (MInfo.nBitsReceived != 4||(MRcvBuffer[0]&0x0f)!=0x0a) // 4 bit expected
{
status = MI_BITCOUNTERR;
}
else
{
status = MI_OK;
}
return status;
}
char M500PiccWBlock0(void)
{
// uint8_t buff[]={0x01, 0x23, 0x45, 0x67, 0x00, 0x08, 0x04, 0x00, 0x01, 0x72, 0x92, 0x86, 0x61, 0x66, 0xF2, 0x1D};
// uint8_t buff[]={0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x04, 0x00, 0x01, 0x72, 0x92, 0x86, 0x61, 0x66, 0xF2, 0x1D};
// uint8_t buff[]={0x00, 0x00, 0x00, 0x01, 0x01, 0x08, 0x04, 0x00, 0x46, 0x59, 0x25, 0x58, 0x49, 0x10, 0x23, 0x02, 0xc0, 0x10};
uint8_t buff[]={0x00, 0xdc, 0x44, 0x20, 0xb8, 0x08, 0x04, 0x00, 0x46, 0x59, 0x25, 0x58, 0x49, 0x10, 0x23, 0x02, 0xc0, 0x10};
return M500PiccWrite(0,buff);
}
char M500PiccWrite( unsigned char addr,
unsigned char *_data)
{
char status = MI_OK;
// ************* Cmd Sequence **********************************
ResetInfo(MInfo);
MSndBuffer[0] = PICC_WRITE; // Write command code
MSndBuffer[1] = addr;
MSndBuffer[2] = 0X5F;
MSndBuffer[3] = 0XB1;
MInfo.nBytesToSend = 4;
// MInfo.nBytesToSend = 2;
status = M500PcdCmd(PCD_TRANSCEIVE,
MSndBuffer,
MRcvBuffer,
&MInfo);
if (status != MI_NOTAGERR) // no timeout error
{
if (MInfo.nBitsReceived != 4) // 4 bits are necessary
{
status = MI_BITCOUNTERR;
}
else // 4 bit received
{
MRcvBuffer[0] &= 0x0f; // mask out upper nibble
if ((MRcvBuffer[0] & 0x0a) == 0)
{
status = MI_NOTAUTHERR;
}
else
{
if (MRcvBuffer[0] == 0x0a)
{
status = MI_OK;
}
else
{
status = MI_CODEERR;
}
}
}
}
if ( status == MI_OK)
{
M500PcdSetTmo(3); // long timeout
ResetInfo(MInfo);
memcpy(MSndBuffer,_data,18);
MInfo.nBytesToSend = 18;
// memcpy(MSndBuffer,_data,16);
// MInfo.nBytesToSend = 16;
status = M500PcdCmd(PCD_TRANSCEIVE,
MSndBuffer,
MRcvBuffer,
&MInfo);
if (status & 0x80) // timeout occured
{
status = MI_NOTAGERR;
}
else
{
if (MInfo.nBitsReceived != 4) // 4 bits are necessary
{
status = MI_BITCOUNTERR;
}
else // 4 bit received
{
MRcvBuffer[0] &= 0x0f; // mask out upper nibble
if ((MRcvBuffer[0] & 0x0a) == 0)
{
status = MI_WRITEERR;
}
else
{
if (MRcvBuffer[0] == 0x0a)
{
status = MI_OK;
}
else
{
status = MI_CODEERR;
}
}
}
}
M500PcdSetTmo(1); // short timeout
}
return status;
} |
|