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

📄 rc500.h

📁 基于RC500射频卡读写模块的程序设计
💻 H
📖 第 1 页 / 共 3 页
字号:


// _____________________________________________________________________________
//
//  FUNCTION: WriteRawIO
//        IN: addr        address within the reader address space (0x00 to 0xFF),
//                        where the value should be written.
//            value       value, which should be written
//       OUT: -
//    RETURN: -
//   COMMENT: Inline code for reading one char from the reader module
//            The reader module is connected to a 8 bit multiplexed data address
//            bus, therefore the lower address byte is directly mapped to the
//	      reader module is mapped as follows:
//                     uC             Reader
//                     AD0              A0
//                     AD1              A1
//			.		.
//                     AD7              A7
//
#define WriteRawIO(addr,value)  *(GpBase + addr) = value;

// _____________________________________________________________________________
//
//  FUNCTION: ReadRawIO
//        IN: addr        address within the reader address space (0x00 to 0xFF),
//                        which shoud be read.
//       OUT: -
//    RETURN: value of the reader module
//   COMMENT: Inline code for reading one char from the reader module
//            The reader module is connected to a 8 bit multiplexed data address
//            bus, therefore the lower address byte is directly mapped to the
//	      reader module is mapped as follows:
//                     uC             Reader
//                     AD0              A0
//                     AD1              A1
//			.		.
//                     AD7              A7
//
#define ReadRawIO(addr) (*(GpBase + addr))

//extern unsigned char xdata *idata GpBase;    // variable only for internal use
//#endif
// MFRC500 EEPROM Crypto1 address
#define Crypto1E2Add_AKEY(x)    0x80+x*0x18
#define Crypto1E2Add_BKEY(x)    0x8c+x*0x18
///////////////////////////////////////////////////////////////////////////////
//                 Module Definitions
///////////////////////////////////////////////////////////////////////////////
#define GetRegPage(adr) (0x80 | (adr>>3))
EXTERN unsigned char xdata * GpBase;//2004.1.5= &ini;   // redirect pointer to base address
EXTERN char rc500(bit mode,bit authmode,uchar block,uchar *carddata,uchar *cardsn);
EXTERN char readsnr(uchar *cardsn);/*2004.4.31*/
EXTERN void delay_8us_NOP(void);

EXTERN void delay_50us(uchar _50us);
EXTERN void delay_1ms(uchar _1ms);
EXTERN void delay_10ms(uint _10ms);

#ifdef NOP_DELAY
 EXTERN void delay_50us_NOP(void);
#endif


// _____________________________________________________________________________
//
//  FUNCTION: M500PcdReset
//        IN: -
//       OUT: -
//    RETURN: MI_OK
//            MI_RESETERR
//            MI_INTERFACEERR
//   COMMENT: This function initiates a reset of the reader IC. Note, that
//            the reset pin of the reader has to be connected to the 
//            expected port pin of the microcontroller.
//
EXTERN char M500PcdReset(void);

// _____________________________________________________________________________
//
//  FUNCTION: M500PcdConfig
//        IN: -
//       OUT: -
//    RETURN: MI_OK
//            MI_RESETERR
//            MI_INTERFACEERR
//   COMMENT: Configuration of the reader IC. This function has to be called
//            before the first data is written to the reader. A reset 
//            is initiated and several registers are set.
//
EXTERN char M500PcdConfig(void);

// _____________________________________________________________________________
//
//  FUNCTION: M500PcdInOutSlaveConfig
//        IN: -
//       OUT: -
//    RETURN: MI_OK
//            MI_UNKNOWN_COMMAND
//            MI_ACCESSTIMEOUT
//   COMMENT: The reader IC is able to communicate with another reader IC
//            via the digital "mifare in" and "mifare out" interface. Therefore
//            one reader acts as a master and sends commands via "mifare out".
//            The other reader ic acts as a slave and receives data via
//            "mifare in" interface. The slave module can not be initialised
//            by the microcontroller because only the "mifare in/out"
//            interface is connected.For this reason, the slave module has 
//            to be initialised once. For that the appropriate parameter 
//            settings are written to 
//            the E2PROM. After POR (power on reset) the IC reads these settings
//            and initialises automatically as slave.
//
EXTERN char M500PcdInOutSlaveConfig(void);

