#include <RFID.h>
#include <SPI.h>
RFID rfid(10,5);
unsigned char RC_size;
unsigned char blockAddr; //选择操作的块地址0~63
unsigned char i,tmp;
unsigned char status;
unsigned char str[MAX_LEN];
String RFID_readcardnum() {
rfid.readCardSerial();
String stringserNum=String(rfid.serNum[0], HEX)+String(rfid.serNum[1], HEX)+String(rfid.serNum[2], HEX)+String(rfid.serNum[3], HEX)+String(rfid.serNum[4], HEX);
//选卡,返回卡容量(锁定卡片,防止多次读写)
rfid.selectTag(rfid.serNum);
return stringserNum;
}
//4字节卡序列号,第5字节为校验字节
//新扇区A密码,16个扇区,每个扇区密码6Byte
unsigned char sectorNewKeyA[16][16] = {
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xff,0x07,0x80,0x69, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xff,0x07,0x80,0x69, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},};
unsigned char serNum[5];
//写卡数据
//原扇区A密码,16个扇区,每个扇区密码6Byte
unsigned char sectorKeyA[16][16] = {
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},};
void setup(){
Serial.begin(9600);
SPI.begin();
rfid.init();
Serial.begin(9600);
}
void loop(){
if ( rfid.isCard() ) {
Serial.println(RFID_readcardnum());
}
}