123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- #ifndef __RC522_H__
- #define __RC522_H__
- #include "iocc2530.h"
- #include "public.h"
- //#define IC_SDA P2_0
- //#define IC_SCK P0_7
- //#define IC_MOSI P0_6
- //#define IC_MISO P0_5
- //#define IC_RST P0_4
- #define IC_SDA_PIN P2_0 //数据引脚
- #define IC_SDA_NUM GPIO_0
- #define IC_SDA_PORT P2DIR //设置方向 输入还是输出
- #define IC_SDA_PIN_MODE P2INP //设置输入模式 上拉下拉 三态 这里用三态 P10P11不能设置输入模式
- //引脚配置为输出;
- #define IC_SDA_PIN_OUT() { IC_SDA_PORT |= IC_SDA_NUM; asm("NOP");IC_SDA_PIN_MODE&=~IC_SDA_NUM; }
- #define IC_SCK_PIN P1_7 //数据引脚
- #define IC_SCK_NUM GPIO_7
- #define IC_SCK_PORT P1DIR //设置方向 输入还是输出
- #define IC_SCK_PIN_MODE P1INP //设置输入模式 上拉下拉 三态 这里用三态 P10P11不能设置输入模式
- //引脚配置为输出;
- #define IC_SCK_PIN_OUT() { IC_SCK_PORT |= IC_SCK_NUM; asm("NOP");IC_SCK_PIN_MODE&=~IC_SCK_NUM; }
- #define IC_MOSI_PIN P1_6 //数据引脚
- #define IC_MOSI_NUM GPIO_6
- #define IC_MOSI_PORT P1DIR //设置方向 输入还是输出
- #define IC_MOSI_PIN_MODE P1INP //设置输入模式 上拉下拉 三态 这里用三态 P10P11不能设置输入模式
- //引脚配置为输出;
- #define IC_MOSI_PIN_OUT() { IC_MOSI_PORT |= IC_MOSI_NUM; asm("NOP");IC_MOSI_PIN_MODE&=~IC_MOSI_NUM; }
- #define IC_MISO_PIN P1_5 //数据引脚
- #define IC_MISO_NUM GPIO_5
- #define IC_MISO_PORT P1DIR //设置方向 输入还是输出
- #define IC_MISO_PIN_MODE P1INP //设置输入模式 上拉下拉 三态 这里用三态 P10P11不能设置输入模式
- //引脚配置为输出;
- #define IC_MISO_PIN_OUT() { IC_MISO_PORT |= IC_MISO_NUM; asm("NOP");IC_MISO_PIN_MODE&=~IC_MISO_NUM; }
- #define IC_RST_PIN P1_4 //数据引脚
- #define IC_RST_NUM GPIO_4
- #define IC_RST_PORT P1DIR //设置方向 输入还是输出
- #define IC_RST_PIN_MODE P1INP //设置输入模式 上拉下拉 三态 这里用三态 P10P11不能设置输入模式
- //引脚配置为输出;
- #define IC_RST_PIN_IN() { IC_RST_PORT &=~IC_RST_NUM; asm("NOP");IC_RST_PIN_MODE&=~IC_RST_NUM; }
- char PcdRead(unsigned char addr,unsigned char *pData);
- void SPIWriteByte(unsigned char infor);
- unsigned char SPIReadByte(void);
- unsigned char ReadRawRC(unsigned char Address);
- void WriteRawRC(unsigned char Address, unsigned char value);
- void SetBitMask(unsigned char reg,unsigned char mask) ;
- void ClearBitMask(unsigned char reg,unsigned char mask) ;
- void PcdAntennaOn(void);
- void PcdAntennaOff(void);
- void PcdReset(void);
- void M500PcdConfigISOType(unsigned char type);
- char PcdComMF522(unsigned char Command, //RC522命令字
- unsigned char *pInData, //通过RC522发送到卡片的数据
- unsigned char InLenByte, //发送数据的字节长度
- unsigned char *pOutData, //接收到的卡片返回数据
- unsigned int *pOutLenBit) ;
- char PcdRequest(unsigned char req_code,unsigned char *pTagType);
- char PcdAnticoll(unsigned char *pSnr);
- void CalulateCRC(unsigned char *pIndata,unsigned char len,unsigned char *pOutData);
- char PcdSelect(unsigned char *pSnr);
- char PcdAuthState(unsigned char auth_mode,unsigned char addr,unsigned char *pKey,unsigned char *pSnr);
- char PcdWrite(unsigned char addr,unsigned char *pData);
- char PcdRead(unsigned char addr,unsigned char *pData);
- char PcdHalt(void);
- extern void PcdReset(void);//复位
- extern void M500PcdConfigISOType(unsigned char type);//工作方式
- extern char PcdRequest(unsigned char req_code,unsigned char *pTagType);//寻卡
- extern char PcdAnticoll(unsigned char *pSnr);//读卡号
- extern void RC522_HAL_Init(void);
- /////////////////////////////////////////////////////////////////////
- //MF522命令字
- /////////////////////////////////////////////////////////////////////
- #define PCD_IDLE 0x00 //取消当前命令
- #define PCD_AUTHENT 0x0E //验证密钥
- #define PCD_RECEIVE 0x08 //接收数据
- #define PCD_TRANSMIT 0x04 //发送数据
- #define PCD_TRANSCEIVE 0x0C //发送并接收数据
- #define PCD_RESETPHASE 0x0F //复位
- #define PCD_CALCCRC 0x03 //CRC计算
- /////////////////////////////////////////////////////////////////////
- //Mifare_One卡片命令字
- /////////////////////////////////////////////////////////////////////
- #define PICC_REQIDL 0x26 //寻天线区内未进入休眠状态
- #define PICC_REQALL 0x52 //寻天线区内全部卡
- #define PICC_ANTICOLL1 0x93 //防冲撞
- #define PICC_ANTICOLL2 0x95 //防冲撞
- #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 //休眠
- /////////////////////////////////////////////////////////////////////
- //MF522 FIFO长度定义
- /////////////////////////////////////////////////////////////////////
- #define DEF_FIFO_LENGTH 64 //FIFO size=64byte
- #define MAXRLEN 18
- /////////////////////////////////////////////////////////////////////
- //MF522寄存器定义
- /////////////////////////////////////////////////////////////////////
- // PAGE 0
- #define RFU00 0x00
- #define CommandReg 0x01
- #define ComIEnReg 0x02
- #define DivlEnReg 0x03
- #define ComIrqReg 0x04
- #define DivIrqReg 0x05
- #define ErrorReg 0x06
- #define Status1Reg 0x07
- #define Status2Reg 0x08
- #define FIFODataReg 0x09
- #define FIFOLevelReg 0x0A
- #define WaterLevelReg 0x0B
- #define ControlReg 0x0C
- #define BitFramingReg 0x0D
- #define CollReg 0x0E
- #define RFU0F 0x0F
- // PAGE 1
- #define RFU10 0x10
- #define ModeReg 0x11
- #define TxModeReg 0x12
- #define RxModeReg 0x13
- #define TxControlReg 0x14
- #define TxAutoReg 0x15
- #define TxSelReg 0x16
- #define RxSelReg 0x17
- #define RxThresholdReg 0x18
- #define DemodReg 0x19
- #define RFU1A 0x1A
- #define RFU1B 0x1B
- #define MifareReg 0x1C
- #define RFU1D 0x1D
- #define RFU1E 0x1E
- #define SerialSpeedReg 0x1F
- // PAGE 2
- #define RFU20 0x20
- #define CRCResultRegM 0x21
- #define CRCResultRegL 0x22
- #define RFU23 0x23
- #define ModWidthReg 0x24
- #define RFU25 0x25
- #define RFCfgReg 0x26
- #define GsNReg 0x27
- #define CWGsCfgReg 0x28
- #define ModGsCfgReg 0x29
- #define TModeReg 0x2A
- #define TPrescalerReg 0x2B
- #define TReloadRegH 0x2C
- #define TReloadRegL 0x2D
- #define TCounterValueRegH 0x2E
- #define TCounterValueRegL 0x2F
- // PAGE 3
- #define RFU30 0x30
- #define TestSel1Reg 0x31
- #define TestSel2Reg 0x32
- #define TestPinEnReg 0x33
- #define TestPinValueReg 0x34
- #define TestBusReg 0x35
- #define AutoTestReg 0x36
- #define VersionReg 0x37
- #define AnalogTestReg 0x38
- #define TestDAC1Reg 0x39
- #define TestDAC2Reg 0x3A
- #define TestADCReg 0x3B
- #define RFU3C 0x3C
- #define RFU3D 0x3D
- #define RFU3E 0x3E
- #define RFU3F 0x3F
- /////////////////////////////////////////////////////////////////////
- //和MF522通讯时返回的错误代码
- /////////////////////////////////////////////////////////////////////
- #define MI_OK 0x26
- #define MI_NOTAGERR 0xcc
- #define MI_ERR 0xbb
- #endif
|