// _____________________________________________________________________________
//
//  FUNCTION: M500PcdInOutMasterConfig
//        IN: -
//       OUT: -
//    RETURN: MI_OK
//   COMMENT: Corresponding to the slave configuration routine. This function
//            initialises the master reader IC. The function is additional
//            to the standard configuration "M500PcdConfig".
//
EXTERN char M500PcdInOutMasterConfig(void);

// _____________________________________________________________________________
//
//  FUNCTION: MfPcdLoadMk
//        IN: kl_mode     PICC_AUTHENT1A or PICC_AUTHENT1B 
//                              selects master key A or master key B 
//                        KS0, KS1, KS2 selects one of the three master key sets.
//            key_addr    spec. the key RAM address to which the data shall be 
//                        written (0..15)
//            mk          pointer to a 6 byte authentication key
//       OUT: -
//    RETURN: MI_OK
//   COMMENT: In order to be "calling compatibel" to former libraries, this 
//            function enables to store all keys in the microcontroller.
//            When calling the authentication function "M500PiccAuth", 
//            these keys can be used.
//            Note: This concept supports backward compatibility for the 
//            application software, but does not fulfill the same security 
//            level because keys are in this case stored autside the secure key 
//            memory of the MF RC500.
//
EXTERN char M500PcdLoadMk(unsigned char  kl_mode, 
                   unsigned char  key_addr, 
                   unsigned char  *mk);
 
// _____________________________________________________________________________
//
//  FUNCTION: M500PcdLoadKeyE2
//        IN: key_type      PICC_AUTHENT1A or PICC_AUTHENT1B 
//            sector        key sector number, on which the key should be stored
//                          values from 0 to 15 are valid
//            uncoded_keys  6 bytes key 
//       OUT: -
//    RETURN: 
//   COMMENT: This function stores the keys in the reader internal E2PROM.
//            These keys are available for the function M500PiccAuthE2.
//                     
EXTERN char M500PcdLoadKeyE2(unsigned char key_type,
                      unsigned char sector,
                      unsigned char *uncoded_keys); 

// _____________________________________________________________________________
//
//  FUNCTION: PcdReadE2
//        IN: startaddr     2 bytes of starting address of the E2PROM 
//            length        number of byte of data to be read
//       OUT: *_data        buffer for the read bytes 
//    RETURN: 
//   COMMENT: This functions reads out data stored in the MF RC500's EERPOM   
//	      beginning ataddress startaddr. The number of bytes to be read are  
//	      given by  the variablelength and the read out data are stored in  
//            the provided data buffer.
//
EXTERN char PcdReadE2(unsigned short startaddr,  
               unsigned char length,
               unsigned char* _data);

// _____________________________________________________________________________
//
//  FUNCTION: PcdWriteE2
//        IN: startaddr     2 bytes of starting address of the E2PROM 
//            length        number of byte of data to be write
//       OUT: *_data        buffer for the write bytes 
//    RETURN: 
//   COMMENT: This function writes a given length of data bytes stored in the data  
// 	      buffer to the reader IC's EEPROM beginning at address <em>startaddr</em>. 
//
EXTERN char PcdWriteE2(unsigned short startaddr,
                unsigned char length,
                unsigned char* _data);

// _____________________________________________________________________________
//
//  FUNCTION: M500PcdMfOutSelect
//        IN: type      The signal to be appear at MfOut pin 
//
//		000: Constant Low
//		001: Constant High
//		010: Modulation signal from the internal coder, Miller coded
//		011: Serial data stream, not Miller coded
//		100: Output signal of the energy carrier demodulator
//		101: Output signal of the subcarrier demodulator
//		110: RFU
//		111: RFU
//       OUT: -
//    RETURN: 
//   COMMENT: This function config the output of the MfOut pin
//                     
EXTERN char M500PcdMfOutSelect(unsigned char type);
                     
// _____________________________________________________________________________
//
//  FUNCTION: M500PcdWriteRegister
//        IN: Reg      	Register address
//	      value	value to be written	 
//       OUT: -
//    RETURN: 
//   COMMENT: This function write the value to the RC500 register
//                     
EXTERN char M500PcdWriteRegister(unsigned char Reg, unsigned char value);

