[Arduino] 驱动RC522 读取 UID例程
---------------------------------
Freaduino mega 2560
rc522 & arduino lib 下载地址: https://github.com/miguelbalboa/rfid
----------------------------------
现象:
-------------------------------------------codeStart------------------------------
1 /************************************************ 2 *@: main.h 3 *@: rc522 Module 4 *@: Hmily 5 *@: 2014.10.31 15:44:58 Version 1.0 6 ************************************************/ 7 8 //***************************************************************************************** 9 //@:Header files included 10 //***************************************************************************************** 11 #if defined(ARDUINO) && ARDUINO >= 100 12 #include "Arduino.h" 13 #else 14 #include "WProgram.h" 15 #endif 16 #include <SPI.h> 17 #include <MFRC522.h> 18 19 #ifndef __MAIN_H__ 20 #define __MAIN_H__ 21 22 // board type 23 #define BOARD_TYPE_ARDUINO_NANO 0x01 24 #define BOARD_TYPE_ARDUINO_MEGA 0x02 25 #define BOARD_TYPE_ARDUINO_MEGA_2560 BOARD_TYPE_ARDUINO_MEGA 26 27 #define BOARD_TYPE BOARD_TYPE_ARDUINO_MEGA 28 #define DEBUG_MODE 1 29 30 // type definition 31 #define uint_8 unsigned char 32 #define sint_8 signed char 33 #define uint_16 unsigned short int 34 #define sint_16 signed short int 35 36 // pin distribution 37 #if BOARD_TYPE == BOARD_TYPE_ARDUINO_MEGA 38 // *****for BOARD_TYPE_ARDUINO_MEGA_2560 & BOARD_TYPE_ARDUINO_MEGA 39 // http://arduino.cc/en/Main/ArduinoBoardMega2560 40 // rc522 spi interface 41 #define PIN_RC522_CS 53 //SPI_SS default 42 #define PIN_RC522_SCK 52 43 #define PIN_RC522_MISO 50 44 #define PIN_RC522_MOSI 51 45 #define PIN_RC522_RST 49 46 #else 47 // *****for BOARD_TYPE_ARDUINO_NANO 48 //http://arduino.cc/en/Main/ArduinoBoardNano 49 // rc522 spi interface 50 #define PIN_RC522_CS 10 //SPI_SS default 51 #define PIN_RC522_SCK 13 52 #define PIN_RC522_MISO 12 53 #define PIN_RC522_MOSI 11 54 #define PIN_RC522_RST 9 55 56 #endif // end of switch(BOARD_TYPE) 57 58 #endif // end of __MAIN_H__
1 /************************************************ 2 *@: op_rc522.h 3 *@: rc522 Module extern interface 4 *@: Hmily 5 *@: 2014.10.31 15:44:58 Version 1.0 6 ************************************************/ 7 8 //***************************************************************************************** 9 //@:Header files included 10 //***************************************************************************************** 11 #if defined(ARDUINO) && ARDUINO >= 100 12 #include "Arduino.h" 13 #else 14 #include "WProgram.h" 15 #endif 16 17 #include "main.h" 18 #include <SPI.h> 19 #include <MFRC522.h> 20 21 22 23 #ifndef __OP_RC522_H__ 24 #define __OP_RC522_H__ 25 26 27 28 29 30 extern void Process_RFID(void); 31 extern void RFID_Init(void); 32 33 #endif // end of __OP_RCC_H__