找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 7293|回復(fù): 2
收起左側(cè)

Arduino RC522 RFID庫文件源碼資料

[復(fù)制鏈接]
ID:322058 發(fā)表于 2018-5-4 14:23 | 顯示全部樓層 |閱讀模式
0.jpg
RFID實(shí)驗(yàn)源程序如下:
  1. /******************************************************************************
  2. ----------------本例程僅供學(xué)習(xí)使用,未經(jīng)作者允許,不得用于其他用途。-----------
  3. ------------------------版權(quán)所有,仿冒必究!-----------------------------------
  4. ----------------1.開發(fā)環(huán)境:Arduino IDE-----------------------------------------
  5. ----------------2.測試使用開發(fā)板型號:Arduino Leonardo or Arduino UNO R3-------
  6. ----------------3.單片機(jī)使用晶振:16M------------------------------------------
  7. ----------------5.作者:神秘藏寶室---------------------------------------------
  8. ******************************************************************************/
  9. #include "RC522.h"
  10. #include <SPI.h>

  11. #define Relay 2

  12. //4 bytes Serial number of card, the 5 bytes is verfiy bytes
  13. unsigned char serNum[5];


  14. void setup()
  15. {
  16.     Serial.begin(9600);
  17.     Serial.print("Ilovemcu.taobao.com");
  18.     pinMode(Relay,OUTPUT);
  19.     SPI.begin();   
  20.     pinMode(chipSelectPin,OUTPUT); // Set digital pin 10 as OUTPUT to connect it to the RFID /ENABLE pin
  21.     digitalWrite(chipSelectPin, LOW); // Activate the RFID reader
  22.     pinMode(NRSTPD,OUTPUT); // Set digital Reset , Not Reset and Power-down
  23.    
  24.     MFRC522_Init();                                                //初始化RFID
  25. }


  26. void loop()
  27. {
  28.     unsigned char status;
  29.     unsigned char str[MAX_LEN];
  30.    
  31.     // Search card, return card types
  32.     status = MFRC522_Request(PICC_REQIDL, str);
  33.     if (status == MI_OK)                        //讀取到ID卡時(shí)候
  34.     {   
  35.                 // Show card type
  36.                 //ShowCardType(str);
  37.    
  38.                 //Prevent conflict, return the 4 bytes Serial number of the card
  39.                 status = MFRC522_Anticoll(str);
  40.    
  41.                 // str[0..3]: serial number of the card
  42.                 // str[4]: XOR checksum of the SN.
  43.                 if (status == MI_OK)
  44.                 {
  45.                         memcpy(serNum, str, 5);
  46.                         Serial.print("ID:");
  47.                         ShowCardID(serNum);
  48.    
  49.                         // Check people associated with card ID
  50.                         unsigned char* id = serNum;
  51.                         if( id[0]==0xed && id[1]==0x34 && id[2]==0xfa && id[3]==0x95 )
  52.                         {
  53.                                 digitalWrite(Relay,HIGH);                //打開繼電器
  54.                                 Serial.println("The Host 1!");
  55.                         }
  56.                         else if(id[0]==0x4C && id[1]==0xB3 && id[2]==0x74 && id[3]==0x19)
  57.                         {
  58.                                 digitalWrite(Relay,LOW);                //繼電器
  59.                                 Serial.println("The Host 2!");
  60.                         }
  61.                         else
  62.                         {
  63.                                 Serial.println("Stranger!");
  64.                         }
  65.                         
  66.                 }
  67.                
  68.     }
  69.    
  70.     MFRC522_Halt(); //command the card into sleep mode
  71.     delay(100);
  72. }
復(fù)制代碼

所有資料51hei提供下載:
lesson38.rar (6.67 KB, 下載次數(shù): 82)


回復(fù)

使用道具 舉報(bào)

ID:341806 發(fā)表于 2018-5-30 23:27 | 顯示全部樓層
那個(gè),我想問下為什么接入繼電器的時(shí)候處于高電平狀態(tài)?
回復(fù)

使用道具 舉報(bào)

ID:986646 發(fā)表于 2021-12-1 08:26 來自手機(jī) | 顯示全部樓層
請問有RFID頭文件嗎
回復(fù)

使用道具 舉報(bào)

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表