0.jpg (25.32 KB, 下載次數(shù): 81)
下載附件
2018-5-5 02:06 上傳
RFID實(shí)驗(yàn)源程序如下:
- /******************************************************************************
- ----------------本例程僅供學(xué)習(xí)使用,未經(jīng)作者允許,不得用于其他用途。-----------
- ------------------------版權(quán)所有,仿冒必究!-----------------------------------
- ----------------1.開發(fā)環(huán)境:Arduino IDE-----------------------------------------
- ----------------2.測(cè)試使用開發(fā)板型號(hào):Arduino Leonardo or Arduino UNO R3-------
- ----------------3.單片機(jī)使用晶振:16M------------------------------------------
- ----------------5.作者:神秘藏寶室---------------------------------------------
- ******************************************************************************/
- #include "RC522.h"
- #include <SPI.h>
- #define Relay 2
- //4 bytes Serial number of card, the 5 bytes is verfiy bytes
- unsigned char serNum[5];
- void setup()
- {
- Serial.begin(9600);
- Serial.print("Ilovemcu.taobao.com");
- pinMode(Relay,OUTPUT);
- SPI.begin();
- pinMode(chipSelectPin,OUTPUT); // Set digital pin 10 as OUTPUT to connect it to the RFID /ENABLE pin
- digitalWrite(chipSelectPin, LOW); // Activate the RFID reader
- pinMode(NRSTPD,OUTPUT); // Set digital Reset , Not Reset and Power-down
-
- MFRC522_Init(); //初始化RFID
- }
- void loop()
- {
- unsigned char status;
- unsigned char str[MAX_LEN];
-
- // Search card, return card types
- status = MFRC522_Request(PICC_REQIDL, str);
- if (status == MI_OK) //讀取到ID卡時(shí)候
- {
- // Show card type
- //ShowCardType(str);
-
- //Prevent conflict, return the 4 bytes Serial number of the card
- status = MFRC522_Anticoll(str);
-
- // str[0..3]: serial number of the card
- // str[4]: XOR checksum of the SN.
- if (status == MI_OK)
- {
- memcpy(serNum, str, 5);
- Serial.print("ID:");
- ShowCardID(serNum);
-
- // Check people associated with card ID
- unsigned char* id = serNum;
- if( id[0]==0xed && id[1]==0x34 && id[2]==0xfa && id[3]==0x95 )
- {
- digitalWrite(Relay,HIGH); //打開繼電器
- Serial.println("The Host 1!");
- }
- else if(id[0]==0x4C && id[1]==0xB3 && id[2]==0x74 && id[3]==0x19)
- {
- digitalWrite(Relay,LOW); //繼電器
- Serial.println("The Host 2!");
- }
- else
- {
- Serial.println("Stranger!");
- }
-
- }
-
- }
-
- MFRC522_Halt(); //command the card into sleep mode
- delay(100);
- }
復(fù)制代碼
所有資料51hei提供下載:
lesson38.rar
(6.67 KB, 下載次數(shù): 82)
2018-5-4 14:22 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|