⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rc500.h

📁 基于RC500射频卡读写模块的程序设计
💻 H
📖 第 1 页 / 共 3 页
字号:
#ifdef __SRC
 #define EXTERN
#else
 #define EXTERN		       	extern
#endif
#define INFO_CNT                23
// Configuration for the reader timeout counter 
// Timer 2 (modify OSC_FREQ if another crystal frequency is used)
#define OSC_FREQ                11059600L	
#ifndef NO_TIMER2

 // Timer 2

 #define RCAP2_50us             65536L - OSC_FREQ/240417L
 #define RCAP2_1ms              65536L - OSC_FREQ/12021L
 #define RCAP2_10ms             65536L - OSC_FREQ/1200L

 sfr16   RCAP2LH                = 0xCA;
 sfr16   T2LH                   = 0xCC;

#else

 #define SCON                   S0CON
 #define SBUF                   S0BUF
 #define ES                     ES0

#endif

#ifdef NOP_DELAY

#define DELAY_us(x)            delay_50us_NOP()

#else

 #define DELAY_us(x)            for (i = 0; i < (uchar)(((x)*9)/20); i++)
 // 20 <= x <= 567

#endif


//#ifdef __cplusplus
//extern "C"
//{
//#endif

//#include <mfosdefs.h>

// Important registers of the MF RC500 reader module
// PAGE 0      Command and Status
#define     RegPage               0x00    // Page Select Register
#define     RegCommand            0x01    // Command Register
#define     RegFIFOData           0x02    // FiFo Register
#define     RegPrimaryStatus      0x03    // Modem State/IRQ/ERR/LoHiAlert Reg
#define     RegFIFOLength         0x04    // Buffer lenght Register
#define     RegSecondaryStatus    0x05
#define     RegInterruptEn        0x06    // IRQ enable Register
#define     RegInterruptRq        0x07    // IRQ bits Register
// PAGE 1      Control and Status
#define     RegControl            0x09    // processor control
#define     RegErrorFlag          0x0A
#define     RegCollpos            0x0B
#define     RegTimerValue         0x0C
#define     RegCRCResultLSB       0x0D
#define     RegCRCResultMSB       0x0E
#define     RegBitFraming         0x0F
// PAGE 2      Transmitter and Coder Control
#define     RegTxControl          0x11
#define     RegCwConductance      0x12
#define     RFU13                 0x13
#define     RFU14                 0x14
#define     RegModWidth           0x15
#define     RFU16                 0x16
#define     RFU17                 0x17
// PAGE 3      Receiver and Decoder Control
#define     RegRxControl1         0x19
#define     RegDecoderControl     0x1A
#define     RegBitPhase           0x1B
#define     RegRxThreshold        0x1C
#define     RFU1D                 0x1D
#define     RegRxControl2         0x1E
#define     RegClockQControl      0x1F
// PAGE 4      RF-Timing and Channel Redundancy
#define     RegRxWait             0x21
#define     RegChannelRedundancy  0x22
#define     RegCRCPresetLSB       0x23
#define     RegCRCPresetMSB       0x24
#define     RFU25                 0x25
#define     RegMfOutSelect        0x26
#define     RFU27                 0x27
// PAGE 5      FIFO, Timer and IRQ-Pin Configuration
#define     RegFIFOLevel          0x29
#define     RegTimerClock         0x2A
#define     RegTimerControl       0x2B
#define     RegTimerReload        0x2C
#define     RegIRqPinConfig       0x2D
#define     RFU2E                 0x2E
#define     RFU2F                 0x2F
// PAGE 6      RFU
#define     RFU31                 0x31
#define     RFU32                 0x32
#define     RFU33                 0x33
#define     RFU34                 0x34
#define     RFU35                 0x35
#define     RFU36                 0x36
#define     RFU37                 0x37
// PAGE 7      Test Control
#define     RFU39                 0x39   //!< RFU
#define     RegTestAnaSelect      0x3A   //!< selects analog test mode
#define     RFU3B                 0x3B   //!< RFU
#define     RFU3C                 0x3C   //!< RFU
#define     RegTestDigiSelect     0x3D   //!< selects digital test mode
#define     RFU3E                 0x3E   //!< RFU
#define     RegTestDigiAccess     0x3F


#define DEF_FIFO_LENGTH     64  // default FIFO length

