RC 522
#include "main.h"
#include "string.h"
void RC522_Delay(unsigned short int Delay_Time)
{
unsigned short int i, j;
for (i = 200; i > 0; i--)
{
for (j = Delay_Time; j > 0; j--);
}
}
void RC522_IO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RC522_SCK_GPIO_CLK | RC522_MISO_GPIO_CLK | RC522_MOSI_GPIO_CLK
| RC522_NSEL_GPIO_CLK | RC522_RESET_GPIO_CLK
| RC522_IRQ_GPIO_CLK, ENABLE);
/* Configure PD0 and PD2 in output pushpull mode */
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = (RC522_SCK_PIN);
GPIO_Init(RC522_SCK_GPIO_PORT, &GPIO_InitStructure); //sck
GPIO_InitStructure.GPIO_Pin = (RC522_MOSI_PIN); //mosi
GPIO_Init(RC522_MOSI_GPIO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = (RC522_NSEL_PIN); //nsel
GPIO_Init(RC522_NSEL_GPIO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = (RC522_RESET_PIN); //reset
GPIO_Init(RC522_RESET_GPIO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Pin = RC522_MISO_PIN;
GPIO_Init(RC522_MISO_GPIO_PORT, &GPIO_InitStructure); // 配置为输入
GPIO_InitStructure.GPIO_Pin = RC522_IRQ_PIN;
GPIO_Init(RC522_IRQ_GPIO_PORT, &GPIO_InitStructure); // 配置为输入
}
void RC522_IO_Test(void)
{
RC522_SCK_RESET();
RC522_MOSI_RESET();
RC522_NSEL_RESET();
RC522_RESET_RESET();
}
/////////////////////////////////////////////////////////////////////
//功 能:寻卡
//参数说明: req_code[IN]:寻卡方式
// 0x52 = 寻感应区内所有符合14443A标准的卡
// 0x26 = 寻未进入休眠状态的卡
// pTagType[OUT]:卡片类型代码
// 0x4400 = Mifare_UltraLight
// 0x0400 = Mifare_One(S50)
// 0x0200 = Mifare_One(S70)
// 0x0800 = Mifare_Pro(X)
// 0x4403 = Mifare_DESFire
//返 回: 成功返回MI_OK
/////////////////////////////////////////////////////////////////////
unsigned char PcdRequest(unsigned char req_code, unsigned char *pTagType)
{
unsigned char status;
unsigned short int unLen;
unsigned char ucComMF522Buf[MAXRLEN];
ClearBitMask(Status2Reg, 0x08);
WriteRawRC(BitFramingReg, 0x07);
SetBitMask(TxControlReg, 0x03);
ucComMF522Buf[0] = req_code;
status = PcdComMF522(PCD_TRANSCEIVE, ucComMF522Buf, 1, ucComMF522Buf,
&unLen);
if ((status == MI_OK) && (unLen == 0x10))
{
*pTagType = ucComMF522Buf[0];
*(pTagType + 1) = ucComMF522Buf[1];
}
else
{
status = MI_ERR;
}
return status;
}
/////////////////////////////////////////////////////////////////////
//功 能:防冲撞
//参数说明: pSnr[OUT]:卡片序列号,4字节
//返 回: 成功返回MI_OK
/////////////////////////////////////////////////////////////////////
unsigned char PcdAnticoll(unsigned char *pSnr)
{
unsigned char status;
unsigned char i, snr_check = 0;
unsigned short int unLen;
unsigned char ucComMF522Buf[MAXRLEN];
ClearBitMask(Status2Reg, 0x08);
WriteRawRC(BitFramingReg, 0x00);
ClearBitMask(CollReg, 0x80);
ucComMF522Buf[0] = PICC_ANTICOLL1;
ucComMF522Buf[1] = 0x20;
status = PcdComMF522(PCD_TRANSCEIVE, ucComMF522Buf, 2, ucComMF522Buf, &unLen);
if (status == MI_OK)
{
for (i = 0; i < 4; i++)
{
Delay(200);//加入了一个延时
*(pSnr + i) = ucComMF522Buf[i];
snr_check ^= ucComMF522Buf[i];
}
if (snr_check != ucComMF522Buf[i])
{
status = MI_ERR;
}
}
SetBitMask(CollReg, 0x80);
return status;
}
/////////////////////////////////////////////////////////////////////
//功 能:选定卡片
//参数说明: pSnr[IN]:卡片序列号,4字节
//返 回: 成功返回MI_OK
/////////////////////////////////////////////////////////////////////
unsigned char PcdSelect(unsigned char *pSnr)
{
unsigned char status;
unsigned char i;
unsigned short int unLen;
unsigned char ucComMF522Buf[MAXRLEN];
ucComMF522Buf[0] = PICC_ANTICOLL1;
ucComMF522Buf[1] = 0x70;
ucComMF522Buf[6] = 0;
for (i = 0; i < 4; i++)
{
Delay(200);
ucComMF522Buf[i + 2] = *(pSnr + i);
ucComMF522Buf[6] ^= *(pSnr + i);
}
CalulateCRC(ucComMF522Buf, 7, &ucComMF522Buf[7]);
ClearBitMask(Status2Reg, 0x08);
status = PcdComMF522(PCD_TRANSCEIVE, ucComMF522Buf, 9, ucComMF522Buf,
&unLen);
if ((status == MI_OK) && (unLen == 0x18))
{
status = MI_OK;
}
else
{
status = MI_ERR;
}
return status;
}
/////////////////////////////////////////////////////////////////////
//功 能:验证卡片密码
//参数说明: auth_mode[IN]: 密码验证模式
// 0x60 = 验证A密钥
// 0x61 = 验证B密钥
// addr[IN]:块地址
// pKey[IN]:密码
// pSnr[IN]:卡片序列号,4字节
//返 回: 成功返回MI_OK
/////////////////////////////////////////////////////////////////////
unsigned char PcdAuthState(unsigned char auth_mode, unsigned char addr, unsigned char *pKey, unsigned char *pSnr)
{
unsigned char status;
unsigned short int unLen;
unsigned char i, ucComMF522Buf[MAXRLEN];
ucComMF522Buf[0] = auth_mode;
ucComMF522Buf[1] = addr;
for (i = 0; i < 6; i++)
{
Delay(200);
ucComMF522Buf[i + 2] = *(pKey + i);
}
for (i = 0; i < 6; i++)
{
Delay(200);
ucComMF522Buf[i + 8] = *(pSnr + i);
}
status = PcdComMF522(PCD_AUTHENT, ucComMF522Buf, 12, ucComMF522Buf, &unLen);
if ((status != MI_OK) || (!(ReadRawRC(Status2Reg) & 0x08)))
{
status = MI_ERR;
}
return status;
}
/////////////////////////////////////////////////////////////////////
//功 能:读取M1卡一块数据
//参数说明: addr[IN]:块地址
// p [OUT]:读出的数据,16字节
//返 回: 成功返回MI_OK
/////////////////////////////////////////////////////////////////////
unsigned char PcdRead(unsigned char addr, unsigned char *pData)
{
unsigned char status;
unsigned short int unLen;
unsigned char i, ucComMF522Buf[MAXRLEN];
ucComMF522Buf[0] = PICC_READ;
ucComMF522Buf[1] = addr;
CalulateCRC(ucComMF522Buf, 2, &ucComMF522Buf[2]);
status = PcdComMF522(PCD_TRANSCEIVE, ucComMF522Buf, 4, ucComMF522Buf,
&unLen);
if ((status == MI_OK) && (unLen == 0x90))
{
for (i = 0; i < 16; i++)
{
Delay(200);
*(pData + i) = ucComMF522Buf[i];
}
}
else
{
status = MI_ERR;
}
return status;
}
/////////////////////////////////////////////////////////////////////
//功 能:写数据到M1卡一块
//参数说明: addr[IN]:块地址
// p [IN]:写入的数据,16字节
//返 回: 成功返回MI_OK
/////////////////////////////////////////////////////////////////////
unsigned char PcdWrite(unsigned char addr, unsigned char *pData)
{
unsigned char status;
unsigned short int unLen;
unsigned char i, ucComMF522Buf[MAXRLEN];
ucComMF522Buf[0] = PICC_WRITE;
ucComMF522Buf[1] = addr;
CalulateCRC(ucComMF522Buf, 2, &ucComMF522Buf[2]);
status = PcdComMF522(PCD_TRANSCEIVE, ucComMF522Buf, 4, ucComMF522Buf,
&unLen);
if ((status != MI_OK) || (unLen != 4)
|| ((ucComMF522Buf[0] & 0x0F) != 0x0A))
{
status = MI_ERR;
}
if (status == MI_OK)
{
for (i = 0; i < 16; i++)
{
Delay(200);
ucComMF522Buf[i] = *(pData + i);
}
CalulateCRC(ucComMF522Buf, 16, &ucComMF522Buf[16]);
status = PcdComMF522(PCD_TRANSCEIVE, ucComMF522Buf, 18, ucComMF522Buf,
&unLen);
if ((status != MI_OK) || (unLen != 4)
|| ((ucComMF522Buf[0] & 0x0F) != 0x0A))
{
status = MI_ERR;
}
}
return status;
}
/////////////////////////////////////////////////////////////////////
//功 能:扣款和充值
//参数说明: dd_mode[IN]:命令字
// 0xC0 = 扣款
// 0xC1 = 充值
// addr[IN]:钱包地址
// pValue[IN]:4字节增(减)值,低位在前
//返 回: 成功返回MI_OK
/////////////////////////////////////////////////////////////////////
unsigned char PcdValue(unsigned char dd_mode, unsigned char addr, unsigned char *pValue)
{
unsigned char status;
unsigned short int unLen;
unsigned char i, ucComMF522Buf[MAXRLEN];
ucComMF522Buf[0] = dd_mode;
ucComMF522Buf[1] = addr;
CalulateCRC(ucComMF522Buf, 2, &ucComMF522Buf[2]);
status = PcdComMF522(PCD_TRANSCEIVE, ucComMF522Buf, 4, ucComMF522Buf,
&unLen);
if ((status != MI_OK) || (unLen != 4)
|| ((ucComMF522Buf[0] & 0x0F) != 0x0A))
{
status = MI_ERR;
}
if (status == MI_OK)
{
for (i = 0; i < 16; i++)
{
ucComMF522Buf[i] = *(pValue + i);
}
CalulateCRC(ucComMF522Buf, 4, &ucComMF522Buf[4]);
unLen = 0;
status = PcdComMF522(PCD_TRANSCEIVE, ucComMF522Buf, 6, ucComMF522Buf,
&unLen);
if (status != MI_ERR)
{
status = MI_OK;
}
}
if (status == MI_OK)
{
ucComMF522Buf[0] = PICC_TRANSFER;
ucComMF522Buf[1] = addr;
CalulateCRC(ucComMF522Buf, 2, &ucComMF522Buf[2]);
status = PcdComMF522(PCD_TRANSCEIVE, ucComMF522Buf, 4, ucComMF522Buf,
&unLen);
if ((status != MI_OK) || (unLen != 4)
|| ((ucComMF522Buf[0] & 0x0F) != 0x0A))
{
status = MI_ERR;
}
}
return status;
}
/////////////////////////////////////////////////////////////////////
//功 能:备份钱包
//参数说明: sourceaddr[IN]:源地址
// goaladdr[IN]:目标地址
//返 回: 成功返回MI_OK
/////////////////////////////////////////////////////////////////////
unsigned char PcdBakValue(unsigned char sourceaddr, unsigned char goaladdr)
{
unsigned char status;
unsigned short int unLen;
unsigned char ucComMF522Buf[MAXRLEN];
ucComMF522Buf[0] = PICC_RESTORE;
ucComMF522Buf[1] = sourceaddr;
CalulateCRC(ucComMF522Buf, 2, &ucComMF522Buf[2]);
status = PcdComMF522(PCD_TRANSCEIVE, ucComMF522Buf, 4, ucComMF522Buf,
&unLen);
if ((status != MI_OK) || (unLen != 4)
|| ((ucComMF522Buf[0] & 0x0F) != 0x0A))
{
status = MI_ERR;
}
if (status == MI_OK)
{
ucComMF522Buf[0] = 0;
ucComMF522Buf[1] = 0;
ucComMF522Buf[2] = 0;
ucComMF522Buf[3] = 0;
CalulateCRC(ucComMF522Buf, 4, &ucComMF522Buf[4]);
status = PcdComMF522(PCD_TRANSCEIVE, ucComMF522Buf, 6, ucComMF522Buf,
&unLen);
if (status != MI_ERR)
{
status = MI_OK;
}
}
if (status != MI_OK)
{
return MI_ERR;
}
ucComMF522Buf[0] = PICC_TRANSFER;
ucComMF522Buf[1] = goaladdr;
CalulateCRC(ucComMF522Buf, 2, &ucComMF522Buf[2]);
status = PcdComMF522(PCD_TRANSCEIVE, ucComMF522Buf, 4, ucComMF522Buf,
&unLen);
if ((status != MI_OK) || (unLen != 4)
|| ((ucComMF522Buf[0] & 0x0F) != 0x0A))
{
status = MI_ERR;
}
return status;
}
/////////////////////////////////////////////////////////////////////
//功 能:命令卡片进入休眠状态
//返 回: 成功返回MI_OK
/////////////////////////////////////////////////////////////////////
unsigned char PcdHalt(void)
{
//unsigned char status;
unsigned short int unLen;
unsigned char ucComMF522Buf[MAXRLEN];
ucComMF522Buf[0] = PICC_HALT;
ucComMF522Buf[1] = 0;
CalulateCRC(ucComMF522Buf, 2, &ucComMF522Buf[2]);
//status =
PcdComMF522(PCD_TRANSCEIVE, ucComMF522Buf, 4, ucComMF522Buf, &unLen);
return MI_OK;
}
/////////////////////////////////////////////////////////////////////
//用MF522计算CRC16函数
/////////////////////////////////////////////////////////////////////
void CalulateCRC(unsigned char *pIndata, unsigned char len,
unsigned char *pOutData)
{
unsigned char i, n;
ClearBitMask(DivIrqReg, 0x04);
WriteRawRC(CommandReg, PCD_IDLE);
SetBitMask(FIFOLevelReg, 0x80);
for (i = 0; i < len; i++)
{
WriteRawRC(FIFODataReg, *(pIndata + i));
}
WriteRawRC(CommandReg, PCD_CALCCRC);
i = 0xFF;
do
{
n = ReadRawRC(DivIrqReg);
i--;
} while ((i != 0) && !(n & 0x04));
pOutData[0] = ReadRawRC(CRCResultRegL);
pOutData[1] = ReadRawRC(CRCResultRegM);
}
/////////////////////////////////////////////////////////////////////
//功 能:复位RC522
//返 回: 成功返回MI_OK
/////////////////////////////////////////////////////////////////////
unsigned char PcdReset(void)
{
RC522_RESET_SET(); //RST522_1;
RC522_Delay(10); //_NOP();
RC522_RESET_RESET(); //RST522_0;
RC522_Delay(60000); //_NOP();_NOP();
RC522_RESET_SET(); //RST522_1;RST522_1;
RC522_Delay(500); //_NOP();_NOP();
WriteRawRC(CommandReg, PCD_RESETPHASE);
RC522_Delay(2000); //_NOP();_NOP();
WriteRawRC(ModeReg, 0x3D); //?Mifare???,CRC???0x6363
WriteRawRC(TReloadRegL, 30); //?30?????
WriteRawRC(TReloadRegH, 0);
WriteRawRC(TModeReg, 0x8D);
WriteRawRC(TPrescalerReg, 0x3E);
WriteRawRC(TxAutoReg, 0x40);
ClearBitMask(TestPinEnReg, 0x80); //off MX and DTRQ out
WriteRawRC(TxAutoReg, 0x40);
return MI_OK;
}
/////////////////////////////////////////////////////////////////////
//功 能:读RC632寄存器
//参数说明:Address[IN]:寄存器地址
//返 回:读出的值
/////////////////////////////////////////////////////////////////////
unsigned char ReadRawRC(unsigned char Address)
{
unsigned char i, ucAddr;
unsigned char ucResult = 0;
RC522_SCK_RESET(); //SCK522_0;
RC522_NSEL_RESET(); //NSS522_0;
ucAddr = ((Address << 1) & 0x7E) | 0x80;
for (i = 8; i > 0; i--)
{
Delay(200);
if ((ucAddr & 0x80) == 0x80)
{
RC522_MOSI_SET(); //SI522_1;
}
else
{
RC522_MOSI_RESET(); //SI522_0;
}
RC522_SCK_SET(); //SCK522_1;
ucAddr <<= 1;
RC522_SCK_RESET(); //SCK522_0;
}
for (i = 8; i > 0; i--)
{
Delay(200);
RC522_SCK_SET(); //SCK522_1;
ucResult <<= 1;
ucResult |= RC522_MISO_STATUS; //SO522;
RC522_SCK_RESET(); //SCK522_0;
}
RC522_NSEL_SET(); //NSS522_1;
RC522_SCK_SET(); //SCK522_1;
return ucResult;
}
/////////////////////////////////////////////////////////////////////
//功 能:写RC632寄存器
//参数说明:Address[IN]:寄存器地址
// value[IN]:写入的值
/////////////////////////////////////////////////////////////////////
void WriteRawRC(unsigned char Address, unsigned char value)
{
unsigned char i, ucAddr;
RC522_SCK_RESET(); //SCK522_0;
RC522_NSEL_RESET(); //NSS522_0;
ucAddr = ((Address << 1) & 0x7E);
for (i = 8; i > 0; i--)
{
Delay(200);
if ((ucAddr & 0x80) == 0x80)
{
RC522_MOSI_SET(); //SI522_1;
}
else
{
RC522_MOSI_RESET(); //SI522_0;
}
RC522_SCK_SET(); //SCK522_1;
ucAddr <<= 1;
RC522_SCK_RESET(); //SCK522_0;
}
for (i = 8; i > 0; i--)
{
Delay(200);
if ((value & 0x80) == 0x80)
{
RC522_MOSI_SET(); //SI522_1;
}
else
{
RC522_MOSI_RESET(); //SI522_0;
}
RC522_SCK_SET(); //SCK522_1;
value <<= 1;
RC522_SCK_RESET(); //SCK522_0;
}
RC522_NSEL_SET(); //NSS522_1;
RC522_SCK_SET(); //SCK522_1;
}
/////////////////////////////////////////////////////////////////////
//功 能:置RC522寄存器位
//参数说明:reg[IN]:寄存器地址
// mask[IN]:置位值
/////////////////////////////////////////////////////////////////////
void SetBitMask(unsigned char reg, unsigned char mask)
{
unsigned char tmp = 0x0;
tmp = ReadRawRC(reg);
WriteRawRC(reg, tmp | mask); // set bit mask
}
/////////////////////////////////////////////////////////////////////
//功 能:清RC522寄存器位
//参数说明:reg[IN]:寄存器地址
// mask[IN]:清位值
/////////////////////////////////////////////////////////////////////
void ClearBitMask(unsigned char reg, unsigned char mask)
{
unsigned char tmp = 0x0;
tmp = ReadRawRC(reg);
WriteRawRC(reg, tmp & ~mask); // clear bit mask
}
/////////////////////////////////////////////////////////////////////
//功 能:通过RC522和ISO14443卡通讯
//参数说明:Command[IN]:RC522命令字
// pIn [IN]:通过RC522发送到卡片的数据
// InLenByte[IN]:发送数据的字节长度
// pOut [OUT]:接收到的卡片返回数据
// *pOutLenBit[OUT]:返回数据的位长度
/////////////////////////////////////////////////////////////////////
unsigned char PcdComMF522
(
unsigned char Command,
unsigned char *pInData,
unsigned char InLenByte,
unsigned char *pOutData,
unsigned short int *pOutLenBit
)
{
unsigned char status = MI_ERR;
unsigned char irqEn = 0x00;
unsigned char waitFor = 0x00;
unsigned char lastBits;
unsigned char n;
unsigned short int i;
switch (Command)
{
case PCD_AUTHENT:
irqEn = 0x12;
waitFor = 0x10;
break;
case PCD_TRANSCEIVE:
irqEn = 0x77;
waitFor = 0x30;
break;
default:
break;
}
WriteRawRC(ComIEnReg, irqEn | 0x80);
ClearBitMask(ComIrqReg, 0x80);
WriteRawRC(CommandReg, PCD_IDLE);
SetBitMask(FIFOLevelReg, 0x80);
for (i = 0; i < InLenByte; i++)
{
WriteRawRC(FIFODataReg, pInData[i]);
}
WriteRawRC(CommandReg, Command);
if (Command == PCD_TRANSCEIVE)
{
SetBitMask(BitFramingReg, 0x80);
}
i = 800; //600;//????????,??M1???????25ms
do
{
n = ReadRawRC(ComIrqReg);
i--;
} while ((i != 0) && !(n & 0x01) && !(n & waitFor));
ClearBitMask(BitFramingReg, 0x80);
if (i != 0)
{
if (!(ReadRawRC(ErrorReg) & 0x1B))
{
status = MI_OK;
if (n & irqEn & 0x01)
{
status = MI_NOTAGERR;
}
if (Command == PCD_TRANSCEIVE)
{
n = ReadRawRC(FIFOLevelReg);
lastBits = ReadRawRC(ControlReg) & 0x07;
if (lastBits)
{
*pOutLenBit = (n - 1) * 8 + lastBits;
}
else
{
*pOutLenBit = n * 8;
}
if (n == 0)
{
n = 1;
}
if (n > MAXRLEN)
{
n = MAXRLEN;
}
for (i = 0; i < n; i++)
{
pOutData[i] = ReadRawRC(FIFODataReg);
}
}
}
else
{
status = MI_ERR;
}
}
SetBitMask(ControlReg, 0x80); // stop timer now
WriteRawRC(CommandReg, PCD_IDLE);
return status;
}
//开启天线
//每次启动或关闭天险发射之间应至少有1ms的间隔
void PcdAntennaOn(void)
{
unsigned char i;
i = ReadRawRC(TxControlReg);
if (!(i & 0x03))
{
SetBitMask(TxControlReg,0x03);
}
}
//关闭天线
void PcdAntennaOff(void)
{
ClearBitMask(TxControlReg, 0x03);
}
void RC522_Config(unsigned char Card_Type)
{
ClearBitMask(Status2Reg, 0x08);
WriteRawRC(ModeReg, 0x3D); //3F
WriteRawRC(RxSelReg, 0x86); //84
WriteRawRC(RFCfgReg, 0x7F); //4F
WriteRawRC(TReloadRegL, 30); //tmoLength);// TReloadVal = 'h6a =tmoLength(dec)
WriteRawRC(TReloadRegH, 0);
WriteRawRC(TModeReg, 0x8D);
WriteRawRC(TPrescalerReg, 0x3E);
// WriteRawRC(TxAutoReg,0x40);//???
RC522_Delay(5000); //delay_10ms(1);
PcdAntennaOn();
}
void RC522_init(void)
{
RC522_IO_Init();
RC522_IO_Test();
PcdReset();
PcdAntennaOff();
RC522_Delay(2000);
PcdAntennaOn();
}
void Read_RF_id(void)
{
if(T1_Count2 > 100 ) /* 1000 * 1 ms = 1s 时间到 */
{
T1_Count2 = 0;
RF_status=PcdRequest(0x52,RF_CT);//寻卡,输出为卡类型
if(RF_status==MI_OK) //寻卡成功
{
RF_STEP=1;
RF_status = PcdAnticoll(RF_SN); //防冲撞处理,输出卡片序列号,4字节--第0扇区第0块前4个字节是UID(序列号)
}
if(RF_status==MI_OK) //防冲撞成功
{
RF_STEP=2;
RF_status = PcdSelect(RF_SN); //选卡
}
if(RF_status==MI_OK) //选卡成功
{
RF_STEP=3;
RF_status = PcdAuthState(0x60, 5, RF_Card_KEY, RF_SN);//验证卡
}
if(RF_status==MI_OK) //验证卡成功
{
RF_STEP=4;
RF_ADD=RF_SN[0]+RF_SN[1]+RF_SN[2]+RF_SN[3];
RF_SEMI=Read_RF_SEMI(RF_ADD);
}
}
}
//读取序列号
unsigned char Read_RF_SEMI(unsigned int Add)
{
unsigned char SEMI_tmp;
SEMI_tmp=AT24C64_Read_Byte(SYS_ADDR,Add);
return SEMI_tmp;
}
//写入序列号
void Write_RF_SEMI(void)
{
if(usSRegHoldBuf[100]==5)//..等于2的时候写入序列号
{
AT24C64_Write_Byte(SYS_ADDR,usSRegHoldBuf[102],usSRegHoldBuf[101]);
usSRegHoldBuf[100]=0;
usSRegHoldBuf[101]=0;
usSRegHoldBuf[102]=0;
}
}
//检测是不是新卡
void Test_new_RF_Card(void)
{
if(T1S_FLAG)
{
if(RF_SEMI!=RF_SEMI_old)
{
RF_SEMI_old=RF_SEMI;
RF_SEMI_change_flag=1;
}
}
}
|