www.pudn.com > RC500.rar > m500a.h


#ifndef M500A_H 
#define M500A_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) 
 
#define GetRegPage(addr)    (0x80 | (addr>>3)) 
 
#define nocard			    0 
#define mifare1S50		    1 
#define mifare1S70  	    2 
#define mifarelight		    3 
#define unknowncard		    4 
 
// write data to address 写一个数据到某个地址 
/////////////////////////////////////////////////////////////////////// 
 void WriteRawIO(unsigned char Address,unsigned char value); 
 
// read data from address 从某个地址读出一个数据 
/////////////////////////////////////////////////////////////////////// 
 unsigned char ReadRawIO(unsigned char Address); 
 
// write data eeprom 往一个地址写一个数据(EEPROM) 
/////////////////////////////////////////////////////////////////////// 
 void WriteIO(unsigned char Address, unsigned char value); 
 
// read data eeprom 从一个地址读出一个数据(EEPROM) 
/////////////////////////////////////////////////////////////////////// 
 unsigned char ReadIO(unsigned char Address); 
 
// Set pcd time 设置定时时间 
/////////////////////////////////////////////////////////////////////// 
 void M500PcdSetTime(unsigned char timeLength); 
 
// Request Command defined in ISO14443(Mifare) 定义mifare 请求命令 
/////////////////////////////////////////////////////////////////////// 
 char  M500PcdCmd(unsigned char cmd, 
               volatile unsigned char data *rcv, 
                MfCmdInfo idata *info); 
 
// Set bit 置一个bit 
/////////////////////////////////////////////////////////////////////// 
 char SetBitMask(unsigned char reg,unsigned char mask);   
 
// Clear bit 清一个bit 
/////////////////////////////////////////////////////////////////////// 
 char ClearBitMask(unsigned char reg,unsigned char mask); 
 
//清除FIFO 
/////////////////////////////////////////////////////////////////////// 
 void FlushFIFO(void); 
 
// Value format operations for Mifare Standard card ICs 操作值设置 
/////////////////////////////////////////////////////////////////////// 
 char M500PiccValue(unsigned char dd_mode,  
                   unsigned char addr,  
                   unsigned char *value, 
                   unsigned char trans_addr); 
 
// Set card in HALT-state  终止卡的操作 
/////////////////////////////////////////////////////////////////////// 
/////////////////////////////////////////////////////////////////////// 
// Key loading into the MF RC500's EEPROM 
// 校验卡密码(E2) 
/////////////////////////////////////////////////////////////////////// 
 char M500PiccAuthE2( unsigned char auth_mode,unsigned char *snr,       
                     unsigned char keynr,unsigned char block);  
/////////////////////////////////////////////////////////////// 
// Key loading into the MF RC500's EEPROM 
///////////////////////////////////////////////////////////////		             
 char M500PcdLoadKeyE2(unsigned char key_type, 
                       unsigned char sector, 
                       unsigned char *uncoded_keys); 
//////////////////////////////////////////////////////////////// 
// Read the mifare card 
// 读卡 
//////////////////////////////////////////////////////////////// 
 char M500PiccRead(unsigned char addr,unsigned char *_data); 
// Write the mifare card 
// 写卡  下载密码 
//////////////////////////////////////////////////////////////// 
 char M500PiccWrite( unsigned char addr,unsigned char *_data); 
  
 char MfConfig(void); 
// Set card in HALT-state  终止卡的操作 
/////////////////////////////////////////////////////////////////////// 
 char M500PiccHalt(void); 
// Reset Card 复位卡 
/////////////////////////////////////////////////////////////////////// 
 char M500PcdRfReset(unsigned char ms); 
// Authentication key coding 
/////////////////////////////////////////////////////////////////////// 
 char M500HostCodeKey(unsigned char *uncoded,  
                     unsigned char *coded); 
// Request Command defined in ISO14443(MIFARE) 
// Request 
// 寻卡 
/////////////////////////////////////////////////////////////////////// 
 char M500PiccCommonRequest(unsigned char req_code,  
                         unsigned char *atq); 
// Cascaded Anti-Collision Command defined in ISO14443(MIFARE) 
// 防冲突 读卡的系列号 MLastSelectedSnr 
/////////////////////////////////////////////////////////////////// 
 char M500PiccCascAnticoll( unsigned char bcnt,        
                           unsigned char *snr);    
 char M500PiccCascSelect(unsigned char *snr, 
                        unsigned char *sak);       
 
// Set bit 置一个bit 
/////////////////////////////////////////////////////////////////////// 
 char SetBitMask(unsigned char reg,unsigned char mask);  
// Set pcd time 设置定时时间 
///////////////////////////////////////////////////////////////////////                     
 void M500PcdSetTmo(unsigned char tmoLength); 
// Request Command defined in ISO14443(Mifare) 定义mifare 请求命令 
/////////////////////////////////////////////////////////////////////// 
 char M500PcdCmd(unsigned char cmd, 
                volatile unsigned char data * rcv, 
                volatile MfCmdInfo idata *info); 
// Clear bit 清一个bit 
/////////////////////////////////////////////////////////////////////// 
 char ClearBitMask(unsigned char reg,unsigned char mask); 
//清除FIFO 
/////////////////////////////////////////////////////////////////////// 
 void FlushFIFO(void); 
// Write the MF RC500's EEPROM 
/////////////////////////////////////////////////////////////////////// 
 char PcdWriteE2(unsigned int startaddr, 
                unsigned char length, 
                unsigned char* _data); 
//认证状态 
/////////////////////////////////////////////////////////////////////// 
 char M500PiccAuthState(unsigned char auth_mode, 
                       unsigned char *snr,     
                       unsigned char block);  
////////////////////////////////////////////////////////////////////////////// 
 
#endif 
////////////////////////////////////////////////////////////////////////////// 
// End of File 
//////////////////////////////////////////////////////////////////////////////