RC500.H
上传用户:hbtfgg
上传日期:2021-12-10
资源大小:16k
文件大小:24k
- #ifndef uchar
- #define uchar unsigned char
- #endif
- #ifndef uint
- #define uint unsigned int
- #endif
- /*****************************************************************************
- *端口定义
- *****************************************************************************/
- sbit RC500_CE=P2^6; /*RC500片选*/
- sbit RC500_RST=P2^7; /*RC500复位*/
- /*****************************************************************************
- *函数原型
- *****************************************************************************/
- extern char PcdReset(); /*复位并初始化RC500*/
- extern char PcdRequest(uchar req_code); /*寻卡*/
- extern char PcdAnticoll(uchar *snr); /*防冲撞*/
- extern char PcdSelect(uchar *snr); /*选定一张卡*/
- extern char ChangeCodeKey(uchar *uncoded,uchar *coded); /*转换密钥格式*/
- extern char PcdAuthKey(uchar *coded); /*传送密钥*/
- extern char PcdAuthState(uchar auth_mode,uchar block,uchar *snr); /*验证密钥*/
- extern char PcdRead(uchar addr,uchar *readdata); /*读块*/
- extern char PcdWrite(uchar addr,uchar *writedata); /*写块*/
- extern char PcdValue(uchar dd_mode,uchar addr,uchar *value); /*增(减)钱包值*/
- extern char PcdRestore(uchar addr); /*调钱包值*/
- extern char PcdTransfer(uchar addr); /*备份钱包值*/
- extern char PcdHalt(void); /*卡休眠*/
- extern char PcdReadE2(uint startaddr,uchar length,uchar *readdata); /*读RC500-EEPROM数据*/
- extern char PcdWriteE2(uint startaddr,uchar length,uchar *writedata); /*写数据到RC500-EEPROM*/
- extern char PcdConfigRestore(); /*恢复RC500出厂设置*/
- extern char PcdLoadConfig(uint startaddr); /*调RC500-EEPROM中自设定的设置*/
- extern void PcdAntennaOn(); /*开启RC500天线发射*/
- extern void PcdAntennaOff(); /*关闭RC500天线发射*/
- extern char PcdComTransceive(struct TranSciveBuffer *pi); /*和RC500通讯*/
- extern void WriteRC(uchar Address,uchar value); /*写RC500寄存器*/
- extern void WriteRawRC(uchar Address,uchar value); /*写RC500寄存器*/
- extern uchar ReadRC(uchar Address); /*读RC500寄存器*/
- extern uchar ReadRawRC(uchar Address); /*读RC500寄存器*/
- extern void SetBitMask(uchar reg,uchar mask); /*置RC500寄存器位*/
- extern void ClearBitMask(uchar reg,uchar mask); /*清RC500寄存器位*/
- extern void PcdSetTmo(uchar tmoLength); /*设置RC500定时器*/
- extern void DelayMs(uchar j); /*延时*/
- extern void DelayUs(uchar j); /*延时*/
- /*****************************************************************************
- *MFIRE卡命令字
- *****************************************************************************/
- #define PICC_REQIDL 0x26 /*寻天线区内未进入休眠状态的卡*/
- #define PICC_REQALL 0x52 /*寻天线区内全部卡*/
- #define PICC_ANTICOLL1 0x93 /*防冲撞*/
- #define PICC_AUTHENT1A 0x60 /*验证A密钥*/
- #define PICC_AUTHENT1B 0x61 /*验证B密钥*/
- #define PICC_READ 0x30 /*读块*/
- #define PICC_WRITE 0xA0 /*写块*/
- #define PICC_DECREMENT 0xC0 /*扣款*/
- #define PICC_INCREMENT 0xC1 /*充值*/
- #define PICC_RESTORE 0xC2 /*调钱包到缓冲区*/
- #define PICC_TRANSFER 0xB0 /*保存缓冲区中数据*/
- #define PICC_HALT 0x50 /*休眠*/
- /*****************************************************************************
- *RC500命令字
- *****************************************************************************/
- #define PCD_IDLE 0x00 /*取消当前命令*/
- #define PCD_WRITEE2 0x01 /*写EEPROM*/
- #define PCD_READE2 0x03 /*读EEPROM */
- #define PCD_LOADCONFIG 0x07 /*调EEPROM中保存的RC500设置*/
- #define PCD_LOADKEYE2 0x0B /*将EEPROM中保存的密钥调入缓存*/
- #define PCD_AUTHENT1 0x0C /*验证密钥第一步*/
- #define PCD_AUTHENT2 0x14 /*验证密钥第二步*/
- #define PCD_RECEIVE 0x16 /*接收数据*/
- #define PCD_LOADKEY 0x19 /*传送密钥*/
- #define PCD_TRANSMIT 0x1A /*发送数据*/
- #define PCD_TRANSCEIVE 0x1E /*发送并接收数据*/
- #define PCD_RESETPHASE 0x3F /*复位*/
- #define PCD_CALCCRC 0x12 /*CRC计算*/
- /*****************************************************************************
- *RC500 FIFO长度定义
- *****************************************************************************/
- #define DEF_FIFO_LENGTH 64 /*FIFO size=64byte*/
- /*****************************************************************************
- *RC500寄存器定义
- *****************************************************************************/
- #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 length Register
- #define RegSecondaryStatus 0x05 //!< diverse status flags
- #define RegInterruptEn 0x06 //!< IRQ enable Register
- #define RegInterruptRq 0x07 //!< IRQ bits Register
- #define RegControl 0x09 //!< processor control
- #define RegErrorFlag 0x0A /*!< error flags showing the error
- status of the last command executed */
- #define RegCollPos 0x0B /*!< bit position of the first bit
- collision detected on the RF-interface */
- #define RegTimerValue 0x0C //!< preload value of the timer
- #define RegCRCResultLSB 0x0D //!< LSB of the CRC Coprocessor register
- #define RegCRCResultMSB 0x0E //!< MSB of the CRC Coprocessor register
- #define RegBitFraming 0x0F //!< Adjustments for bit oriented frames
- #define RegTxControl 0x11 //!< controls the logical behaviour of
- //!< the antenna driver pins TX1 and TX2
- #define RegCwConductance 0x12 /*!< selects the conductance of the
- antenna driver pins TX1 and TX2 */
- #define RFU13 0x13 //!< RFU
- #define RegCoderControl 0x14 //!< selects coder rate
- #define RegModWidth 0x15 /*!< selects the width of the
- modulation pulse */
- #define RFU16 0x16 //!< RFU
- #define RFU17 0x17 //!< RFU
- #define RegRxControl1 0x19 //!< controls receiver behaviour
- #define RegDecoderControl 0x1A //!< controls decoder behaviour
- #define RegBitPhase 0x1B /*!< selets the bit phase between
- transmitter and receiver clock */
- #define RegRxThreshold 0x1C //!< selects thresholds for the bit decoder
- #define RFU1D 0x1D //!< RFU
- #define RegRxControl2 0x1E /*!< controls decoder behaviour and
- defines the input source for the receiver */
- #define RegClockQControl 0x1F /*!< controls clock generation for the
- 90