📄 mffc632.c
字号:
while(collionflag);
return TI_OK;
}
//------------------------------------------------------------------------------------------------------
//ISO15693_Inventory_16
//------------------------------------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////////////////
char ISO15693_Inventory_16 ( unsigned char *cmd,
unsigned char cmdlen,
unsigned char *rcv)
{
unsigned char idata TimerReload, status, cnt,err, ts,col, rcvLen = 1;
// bit flag;//use to check the existing of the tag in the RFfield
unsigned char regdatalength;
TimerReload = 0x1F;
// flag = 0;
status = TI_OK;
RegChannelRedundancy = RegChannelRedundancy | 0x04; //txcrc enable
RegTimerReload = TimerReload;
RegTimerControl = 0x02;
RegCoderControl = RegCoderControl & (~0x80);
RegInterruptRq = 0x3F;
RegControl=RegControl | 0x01;
RegCommand = 0x00;
for (ts = 0; ts < cmdlen; ts++)
{
RegFIFOData = cmd[ts];
}
RegCommand = PCD_TRANSCEIVE;
MRC500_CNT =0x00;
while ((!(RegInterruptRq & 0x10)) && (MRC500_CNT < 30000) ) {MRC500_CNT += 1;}
if(MRC500_CNT > 20000) // access mrc500 timeout
{
RegCommand=0x00; //PCD_IDLE;
status= TI_ACCESSTIMEOUT;
MRC500_CNT =0x00;
return status;
}
RegChannelRedundancy = RegChannelRedundancy &(~0x04); //crc
RegTxControl = RegTxControl | 0x10; //100 module
RegCoderControl = RegCoderControl | 0x80; // one pusle
for (ts=0; ts<16; ts++)
{
status = TI_OK;
RegInterruptRq = 0x3F;
// WDTD=0x87;
// WDTC=0x1F;
while (!(RegInterruptRq & 0x28 ));
if (RegInterruptRq & 0x20)
{
status = I2_NO_TAG;
}
else
{
if(RegInterruptRq & 0x08)
{
err = RegErrorFlag;
if (err & 0x08)
{
status = I2_CRCERR;
}
else if (err & 0x01)
{
status = I2_COLLERR;
col = RegCollPos;
}
else if (err & 0x04)
{
status = I2_FRAMINGERR;
}
}
}
/*
if (RegInterruptRq & 0x20)
{
// LED_G = ON;
status = I2_NO_TAG;
}
else
{
if(RegInterruptRq & 0x08)
{
err = RegErrorFlag;
// if (err & 0x08) status = I2_CRCERR;
if (err & 0x01)
{
status = I2_COLLERR;
col = RegCollPos;
}
// else if (err & 0x04) status = I2_FRAMINGERR;
}
}
*/
if ((status == TI_OK || status == I2_COLLERR))
{
regdatalength = RegFIFOLength;
if ( status == TI_OK )
{
rcv[0] = regdatalength;
for(cnt=1;cnt<=regdatalength;cnt++) rcv[cnt] = RegFIFOData;
collionflag =0;
break;
// TxOut(regdatalength,0,txbuffer);
// delay_1ms(2);
// flag = 1;
//if there is a tag in the magnetic field,then the tag will response 10 byte data.
}
else
{
// LED_G = ON;
// buz++; //count the times of collion.
collionflag =1;
rcv[rcvLen] = col;
for(cnt = rcvLen+1;cnt < regdatalength+rcvLen+1;cnt++) rcv[cnt] = RegFIFOData;
rcvLen += regdatalength+1;
break;
// delay_1ms(3);
//if there is a collion,the tag will response 13 byte data in every collion.so in the inventory command,the
//next collionseat must add 13.
}
}
if (ts < 15)
{
RegControl = RegControl | 0x01;
RegCommand = PCD_TRANSCEIVE;
delay_1ms(3);
}
}
RegCoderControl = RegCoderControl & (~0x80);
RegTxControl = RegTxControl & (~0x10);
// rcv[0] = buz;
/* if((flag == 0)&&(Firstcollionflag == 1)) //in the first inventory,if there is not a tag,then we will return the I2_NO_TAG.
{
ReturnStatus(inf_nCard);
}
*/
return status;
}
/////////////////////////////////////////////////////////////////////
// ISO15693 Get System Information
/////////////////////////////////////////////////////////////////////
char ISO15693_Get_System_Information (unsigned char flags,
unsigned char *uid,
unsigned char *resp)
{
unsigned char idata txdatalength=0, status;
unsigned char idata txbuffer[10];
txbuffer[0] = flags | 0x02;
txbuffer[1] = ISO15693_GET_SYSTEM_INFO;
if ((flags & 0x20) && !(flags & 0x10)) // flags & 0x20 - Adresflag request flags &
{
for(txdatalength=0;txdatalength<8;txdatalength++)
{
txbuffer[txdatalength+2] = *uid;
uid++;
}
txdatalength = 10;
}
else
txdatalength = 2;
status = ISO15693_Transceive (txbuffer,txdatalength,resp);
if (status == TI_OK)
{
if(resp[0] == 0x0F)
status = TI_NO_ERR;
else
status = TI_Revdata_Err;
}
return(status);
}
/////////////////////////////////////////////////////////////////////
// 15693 READ
/////////////////////////////////////////////////////////////////////
char ISO15693_Read_sm (unsigned char flags,
unsigned char *uid,
unsigned char blnr,
unsigned char nbl,
unsigned char *resp)
{
unsigned char idata txdatalength, status;
unsigned char idata txbuffer[12];
if(nbl)
{
nbl--;
}
txbuffer[0] = flags| 0x02;
if (nbl)
txbuffer[1] = ISO15693_READ_MULTIPLE_BLOCKS;
else
txbuffer[1] = ISO15693_READ_SINGLE_BLOCK;
if ((flags & 0x20) && !(flags & 0x10)) // flags & 0x20 - Addressflag
// request flags & 0x10 - Selectflag request
{
for(txdatalength=0;txdatalength<8;txdatalength++)
{
txbuffer[txdatalength+2] = *uid;
uid++;
}
txdatalength = 10;
}
else
txdatalength = 2;
txbuffer[txdatalength] = blnr;
if (nbl)
{
txdatalength++;
txbuffer[txdatalength] = nbl;
}
txdatalength += 1;
status = ISO15693_Transceive(txbuffer, txdatalength, resp);
if (status == TI_OK)
{
if(resp[0] >= 5) status = TI_NO_ERR;
else
{
// if((resp[1] == 1) && (resp[2] == 0x12)) status = TI_Blocklocked;
if((resp[1] == 1) && (resp[2] == 0x10)) status = TI_Block_notexist;
else if((resp[1] == 1) && (resp[2] == 0x02)) status = TI_Commandformat_err;
// else if((resp[1] == 1) && (resp[2] == 0x03)) status = TI_Option_unsurport;
else if((resp[1] == 1) && (resp[2] == 0x0f)) status = TI_Unkown_err;
else if((resp[1] == 1) && (resp[2] == 0x01)) status = TI_Command_unsurport;
else status = TI_Revdata_Err;
}
}
return status;
}
/////////////////////////////////////////////////////////////////////
// ISO15693 Write Single / Multiple Block(s)
/////////////////////////////////////////////////////////////////////
char ISO15693_Write_sm (unsigned char flags,
unsigned char *uid,
unsigned char blnr,
unsigned char nbl,
unsigned char *_data,
unsigned char *resp)
{
unsigned char idata status;
unsigned char idata txdatalength,cnt;
unsigned char idata txbuffer[78];
if(nbl)
{
nbl--;
}
txbuffer[0] = flags | 0x02;
if (nbl)
txbuffer[1] = ISO15693_WRITE_MULTIPLE_BLOCKS;
else
txbuffer[1] = ISO15693_WRITE_SINGLE_BLOCK;
if ((flags & 0x20) && !(flags & 0x10)) // flags & 0x20 - Addressflag
// request flags & 0x10 - Selectflag request
{
for(cnt=0;cnt<8;cnt++)
{
txbuffer[2+cnt] = *uid;
uid++;
}
txdatalength = 10;
}
else
txdatalength = 2;
txbuffer[txdatalength] = blnr;
txdatalength++;
if (nbl)
{
txbuffer[txdatalength] = nbl;
txdatalength++;
for(cnt=0;cnt<4*nbl;cnt++)
{
txbuffer[txdatalength+cnt] = *_data;
_data++;
}
txdatalength += 4*nbl;
}
else
{
for(cnt=0;cnt<4;cnt++)
{
txbuffer[txdatalength+cnt] = *_data;
_data++;
}
txdatalength += 4;
}
status = ISO15693_Transceive(txbuffer, txdatalength, resp);
if (status == TI_OK)
{
if((resp[0] == 1) && (resp[1] == 0)) status = TI_NO_ERR;
else
{
if((resp[1] == 1) && (resp[2] == 0x12)) status = TI_Blocklocked;
else if((resp[1] == 1) && (resp[2] == 0x01)) status = TI_Command_unsurport;
else if((resp[1] == 1) && (resp[2] == 0x02)) status = TI_Commandformat_err;
else if((resp[1] == 1) && (resp[2] == 0x03)) status = TI_Option_unsurport;
else if((resp[1] == 1) && (resp[2] == 0x0f)) status = TI_Unkown_err;
else if((resp[1] == 1) && (resp[2] == 0x10)) status = TI_Block_notexist;
else status = TI_Revdata_Err;
}
}
return status;
}
/////////////////////////////////////////////////////////////////////
// ISO15693 Lock Block
/////////////////////////////////////////////////////////////////////
char ISO15693_Lock_Block (unsigned char flags,
unsigned char *uid,
unsigned char blnr,
unsigned char *resp)
{
unsigned char idata txdatalength, status;
unsigned char idata txbuffer[11];
txbuffer[0] = flags | 0x02;
txbuffer[1]= ISO15693_LOCK_BLOCK;
if ((flags & 0x20) && !(flags & 0x10)) // flags & 0x20 - Addressflag
// request flags & 0x10 - Selectflag request
{
for(txdatalength=0;txdatalength<8;txdatalength++)
{
txbuffer[txdatalength+2] = *uid;
uid++;
}
txdatalength = 10;
}
else
txdatalength = 2;
txbuffer[txdatalength] = blnr;
txdatalength += 1;
status = ISO15693_Transceive(txbuffer, txdatalength, resp);
if (status == TI_OK)
{
if((resp[0] == 1) && (resp[1] == 0)) status = TI_NO_ERR;
else
{
if((resp[1] == 1) && (resp[2] == 0x11)) status = TI_Blocklocked;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -