9.2-230 安裝RFID射頻識(shí)別傳感器庫(kù)_第1頁(yè)
9.2-230 安裝RFID射頻識(shí)別傳感器庫(kù)_第2頁(yè)
9.2-230 安裝RFID射頻識(shí)別傳感器庫(kù)_第3頁(yè)
9.2-230 安裝RFID射頻識(shí)別傳感器庫(kù)_第4頁(yè)
9.2-230 安裝RFID射頻識(shí)別傳感器庫(kù)_第5頁(yè)
已閱讀5頁(yè),還剩21頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

安裝RFID射頻識(shí)別庫(kù)

2硬件接線1安裝MFRC522庫(kù)RFID示例程序解析2目錄PART.1安裝庫(kù)RC522庫(kù)安裝RC522庫(kù)安裝PART.2示例程序解析函數(shù)的理解MFRC522程序主要函數(shù):MFRC522物件.PCD_Init():初始化MFRC522讀卡器模塊MFRC522物件.PICC_IsNewCardPresent():是否感應(yīng)到新的卡片MFRC522物件.PICC_ReadCardSerial():讀取卡片的資料MFRC522物件.PICC_GetType():取得卡片類型MFRC522物件.PICC_GetTypeName():取得卡片類型名稱當(dāng)讀寫(xiě)器讀到卡片的資料之后,UID的長(zhǎng)度和內(nèi)容,可從底下兩個(gè)屬性值取得:MFRC522物件.uid.size:包含UID的長(zhǎng)度MFRC522物件.uid.uidByte:包含UID碼的陣列讀卡操作過(guò)程Mifare的關(guān)鍵詞按感應(yīng)距離分類緊耦合(close-coupled,需要緊貼感測(cè)器)接近式(proximity,10cm以內(nèi))鄰近式(vicinity,50cm以內(nèi))PICC(ProximityICCard)接近式IC卡PCD(ProximityCouplingDevice)接近型耦合器非接觸型IC卡12示例1-Dumplnfo#include<SPI.h>#include<MFRC522.h>constexpruint8_tRST_PIN=9;//Configurable,seetypicalpinlayoutaboveconstexpruint8_tSS_PIN=10;//Configurable,seetypicalpinlayoutaboveMFRC522mfrc522(SS_PIN,RST_PIN);//CreateMFRC522instance示例1-Dumplnfovoidsetup(){ Serial.begin(9600); //InitializeserialcommunicationswiththePC

while(!Serial); //Donothingifnoserialportisopened(addedforArduinosbasedonATMEGA32U4) SPI.begin(); //InitSPIbus mfrc522.PCD_Init(); //InitMFRC522 mfrc522.PCD_DumpVersionToSerial(); //ShowdetailsofPCD-MFRC522CardReaderdetails Serial.println(F("ScanPICCtoseeUID,SAK,type,anddatablocks..."));}14示例1-Dumplnfo voidloop(){ //Lookfornewcards if(!mfrc522.PICC_IsNewCardPresent()){ return; } //Selectoneofthecards if(!mfrc522.PICC_ReadCardSerial()){ return; } //Dumpdebuginfoaboutthecard;PICC_HaltA()isautomaticallycalled mfrc522.PICC_DumpToSerial(&(mfrc522.uid));}15示例1-Dumplnfo串口監(jiān)視器觀察卡內(nèi)容卡內(nèi)塊分布17示例2-ReadNUID18示例2-ReadNUID#include<SPI.h>#include<MFRC522.h>constexpruint8_tRST_PIN=9;//Configurable,seetypicalpinlayoutaboveconstexpruint8_tSS_PIN=10;//Configurable,seetypicalpinlayoutabove

