题目内容
通过Arduinonano、射频模块MFRC522、带I2C总线的LCD1602扩展板、热敏电阻、RGB三色灯、蜂鸣器设计高频读卡器。以下程序实现了自动读卡(MifareS50)功能,读卡成功后在LCD上显示卡号,并将卡号发送到串口上。#include#include#include#includeconstexpruint8_tRST_PIN=9;//Configurable,seetypicalpinlayoutaboveconstexpruint8_tSS_PIN=10;//Configurable,seetypicalpinlayoutaboveMFRC522rfid(SS_PIN,RST_PIN);//InstanceoftheclassLiquidCrystal_I2Clcd(0x27,20,4);bytenuidPICC[4];//InitarraythatwillstorenewNUIDvoidsetup(){Serial.begin(9600);SPI.begin();//InitSPIbusrfid.PCD_Init();//InitMFRC522lcd.init();lcd.backlight();}voidloop(){//Lookfornewcardsif(!rfid.PICC_IsNewCardPresent())return;//VerifyiftheNUIDhasbeenreadedif(!rfid.PICC_ReadCardSerial())return;if(rfid.uid.uidByte[0]!=nuidPICC[0]||rfid.uid.uidByte[1]!=nuidPICC[1]||rfid.uid.uidByte[2]!=nuidPICC[2]||rfid.uid.uidByte[3]!=nuidPICC[3]){Serial.println(F("Anewcardhasbeendetected."));//StoreNUIDintonuidPICCarrayfor(bytei=0;i<4;i++){nuidPICC[i]=rfid.uid.uidByte[i];}Serial.println(F("TheNUIDtagis:"));Serial.print(F("Inhex:"));printHex(rfid.uid.uidByte,rfid.uid.size);Serial.println();}elseSerial.println(F("Cardreadpreviously."));//HaltPICCrfid.PICC_HaltA();//StopencryptiononPCDrfid.PCD_StopCrypto1();}/***/HelperroutinetodumpabytearrayashexvaluestoSerialandLCD.*/voidprintHex(byte*buffer,bytebufferSize){lcd.setCursor(0,0);for(bytei=0;i
查看答案
搜索结果不匹配?点我反馈