#define SND_BUF_LEN       0x20
#define RCV_BUF_LEN       0x20

//                   P C D - C O M M A N D S
#define PCD_IDLE           0x00 // No action: cancel current command 
                                // or home state, respectively
#define PCD_WRITEE2        0x01 // Get data from FIFO and write it to the E2PROM
#define PCD_READE2         0x03 // Read data from E2PROM and put it into the 
                                // FIFO
#define PCD_LOADCONFIG     0x07 // Read data from E2PROM and initialise the 
                                // registers
#define PCD_LOADKEYE2      0x0B // Read a master key from the E2PROM and put 
                                // it into the master key buffer
#define PCD_AUTHENT1       0x0C // Perform the first part of the card 
                                // authentication using the Crypto1 algorithm.
                                // Remark: The master key is automatically taken 
                                // from 
                                // the master key buffer. this implies, that the
                                // command LoadKeyE2 has to be executed before 
                                // to use a certain key for card authentication
#define PCD_CALCCRC        0x12	// Activate the CRC-Coprocessor
                                // Remark: The result of the CRC calculation can
                                // be read from the register CRCResultXXX
#define PCD_AUTHENT2       0x14	// Perform the second part of the card 
                                // authentication using the Crypto1 algorithm.
#define PCD_RECEIVE        0x16 // Activate Receiver Circuitry. Before the 
                                // receiver actually starts, the state machine 
                                // waits until the time 
                                // configured in the register RcvWait has 
                                // passed.
                                // Remark: It is possible to read data from the 
                                // FIFO although Receive is active. Thus it is 
                                // possible to receive any number of bytes by 
                                // reading them from the FIFO in time.
#define PCD_LOADKEY        0x19 // Read a master key from the FIFO and put it 
                                // into the master key buffer
                                // Remark: The master key has to be prepared in
                                // a certain format. Thus, 12 byte have to be 
                                // passed to load a 6 byte master key
#define PCD_TRANSMIT       0x1A // Transmit data from FIFO to the card
                                // Remark: If data is already in the FIFO when 
                                // the command is activated, this data is 
                                // transmitted immediately. It is possible to 
                                // write data to the FIFO although Transmit 
                                // is active. Thus it is possible to transmitt 
                                // any number of bytes by writting them to the 
                                // FIFO in time. 
#define PCD_TRANSCEIVE     0x1E	// Transmit data from FIFO to the card and after 
                                // that automatically activates the receiver. 
                                // Before the receiver actually starts, the 
                                // STATE MACHINE waits until the time configured
                                //  in the register RcvWait has passed.
                                // Remark: This command is the combination of 
                                // Transmit and Receive
#define PCD_RESETPHASE     0x3F // Runs the Reset- and Initialisation Phase
                                // Remark: This command can not be activated by 
                                // software, but only by a Power-On or 
                                // Hard Reset 


//#ifdef __cplusplus
//}
//#endif

//#ifdef __cplusplus
//extern "C"
//{
//#endif

// General Include File for serveral defines concerning conditional library
// compilation and microcontroller usage
//#include <MfOsDefs.h>


// P I C C - C O M M A N D S
// commands which are handled by the tag
// Each tag command is written to the reader IC and transfered via RF
#define PICC_REQSTD        0x26			// request idle
#define PICC_REQALL        0x52			// request all
#define PICC_ANTICOLL1     0x93			// anticollision level 1
#define PICC_ANTICOLL2     0x95			// anticollision level 2
#define PICC_ANTICOLL3     0x97			// anticollision level 3
#define PICC_AUTHENT1A     0x60			// authentication step 1
#define PICC_AUTHENT1B     0x61			// authentication step 2
#define PICC_READ          0x30			// read block
#define PICC_WRITE         0xA0			// write block
#define PICC_DECREMENT     0xC0         	// decrement value
#define PICC_INCREMENT     0xC1         	// increment value
#define PICC_RESTORE       0xC2         	// restore command code
#define PICC_TRANSFER      0xB0         	// transfer command code
#define PICC_HALT          0x50			// halt

// Mifare Error Codes
// Each function returns a status value, which corresponds to the
// mifare error codes. 
#define MI_OK                           0
#define MI_CHK_OK                       0
#define MI_CRC_ZERO                     0

