RC500.H
上传用户:hbtfgg
上传日期:2021-12-10
资源大小:16k
文件大小:24k
源码类别:

RFID编程

开发平台:

C/C++

  1. #ifndef uchar
  2. #define uchar unsigned char
  3. #endif
  4. #ifndef uint
  5. #define uint unsigned int
  6. #endif
  7. /*****************************************************************************
  8. *端口定义
  9. *****************************************************************************/
  10. sbit RC500_CE=P2^6;                                                    /*RC500片选*/
  11. sbit RC500_RST=P2^7;                                                   /*RC500复位*/
  12. /*****************************************************************************
  13. *函数原型
  14. *****************************************************************************/
  15. extern char PcdReset();                                                /*复位并初始化RC500*/
  16. extern char PcdRequest(uchar req_code);                                /*寻卡*/
  17. extern char PcdAnticoll(uchar *snr);                                   /*防冲撞*/
  18. extern char PcdSelect(uchar *snr);                                     /*选定一张卡*/
  19. extern char ChangeCodeKey(uchar *uncoded,uchar *coded);                /*转换密钥格式*/
  20. extern char PcdAuthKey(uchar *coded);                                  /*传送密钥*/
  21. extern char PcdAuthState(uchar auth_mode,uchar block,uchar *snr);      /*验证密钥*/
  22. extern char PcdRead(uchar addr,uchar *readdata);                       /*读块*/
  23. extern char PcdWrite(uchar addr,uchar *writedata);                     /*写块*/
  24. extern char PcdValue(uchar dd_mode,uchar addr,uchar *value);           /*增(减)钱包值*/
  25. extern char PcdRestore(uchar addr);                                    /*调钱包值*/
  26. extern char PcdTransfer(uchar addr);                                   /*备份钱包值*/
  27. extern char PcdHalt(void);                                             /*卡休眠*/
  28. extern char PcdReadE2(uint startaddr,uchar length,uchar *readdata);    /*读RC500-EEPROM数据*/
  29. extern char PcdWriteE2(uint startaddr,uchar length,uchar *writedata);  /*写数据到RC500-EEPROM*/
  30. extern char PcdConfigRestore();                                        /*恢复RC500出厂设置*/
  31. extern char PcdLoadConfig(uint startaddr);                             /*调RC500-EEPROM中自设定的设置*/
  32. extern void PcdAntennaOn();                                            /*开启RC500天线发射*/
  33. extern void PcdAntennaOff();                                           /*关闭RC500天线发射*/
  34. extern char PcdComTransceive(struct TranSciveBuffer *pi);              /*和RC500通讯*/
  35. extern void WriteRC(uchar Address,uchar value);                        /*写RC500寄存器*/
  36. extern void WriteRawRC(uchar Address,uchar value);                     /*写RC500寄存器*/
  37. extern uchar ReadRC(uchar Address);                                    /*读RC500寄存器*/
  38. extern uchar ReadRawRC(uchar Address);                                 /*读RC500寄存器*/
  39. extern void SetBitMask(uchar reg,uchar mask);                          /*置RC500寄存器位*/
  40. extern void ClearBitMask(uchar reg,uchar mask);                        /*清RC500寄存器位*/
  41. extern void PcdSetTmo(uchar tmoLength);                                /*设置RC500定时器*/
  42. extern void DelayMs(uchar j);                                          /*延时*/
  43. extern void DelayUs(uchar j);                                          /*延时*/
  44. /*****************************************************************************
  45. *MFIRE卡命令字
  46. *****************************************************************************/
  47. #define PICC_REQIDL           0x26                                     /*寻天线区内未进入休眠状态的卡*/
  48. #define PICC_REQALL           0x52                                     /*寻天线区内全部卡*/
  49. #define PICC_ANTICOLL1        0x93                                     /*防冲撞*/
  50. #define PICC_AUTHENT1A        0x60                                     /*验证A密钥*/
  51. #define PICC_AUTHENT1B        0x61                                     /*验证B密钥*/
  52. #define PICC_READ             0x30                                     /*读块*/
  53. #define PICC_WRITE            0xA0                                     /*写块*/
  54. #define PICC_DECREMENT        0xC0                                     /*扣款*/
  55. #define PICC_INCREMENT        0xC1                                     /*充值*/
  56. #define PICC_RESTORE          0xC2                                     /*调钱包到缓冲区*/
  57. #define PICC_TRANSFER         0xB0                                     /*保存缓冲区中数据*/
  58. #define PICC_HALT             0x50                                     /*休眠*/
  59. /*****************************************************************************
  60. *RC500命令字
  61. *****************************************************************************/
  62. #define PCD_IDLE              0x00                                     /*取消当前命令*/
  63. #define PCD_WRITEE2           0x01                                     /*写EEPROM*/
  64. #define PCD_READE2            0x03                                     /*读EEPROM */
  65. #define PCD_LOADCONFIG        0x07                                     /*调EEPROM中保存的RC500设置*/
  66. #define PCD_LOADKEYE2         0x0B                                     /*将EEPROM中保存的密钥调入缓存*/
  67. #define PCD_AUTHENT1          0x0C                                     /*验证密钥第一步*/
  68. #define PCD_AUTHENT2          0x14                                     /*验证密钥第二步*/
  69. #define PCD_RECEIVE           0x16                                     /*接收数据*/
  70. #define PCD_LOADKEY           0x19                                     /*传送密钥*/
  71. #define PCD_TRANSMIT          0x1A                                     /*发送数据*/
  72. #define PCD_TRANSCEIVE        0x1E                                     /*发送并接收数据*/
  73. #define PCD_RESETPHASE        0x3F                                     /*复位*/
  74. #define PCD_CALCCRC           0x12                                     /*CRC计算*/
  75. /*****************************************************************************
  76. *RC500 FIFO长度定义
  77. *****************************************************************************/
  78. #define DEF_FIFO_LENGTH       64                                /*FIFO size=64byte*/
  79. /*****************************************************************************
  80. *RC500寄存器定义
  81. *****************************************************************************/
  82. #define RegPage               0x00                              //!< Page Select Register
  83. #define RegCommand            0x01                              //!< Command Register
  84. #define RegFIFOData           0x02                              //!< FiFo Register
  85. #define RegPrimaryStatus      0x03                              //!< Modem State/IRQ/ERR/LoHiAlert Reg
  86. #define RegFIFOLength         0x04                              //!< Buffer length Register
  87. #define RegSecondaryStatus    0x05                              //!< diverse status flags
  88. #define RegInterruptEn        0x06                              //!< IRQ enable Register
  89. #define RegInterruptRq        0x07                              //!< IRQ bits Register
  90. #define RegControl            0x09                              //!< processor control
  91. #define RegErrorFlag          0x0A                              /*!< error flags showing the error
  92.                                                                  status of the last command executed */
  93. #define RegCollPos            0x0B                              /*!< bit position of the first bit
  94.                                                                  collision detected on the RF-interface */
  95. #define RegTimerValue         0x0C                              //!< preload value of the timer
  96. #define RegCRCResultLSB       0x0D                              //!< LSB of the CRC Coprocessor register
  97. #define RegCRCResultMSB       0x0E                              //!< MSB of the CRC Coprocessor register
  98. #define RegBitFraming         0x0F                              //!< Adjustments for bit oriented frames
  99. #define RegTxControl          0x11                              //!< controls the logical behaviour of
  100.                                                                 //!< the antenna driver pins TX1 and TX2
  101. #define RegCwConductance      0x12                              /*!< selects the conductance of the
  102.                                                                  antenna driver pins TX1 and TX2 */
  103. #define RFU13                 0x13                              //!< RFU
  104. #define RegCoderControl       0x14                              //!< selects coder rate
  105. #define RegModWidth           0x15                              /*!< selects the width of the
  106.                                                                  modulation pulse */
  107. #define RFU16                 0x16                              //!< RFU
  108. #define RFU17                 0x17                              //!< RFU
  109. #define RegRxControl1         0x19                              //!< controls receiver behaviour
  110. #define RegDecoderControl     0x1A                              //!< controls decoder behaviour
  111. #define RegBitPhase           0x1B                              /*!< selets the bit phase between
  112.                                                                  transmitter and receiver clock */
  113. #define RegRxThreshold        0x1C                              //!< selects thresholds for the bit decoder
  114. #define RFU1D                 0x1D                              //!< RFU
  115. #define RegRxControl2         0x1E                              /*!< controls decoder behaviour and
  116.                                                                  defines the input source for the receiver */
  117. #define RegClockQControl      0x1F                              /*!< controls clock generation for the
  118.                                                                  90