// _____________________________________________________________________________
//
//  FUNCTION: M500PcdReadRegister
//        IN: Reg      	Register address 
//       OUT: -
//    RETURN: value	value of register
//   COMMENT: This function read the value of the RC500 register
//                     
EXTERN char M500PcdReadRegister(unsigned char Reg);

// _____________________________________________________________________________
//
//  FUNCTION: M500PiccRequest
//        IN: rq_code  can take the following values
//                     ALL   Request Code 52hex is sent out to get also a 
//                           response from cards in halt state.
//                     IDLE  Request Code 26hex is sent out to get a response 
//                           only from cards that are not in halt state.
//                     Note: Future cards will work also with other request 
//                           codes.
//       OUT: atq      16 bit ATQ (answer to request). 
//                     atq[0] .. LSByte
//                     atq[1] .. MSByte
//    RETURN: 
//   COMMENT: This function accesses the reader module and activates sending the
//            REQ code to the MIFARE card. After sending the command to the card 
//            the function waits for the card's answer.
//
//            Please note, that the actual work is done by the function
//            M500PiccCommonRequest, because of the interface behaviour between
//            Mifare and ISO 14443
//
//            The Card replies the ATQ.
//
//            ATQ:
//
//                    +----+----+----+----+----+----+----+----+
//            LSByte  | b8 | b7 | b6 | b5 | b4 | b3 | b2 | b1 |
//                    +----+----+----+----+----+----+----+----+
//                    |         |    |                        |
//                    | UID size| RFU|   bit-frame anticoll   |
//                    |         |    |                        |
//                    | 00..std |    |  (if any bit set .. Y, |
//                    | 01..dbl |    |             else .. N) |
//                    | 10..tpl |    |                        |
//
//
//
//                    +----+----+----+----+----+----+----+----+
//            MSByte  | b8 | b7 | b6 | b5 | b4 | b3 | b2 | b1 |
//                    +----+----+----+----+----+----+----+----+
//                    |                                       |
//                    |                 RFU                   |
//                    |                                       |
//
EXTERN char M500PiccRequest(unsigned char req_code, 
                       unsigned char *atq);
// _____________________________________________________________________________
//
//  FUNCTION: M500PiccCommonRequest
//        IN: rq_code  can take the following values
//                     ALL   Request Code 52hex is sent out to get also a 
//                           response from cards in halt state.
//                     IDLE  Request Code 26hex is sent out to get a response 
//                           only from cards that are not in halt state.
//                     Note: Future cards will work also with other request 
//                           codes.
//       OUT: atq      16 bit ATQ (answer to request). 
//                     atq[0] .. LSByte
//                     atq[1] .. MSByte
//    RETURN: 
//   COMMENT: Please note, that this function does the actual work which is 
//            described in function M500PiccRequest.
//
EXTERN char M500PiccCommonRequest(unsigned char req_code, 
                             unsigned char *atq);  

// _____________________________________________________________________________
//
//  FUNCTION: M500PiccAnticoll
//        IN: bcnt       Number of snr-bits that are known (default value is 0)
//            *snr       4 bytes serial number (number of bits, which
//                       are known and indicated by "bcnt"
//       OUT: *snr       4 bytes serial number, determined by the anticollision
//                       sequence
//    RETURN: 
//   COMMENT: The actual anticollision loop is done by the function
//            "M500PiccCascAnticoll". Which is called with select_code 0x93.
//
EXTERN char M500PiccAnticoll (unsigned char bcnt,
                         unsigned char *snr);

// _____________________________________________________________________________
//
//  FUNCTION: M500PiccCascAnticoll
//        IN: select_code    0x93  standard select code
//                           0x95  cascaded level 1
//                           0x97  cascaded level 2
//            bcnt       Number of snr-bits that are known (default value is 0)
//            *snr       4 bytes serial number (number of bits, which
//                       are known and indicated by "bcnt"
//       OUT: *snr       4 bytes serial number, determined by the anticollision
//                       sequence
//    RETURN: 
//   COMMENT: Corresponding to the specification in ISO 14443, this function
//            is able to handle extended serial numbers. Therefore more than

⌨️ 快捷键说明

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