MFRC522rfid(SS_PIN,RST_PIN);//InstanceoftheclassMFRC522::MIFARE_Keykey;//InitarraythatwillstorenewNUIDbytenuidPICC[4];19示例2-ReadNUIDvoidsetup(){Serial.begin(9600);SPI.begin();//InitSPIbusrfid.PCD_Init();//InitMFRC522for(bytei=0;i<6;i++){key.keyByte[i]=0xFF;}Serial.println(F("ThiscodescantheMIFAREClasssicNUID."));Serial.print(F("Usingthefollowingkey:"));printHex(key.keyByte,MFRC522::MF_KEY_SIZE);}20示例2-ReadNUIDvoidloop(){//Lookfornewcardsif(!rfid.PICC_IsNewCardPresent())return;//VerifyiftheNUIDhasbeenreadedif(!rfid.PICC_ReadCardSerial())return;Serial.print(F("PICCtype:"));MFRC522::PICC_TypepiccType=rfid.PICC_GetType(rfid.uid.sak);Serial.println(rfid.PICC_GetTypeName(piccType));//CheckisthePICCofClassicMIFAREtypeif(piccType!=MFRC522::PICC_TYPE_MIFARE_MINI&&piccType!=MFRC522::PICC_TYPE_MIFARE_1K&&piccType!=MFRC522::PICC_TYPE_MIFARE_4K){Serial.println(F("YourtagisnotoftypeMIFAREClassic."));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();Serial.print(F("Indec:"));printDec(rfid.uid.uidByte,rfid.uid.size);Serial.println();}elseSerial.println(F("Cardreadpreviously."));//HaltPICCrfid.PICC_HaltA();//StopencryptiononPCDrfid.PCD_StopCrypto1();}/***HelperroutinetodumpabytearrayashexvaluestoSerial.*/voidprintHex(byte*buffer,bytebufferSize){for(bytei=0;i<bufferSize;i++){Serial.print(buffer[i]<0x10?"0":"");Serial.print(buffer[i],HEX);}}/***HelperroutinetodumpabytearrayasdecvaluestoSerial.*/voidprintDec(byte*buffer,bytebufferSize){for(bytei=0;i<bufferSize;i++){Serial.print(buffer[i]<0x10?"0":"");Serial.print(buffer[i],DEC);}}21示例2-ReadNUID//CheckisthePICCofClassicMIFAREtypeif(piccType!=MFRC522::PICC_TYPE_MIFARE_MINI&&piccType!=MFRC522::PICC_TYPE_MIFARE_1K&&piccType!=MFRC522::PICC_TYPE_MIFARE_4K){Serial.println(F("YourtagisnotoftypeMIFAREClassic."));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();Serial.print(F("Indec:"));printDec(rfid.uid.uidByte,rfid.uid.size);Serial.println();}elseSerial.println(F("Cardreadpreviously."));//HaltPICCrfid.PICC_HaltA();//StopencryptiononPCDrfid.PCD_StopCrypto1();}/***HelperroutinetodumpabytearrayashexvaluestoSerial.*/voidprintHex(byte*buffer,bytebufferSize){for(bytei=0;i<bufferSize;i++){Serial.print(buffer[i]<0x10?"0":"");Serial.print(buffer[i],HEX);}}/***HelperroutinetodumpabytearrayasdecvaluestoSerial.*/voidprintDec(byte*buffer,bytebufferSize){for(bytei=0;i<bufferSize;i++){Serial.print(buffer[i]<0x10?"0":"");Serial.print(buffer[i],DEC);}}22示例2-ReadNUID//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();Serial.print(F("Indec:"));printDec(rfid.uid.uidByte,rfid.uid.size);Serial.println();}elseSerial.println(F("Cardreadpreviously."));//HaltPICCrfid.PICC_HaltA();//StopencryptiononPCDrfid.PCD_StopCrypto1();}/***HelperroutinetodumpabytearrayashexvaluestoSerial.*/voidprintHex(byte*buffer,bytebufferSize){for(bytei=0;i<bufferSize;i++){Serial.print(buffer[i]<0x10?"0":"");Serial.print(buffer[i],HEX);}}/***HelperroutinetodumpabytearrayasdecvaluestoSerial.*/voidprintDec(byte*buffer,bytebufferSize){for(bytei=0;i<bufferSize;i++){Serial.print(buffer[i]<0x10?"0":"");Serial.print(buffer[i],DEC);}}23示例3-ReadNUIDelseSerial.println(F("Cardreadpreviously."));//HaltPICCrfid.PICC_HaltA();//StopencryptiononPCDrfid.PCD_StopCrypto1();}/***HelperroutinetodumpabytearrayashexvaluestoSerial.*/voidprintHex(byte*buffer,bytebufferSize){for(bytei=0;i<bufferSize;i++){S

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論