#define MI_CRC_NOTZERO                  1

#define MI_NOTAGERR                     (-1)
#define MI_CHK_FAILED                   (-1)
#define MI_CRCERR                       (-2)
#define MI_CHK_COMPERR                  (-2)
#define MI_EMPTY                        (-3)
#define MI_AUTHERR                      (-4)
#define MI_PARITYERR                    (-5)
#define MI_CODEERR                      (-6)

#define MI_SERNRERR                     (-8)
#define MI_KEYERR                       (-9)
#define MI_NOTAUTHERR                   (-10)
#define MI_BITCOUNTERR                  (-11)
#define MI_BYTECOUNTERR                 (-12)
#define MI_IDLE                         (-13)
#define MI_TRANSERR                     (-14)
#define MI_WRITEERR                     (-15)
#define MI_INCRERR                      (-16)
#define MI_DECRERR                      (-17)
#define MI_READERR                      (-18)
#define MI_OVFLERR                      (-19)
#define MI_POLLING                      (-20)
#define MI_FRAMINGERR                   (-21)
#define MI_ACCESSERR                    (-22)
#define MI_UNKNOWN_COMMAND              (-23)
#define MI_COLLERR                      (-24)
#define MI_RESETERR                     (-25)
#define MI_INITERR                      (-25)
#define MI_INTERFACEERR                 (-26)
#define MI_ACCESSTIMEOUT                (-27)
#define MI_NOBITWISEANTICOLL            (-28)
#define MI_QUIT                         (-30)

#define MI_RECBUF_OVERFLOW              (-50) 
#define MI_SENDBYTENR                   (-51)
	
#define MI_SENDBUF_OVERFLOW             (-53)
#define MI_BAUDRATE_NOT_SUPPORTED       (-54)
#define MI_SAME_BAUDRATE_REQUIRED       (-55)

#define MI_WRONG_PARAMETER_VALUE        (-60)

#define MI_BREAK                        (-99)
#define MI_NY_IMPLEMENTED               (-100)
#define MI_NO_MFRC                      (-101)
#define MI_MFRC_NOTAUTH                 (-102)
#define MI_WRONG_DES_MODE               (-103)
#define MI_HOST_AUTH_FAILED             (-104)

#define MI_WRONG_LOAD_MODE              (-106)
#define MI_WRONG_DESKEY                 (-107)
#define MI_MKLOAD_FAILED                (-108)
#define MI_FIFOERR                      (-109)
#define MI_WRONG_ADDR                   (-110)
#define MI_DESKEYLOAD_FAILED            (-111)

#define MI_WRONG_SEL_CNT                (-114)

#define MI_WRONG_TEST_MODE              (-117)
#define MI_TEST_FAILED                  (-118)
#define MI_TOC_ERROR                    (-119)
#define MI_COMM_ABORT                   (-120)
#define MI_INVALID_BASE                 (-121)
#define MI_MFRC_RESET                   (-122)
#define MI_WRONG_VALUE                  (-123)
#define MI_VALERR                       (-124)

// _____________________________________________________________________________
//
//  FUNCTION: OpenIO
//        IN: -
//       OUT: -
//    RETURN: 0     no error occured
//            != 0  error opening IO
//   COMMENT: open and initialise communication channel to the reader module
//
EXTERN char OpenIO(void);

// _____________________________________________________________________________
//
//  FUNCTION: WriteIO
//        IN: address   register address in the reader module address space
//            value     value, which should be written
//       OUT: -
//    RETURN: -
//   COMMENT: This function determines the necessary page address of the 
//            reader module and writes the page number to the page 
//            register and the value to the specified address.
//
EXTERN void WriteIO(unsigned char Address, unsigned char value);

// _____________________________________________________________________________
//
//  FUNCTION: ReadIO
//        IN: address  register address in the reader module address space
//       OUT: -
//    RETURN: value    value, which should be read
//   COMMENT: This function determines the necessary page address of the 
//            reader module and writes the page number to the page 
//            register and the value to the specified address.
//
EXTERN unsigned char ReadIO(unsigned char Address);

// _____________________________________________________________________________
//
//  FUNCTION: CloseIO
//        IN: -
//       OUT: -
//    RETURN: -
//   COMMENT: Closing the communication channel to the reader module
//

EXTERN void CloseIO(void);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -