#include
#include
#include
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];
Servo servo_4;
char *
card[]={"f070e4ac4","d0b9fb43d1"}; //读卡器读取来的卡号
char *
name[]={"fujiashi","zhengdianxuan"}; //在串口监视器显示出刷卡人昵称
String rc;
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(){
rc= "";
Serial.begin(9600);
SPI.begin();
rfid.init();
Serial.begin(9600);
servo_4.attach(4);
}
void loop(){
if( rfid.isCard() ) {
rc = RFID_readcardnum();
Serial.println(rc);
for (int i = (1); i <= (sizeof(card)/sizeof(card[0])); i = i + (1)) {
if (rc == card[(int)(i - 1)]) {
Serial.println(name[(int)(i - 1)]); //打印昵称
servo_4.write(90); //旋转角度90度
delay(2000); //延迟2秒后返回
servo_4.write(0);
delay(0);
}
}
}
}
实验效果视频:
视频中第一、二张校园卡为指定的校园卡,第三张是无效校园卡
Mixly RFID智能门禁实验效果