




已阅读5页,还剩18页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
SL RC400程序设计#include #include #include #include main.h#include slrc400.h#include iso15693.hunsigned char xdata ini _at_ 0x7f00; / move base address to 0x7f00unsigned char xdata *GpBase = &ini; / redirect pointer to base address#define ReadRawIO(addr) (*(GpBase + addr)#define WriteRawIO(addr,value) *(GpBase + addr) = value;extern struct TranSciveBufferunsigned char MfCommand; unsigned int MfLength; unsigned char MfData64; ;/复位并初始化RC400/注意:RC400上电后应延时500ms才能可靠初始化/char PcdReset() char status = MI_OK; char n = 0; unsigned int i = 2000; RC400_RST=0; DelayMs(50); RC400_RST=1; DelayMs(5); RC400_RST=0; while (i!=0 & n!=PCD_RESETPHASE) n = ReadRawRC(RegCommand); i-; while (i!=0 & n=PCD_RESETPHASE) n = ReadRawRC(RegCommand); i-; if (i != 0) WriteRawRC(RegPage,0x80); n = 0x80; while ( (i!=0) & (n&0x80) ) n = ReadRawRC(RegCommand); i-; if (i=0 | (n&0xFF) status = MI_RESETERR ; else status = MI_RESETERR; if (status = MI_OK) WriteRawRC(RegPage,0x0); return status;/设置RC400的工作方式 /char PcdConfigISOType()ClearBitMask(RegControl,0x08);/ WriteRawRC(RegTxControl,0x58);/100%ASK WriteRawRC(RegCwConductance,0x3f);/输出功率和操作距离调整 WriteRawRC(RegModConductance,0x05); / must be measured for 15% Modulation Index WriteRawRC(RegCoderControl,0x2f); /2e fast 2f / 52.97kHz, 1-256 coding WriteRawRC(RegModWidth,0x3F); /设置调制脉冲宽度: 9.44us WriteRawRC(RegModWidthSOF,0x3F); /设置SOF脉冲宽度: 9.44us/ WriteRawRC(RegTypeBFraming,0x00); WriteRawRC(RegRxControl1,0x8b);/控制接收:电压增益42db WriteRawRC(RegDecoderControl,0x34);/c14); WriteRawRC(RegBitPhase,0xad);/0xcd);/0xad);/?? WriteRawRC(RegRxThreshold,0x68);/c68);/ WriteRawRC(RegBPSKDemControl,0); WriteRawRC(RegRxControl2,0x81);/c41);I时钟用作接收器时钟 WriteRawRC(RegClockQControl,0x00); WriteRawRC(RegRxWait,0x08); WriteRawRC(RegChannelRedundancy,0x2C); / Enable CRC TX/RX WriteRawRC(RegCRCPresetLSB,0xFF); WriteRawRC(RegCRCPresetMSB,0xFF); WriteRawRC(RegTimeSlotPeriod,0x00); WriteRawRC(RegSIGOUTSelect,0x00);/?0X02 / enable SIGOUT = envelope/ WriteRawRC(RFU27,0x00); WriteRawRC(RegFIFOLevel,0x38); WriteRawRC(RegTimerClock,0x0B); WriteRawRC(RegTimerReload,0x00); WriteRawRC(RegTimerControl,0x02); / TStopRxEnd=0,TStopRxBeg=1,/ WriteRawRC(RFU2E,0x00);/ WriteRawRC(RFU2F,0x00); DelayMs(1); PcdAntennaOn(); return MI_OK;/读RC400寄存器位/input:Address=寄存器地址/ouput:读出的值/unsigned char ReadRawRC(unsigned char Address) static unsigned char c;c = ReadRawIO(Address); / read value at the specified / address return c; / 写RC400寄存器/input:Address=寄存器地址/ value=要写入的值/void WriteRawRC(unsigned char Address, unsigned char value) WriteRawIO(Address,value);/置RC400寄存器位/input:reg=寄存器地址/ mask=置位值/void SetBitMask(unsigned char reg,unsigned char mask) char tmp = 0x0; tmp = ReadRawRC(reg); WriteRawRC(reg,tmp | mask); / set bit mask/清RC400寄存器位/input:reg=寄存器地址/ mask=清位值/void ClearBitMask(unsigned char reg,unsigned char mask) char tmp = 0x0; tmp = ReadRawRC(reg); WriteRawRC(reg, tmp & mask); / clear bit mask / 通过RC400和ISO15693卡通讯/input: pi-MfCommand = RC400命令字/ pi-MfLength = 发送的数据长度/ pi-MfData = 发送数据/output:status = 错误字/ pi-MfLength = 接收的数据BIT长度/ pi-MfData = 接收数据/char ISO15693_Transceive(struct TranSciveBuffer *pi)bit recebyte = 0; char status = MI_COM_ERR; unsigned char n,waitFor,TimerReload; unsigned int i; switch (pi-MfCommand) case PCD_TRANSMIT: waitFor = 0x08;/0x10; break; default: waitFor = 0x28; recebyte=1; break; /* switch (pi-MfData1) case ISO15693_STAY_QUIET: TimerReload = 0x04; / 2048/fc = 0x01 = 151 us break; case ISO15693_SELECT: case ISO15693_RESET_TO_READY: TimerReload = 0x0F; / 2048/fc = 0x01 = 151 us break; case ISO15693_LOCK_AFI: case ISO15693_LOCK_DSFID: case ISO15693_LOCK_BLOCK: case ISO15693_WRITE_SINGLE_BLOCK: case ISO15693_WRITE_MULTIPLE_BLOCKS: case ISO15693_WRITE_AFI: case ISO15693_WRITE_DSFID: TimerReload = 0x29; / 2048/fc = 0x01 = 151 us break; case ISO15693_READ_SINGLE_BLOCK: TimerReload = 0x17; / 2048/fc = 0x01 = 151 us break; case ISO15693_INVENTORY: TimerReload = 0x1F; / 2048/fc = 0x01 = 151 us break; case ISO15693_GET_SYSTEM_INFO: TimerReload = 0x25; / 2048/fc = 0x01 = 151 us break; case ISO15693_GET_MULTIPLE_BLOCK_SECURITY: TimerReload = 0x40;/(0x04+(cmdcmdlen-1+0x01)*0x02 + 0x04 + 0x01; / 2048/fc = 0x01 = 151 us break; / (0x04 + cmdcmdlen - 1)*0x02 - Time for all receivedBytes, 0x04 - Time bevore and after response, 0x01 additional case ISO15693_READ_MULTIPLE_BLOCKS: TimerReload = 0x40;/(0x04+0x04*(cmdcmdlen-1+0x01)*0x02 + 0x04 + 0x01; / 2048/fc = 0x01 = 151 us break; default: TimerReload = 0x86; / 2048/fc = 0x01 = 151 us break; WriteRawRC(RegPage,0x00); WriteRawRC(RegFIFOLevel,0x1A); SetBitMask(RegChannelRedundancy, 0x04); WriteRawRC(RegTimerReload, TimerReload); WriteRawRC(RegTimerControl, 0x06);*/ SetBitMask(RegControl,0x01); WriteRawRC(RegCommand, 0x00); WriteRawRC(RegInterruptEn, 0x81); WriteRawRC(RegInterruptRq, 0x3F); WriteRawRC(RegInterruptEn, 0x38 | 0x80); for (i=0; iMfLength; i+) WriteRawRC(RegFIFOData,pi-MfDatai); _nop_();_nop_();_nop_();_nop_();_nop_(); WriteRawRC(RegCommand, PCD_TRANSCEIVE); / start to send command to label i = 0xa000; do n = ReadRawRC(RegInterruptRq); i-; while ( (i!=0) & !(n&waitFor) );/等待发送完毕 if (!recebyte) if (n & 0x10) status = MI_OK; WriteRawRC(RegInterruptEn,0x10); WriteRawRC(RegTimerControl,0x00); WriteRawRC(RegCommand,PCD_IDLE); ClearBitMask(RegCoderControl, 0x80); return status; else if (i!=0) & (n&0x08) if ( !(ReadRawRC(RegErrorFlag) & 0x0C) ) n = ReadRawRC(RegFIFOLength); pi-MfLength = n*8; for (i=0; iMfDatai = ReadRawRC(RegFIFOData); _nop_();_nop_();_nop_();_nop_();_nop_(); if (pi-MfData0 = 0)/没有错误标志 status = MI_OK; WriteRawRC(RegInterruptEn,0x10); WriteRawRC(RegTimerControl,0x00); WriteRawRC(RegCommand,PCD_IDLE); ClearBitMask(RegCoderControl, 0x80); return status; /开启天线 /每次启动或关闭天险发射之间应至少有1ms的间隔/char PcdAntennaOn() unsigned char i; i = ReadRawRC(RegTxControl); if (i & 0x03) return MI_OK; else SetBitMask(RegTxControl, 0x03); return MI_OK; char ISO15693_Transceive1(struct TranSciveBuffer *pi)bit recebyte = 0; char status = MI_COM_ERR; unsigned char n,waitFor,TimerReload; unsigned int i; switch (pi-MfCommand) case PCD_TRANSMIT: waitFor = 0x10; break; default: waitFor = 0x28; recebyte=1; break; switch (pi-MfData1) case ISO15693_STAY_QUIET: TimerReload = 0x04; / 2048/fc = 0x01 = 151 us break; case ISO15693_SELECT: case ISO15693_RESET_TO_READY: TimerReload = 0x0F; / 2048/fc = 0x01 = 151 us break; case ISO15693_LOCK_AFI: case ISO15693_LOCK_DSFID: case ISO15693_LOCK_BLOCK: case ISO15693_WRITE_SINGLE_BLOCK: case ISO15693_WRITE_MULTIPLE_BLOCKS: case ISO15693_WRITE_AFI: case ISO15693_WRITE_DSFID: TimerReload = 0x29; / 2048/fc = 0x01 = 151 us break; case ISO15693_READ_SINGLE_BLOCK: TimerReload = 0x17; / 2048/fc = 0x01 = 151 us break; case ISO15693_INVENTORY: TimerReload = 0x1F; / 2048/fc = 0x01 = 151 us break; case ISO15693_GET_SYSTEM_INFO: TimerReload = 0x25; / 2048/fc = 0x01 = 151 us break; case ISO15693_GET_MULTIPLE_BLOCK_SECURITY: TimerReload = 0x40;/(0x04+(cmdcmdlen-1+0x01)*0x02 + 0x04 + 0x01; / 2048/fc = 0x01 = 151 us break; / (0x04 + cmdcmdlen - 1)*0x02 - Time for all receivedBytes, 0x04 - Time bevore and after response, 0x01 additional case ISO15693_READ_MULTIPLE_BLOCKS: TimerReload = 0x40;/(0x04+0x04*(cmdcmdlen-1+0x01)*0x02 + 0x04 + 0x01; / 2048/fc = 0x01 = 151 us break; default: TimerReload = 0x86; / 2048/fc = 0x01 = 151 us break; WriteRawRC(RegPage,0x00); WriteRawRC(RegFIFOLevel,0x1A); SetBitMask(RegChannelRedundancy, 0x04); WriteRawRC(RegTimerReload, TimerReload); WriteRawRC(RegTimerControl, 0x06); SetBitMask(RegControl,0x01); WriteRawRC(RegCommand, 0x00); WriteRawRC(RegInterruptEn, 0x81); WriteRawRC(RegInterruptRq, 0x3F); WriteRawRC(RegInterruptEn, 0x38 | 0x80); for (i=0; iM
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 儿童色彩创作课件大纲
- 课件智能AI教学课件
- 广东会计初级自考试题及答案
- 历年护理考试题及答案
- 礼仪学堂考试题及答案
- 乐器辅助考试题及答案
- 广东房屋构造自考试题及答案
- 康复基层考试题及答案
- 钼钨冶炼辅料制备工适应性考核试卷及答案
- 信息安全管理员职业考核试卷及答案
- 旅行社劳动合同范文3篇
- 2025年污水处理及其再生利用行业研究报告及未来行业发展趋势预测
- 证券投资学课件吴晓求
- 摩托车整车采购合同范本
- 托管班合伙人合同协议书
- 2025劳动合同补充协议
- 社区节水节电知识培训课件
- 防火墙行业知识培训课件
- 2025版全新升级二手房买卖合同模板下载
- 乡镇执法证考试题及答案
- 2025年监理工程师继续教育试卷及答案
评论
0/150
提交评论