if (status != MI_NOTAGERR) //识别应答
{
if (MInfo.nBitsReceived != 4)
{
status = MI_BITCOUNTERR;
}
else
{
SerBuffer[0] &= 0x0f;
switch(SerBuffer[0])
{
case 0x00:
status = MI_NOTAUTHERR;
break;
case 0x0a:
status = MI_OK;
break;
case 0x01:
status = MI_VALERR;
break;
default:
status = MI_CODEERR;
break;
}
}
}
if ( status == MI_OK)
{
M500PcdSetTmo(3);
ResetInfo(MInfo);
memcpy(SerBuffer,value,4);
MInfo.nBytesToSend = 4;
status = M500PcdCmd(PCD_TRANSCEIVE,
SerBuffer,
&MInfo);//发送数据(第2次发送)
if (status == MI_OK) //识别应答
{
if (MInfo.nBitsReceived != 4)
{
status = MI_BITCOUNTERR;
}
else
{
SerBuffer[0] &= 0x0f;
switch(SerBuffer[0])
{
case 0x00:
status = MI_NOTAUTHERR;
break;
case 0x01:
status = MI_VALERR;
break;
default:
status = MI_CODEERR;
break;
}
}
}
else
{
if (status == MI_NOTAGERR )
status = MI_OK;
}
}
/******************以下代码起什么作用************************/
if (status == MI_OK)
{
ResetInfo(MInfo);
SerBuffer[0] = PICC_TRANSFER;
SerBuffer[1] = trans_addr; //再次传送块号???
MInfo.nBytesToSend = 2;
status = M500PcdCmd(PCD_TRANSCEIVE,
SerBuffer,
&MInfo);//(第3次发送)
if (status != MI_NOTAGERR)
{
if (MInfo.nBitsReceived != 4)
{
status = MI_BITCOUNTERR;
}
else
{
SerBuffer[0] &= 0x0f;
switch(SerBuffer[0])
{
case 0x00:
status = MI_NOTAUTHERR;
break;
case 0x0a:
status = MI_OK;
break;
case 0x01:
status = MI_VALERR;
break;
default:
status = MI_CODEERR;
break;
}
}
}
}
return status;
}
// Value format operations for Mifare Standard card ICs(调试OK)
///////////////////////////////////////////////////////////////////////
//说明:上层函数调用该函数时对addr和trans_addr 传递的值是一样的 1~63
// 加或减值命令 块地址 4byte 数据 块地址
char M500PiccValue(unsigned char dd_mode,unsigned char addr,unsigned char *value,unsigned char trans_addr)
{
char status = MI_OK;
M500PcdSetTmo(1); //设置时间
ResetInfo(MInfo); //控制块
SerBuffer[0] = dd_mode;
SerBuffer[1] = addr;
MInfo.nBytesToSend = 2;
status = M500PcdCmd(PCD_TRANSCEIVE,
SerBuffer,
&MInfo); //发送命令和块号(第1次发送)
if (status != MI_NOTAGERR) //识别应答
{
if (MInfo.nBitsReceived != 4)
{
status = MI_BITCOUNTERR;
}
else
{
SerBuffer[0] &= 0x0f;
switch(SerBuffer[0])
{
case 0x00:
status = MI_NOTAUTHERR;
break;
case 0x0a:
status = MI_OK;
break;
case 0x01:
status = MI_VALERR;
break;
default:
status = MI_CODEERR;
break;
}
}
}
if ( status == MI_OK)
{
M500PcdSetTmo(3);
ResetInfo(MInfo);
memcpy(SerBuffer,value,4);
MInfo.nBytesToSend = 4;
status = M500PcdCmd(PCD_TRANSCEIVE,
SerBuffer,
&MInfo);//发送数据(第2次发送)
if (status == MI_OK) //识别应答
{
if (MInfo.nBitsReceived != 4)
{
status = MI_BITCOUNTERR;
}
else
{
SerBuffer[0] &= 0x0f;
switch(SerBuffer[0])
{
case 0x00:
status = MI_NOTAUTHERR;
break;
case 0x01:
status = MI_VALERR;
break;
default:
status = MI_CODEERR;
break;
}
}
}
else
{
if (status == MI_NOTAGERR )
status = MI_OK;
}
}
/******************以下代码起什么作用************************/
if (status == MI_OK)
{
ResetInfo(MInfo);
SerBuffer[0] = PICC_TRANSFER;
SerBuffer[1] = trans_addr; //再次传送块号???
MInfo.nBytesToSend = 2;
status = M500PcdCmd(PCD_TRANSCEIVE,
SerBuffer,
&MInfo);//(第3次发送)
if (status != MI_NOTAGERR)
{
if (MInfo.nBitsReceived != 4)
{
status = MI_BITCOUNTERR;
}
else
{
SerBuffer[0] &= 0x0f;
switch(SerBuffer[0])
{
case 0x00:
status = MI_NOTAUTHERR;
break;
case 0x0a:
status = MI_OK;
break;
case 0x01:
status = MI_VALERR;
break;
default:
status = MI_CODEERR;
break;
}
}
}
}
return status;
}
///////////////////////////////////////////////////////////////////////
一周热门 更多>