ImageVerifierCode 换一换
格式:DOCX , 页数:31 ,大小:22.30KB ,
资源ID:4289811      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/4289811.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(智能卡RC500读卡程序.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

智能卡RC500读卡程序.docx

1、智能卡RC500读卡程序#include MyDefine.c#include MfErrNo.h#include MfRc500R.h#include MfRcuC.h#include ExternVariableDef.c#define D_data extern void Delay_10us(uchar );/unsigned char idata MLastSelectedSnr5 ;unsigned char idata MRcvBuffer16 ;unsigned char idata MSndBuffer18;static MfCmdInfo idata MInfo ;exte

2、rn void Delay_ms(unsigned int);bit haveset;/*名称:s_data *功能:发送1字节HEX *参数: */unsigned char Mf500PcdConfig(void) unsigned char D_data status = MI_RESETERR; unsigned int D_data ii=5000; unsigned char D_data st_data; do RST_RC500=1; / reset RC500 Delay_10us(200); / wait RST_RC500=0; / clear reset pin Del

3、ay_10us(200); / wait st_data=ReadRC(RegPage); if (st_data=0x80) break; while(-ii); ii=5000; do WriteRC(RegPage,0x00); / Dummy access in order to determine the bus st_data= ReadRC(RegCommand); if (!st_data) break; while(-ii); / configuration / necessary read access / after first write access, the ret

4、urned value / should be zero = interface recognized if (st_data) status = MI_INTERFACEERR; else status = 0; if(!status) XBYTERegClockQControl=0x0; XBYTERegClockQControl=0x40; Delay_10us(5); ClearBitMask(RegClockQControl,0x40); / clear bit ClkQCalib for XBYTERegBitPhase=0xAd; XBYTERegRxThreshold=0xFF

5、; XBYTERegRxControl2=01; XBYTERegFIFOLevel=0x1A; / initialize to 26d XBYTERegTimerControl=0x02; / TStopRxEnd=0,TStopRxBeg=0, XBYTERegIRqPinConfig=0x3; / interrupt active low enable status=PcdRfReset(1); / Rf - reset and enable output driver return status;unsigned char Mf500PiccRequest(unsigned char

6、req_code, unsigned char *atq) unsigned char D_data status = MI_OK; PcdSetTmo(2); WriteRC(RegChannelRedundancy,0x03); / RxCRC and TxCRC disable, parity enable ClearBitMask(RegControl,0x08); / disable crypto 1 unit WriteRC(RegBitFraming,0x07); / set TxLastBits to 7 ResetInfo(); MSndBuffer0 = req_code;

7、 MInfo.nBytesToSend = 1; status = PcdSingleResponseCmd(PCD_TRANSCEIVE); if (status) / error occured atq0 = 0; else if (MInfo.nBitsReceived != 16) / 2 bytes expected atq0 = 0; status = MI_BITCOUNTERR; else status = MI_OK; memcpy(atq,MRcvBuffer,2); return status;unsigned char Mf500PiccCascSelect(unsig

8、ned char select_code,unsigned char *snr, unsigned char *sak) unsigned char D_data status = MI_OK;/ if (CardSortChar=102)/1102卡不需要/ return 0; PcdSetTmo(2); WriteRC(RegChannelRedundancy,0x0F); / RxCRC,TxCRC, Parity enable ClearBitMask(RegControl,0x08); / disable crypto 1 unit ResetInfo(); MSndBuffer0

9、= select_code; MSndBuffer1 = 0x70; / number of bytes send memcpy(MSndBuffer+2,snr,4); MSndBuffer6 = MSndBuffer2 MSndBuffer3 MSndBuffer4 MSndBuffer5; MInfo.nBytesToSend = 7; status = PcdSingleResponseCmd(PCD_TRANSCEIVE); sak0 = 0; if (status = MI_OK) / no timeout occured if (MInfo.nBitsReceived != 8)

10、 / last byte is not complete status = MI_BITCOUNTERR; else sak0 = MRcvBuffer0;/ memcpy(MLastSelectedSnr,snr,4); return status;unsigned char Mf500PiccAnticoll (unsigned char bcnt, unsigned char *snr) return Mf500PiccCascAnticoll(0x93,bcnt,snr); / first cascade levelunsigned char Mf500PiccCascAnticoll

11、 (unsigned char select_code,unsigned char bcnt,unsigned char *snr) unsigned char D_data status = MI_OK; unsigned char D_data snr_in4; / copy of the input parameter snr unsigned char D_data nbytes = 0; / how many bytes received unsigned char D_data nbits = 0; / how many bits received unsigned char D_

12、data complete = 0; / complete snr recived unsigned char D_data i = 0; unsigned char D_data byteOffset = 0; unsigned char D_data snr_crc; / check byte calculation unsigned char D_data snr_check; unsigned char D_data dummyShift1; / dummy byte for snr shift unsigned char D_data dummyShift2; / dummy byt

13、e for snr shift/ if (CardSortChar=102)/1102卡不需要/ return 0; PcdSetTmo(2); memcpy(snr_in,snr,4); WriteRC(RegDecoderControl,0x28); / ZeroAfterColl aktivieren ClearBitMask(RegControl,0x08); / disable crypto 1 unit complete=0; while (!complete & (status = MI_OK) ) ResetInfo(); WriteRC(RegChannelRedundanc

14、y,0x03); / RxCRC and TxCRC disable, parity enable nbits = bcnt % 8; if (nbits) WriteRC(RegBitFraming,nbits 4 | nbits); / TxLastBits/RxAlign auf nb_bi nbytes = bcnt / 8 + 1; if (nbits = 7 ) MInfo.cmd = PICC_ANTICOLL1; / pass command flag to ISR WriteRC(RegBitFraming,nbits); / reset RxAlign to zero el

15、se nbytes = bcnt / 8; MSndBuffer0 = select_code; MSndBuffer1 = 0x20 + (bcnt/8) 4) + nbits; /number of bytes send memcpy (MSndBuffer+2,snr_in,nbytes); MInfo.nBytesToSend = 2 + nbytes; status = PcdSingleResponseCmd(PCD_TRANSCEIVE); / in order to solve an inconsistancy in the anticollision sequence / (

16、will be solved soon), the case of 7 bits has to be treated in a / separate way if (nbits = 7) / reorder received bits dummyShift1 = 0x00; for (i = 0; i (i+1) | (MRcvBufferi (7-i); dummyShift1 = dummyShift2; MInfo.nBitsReceived -= MInfo.nBytesReceived; / subtract received parity bits / recalculation

17、of collision position if ( MInfo.collPos ) MInfo.collPos += 7 - (MInfo.collPos + 6) / 9; if ( status = MI_OK | status = MI_COLLERR) / no other occured / R e s p o n s e P r o c e s s i n g if ( MInfo.nBitsReceived != 40) / not 5 bytes answered status = MI_BITCOUNTERR; else byteOffset = 0; if ( nbits

18、 != 0 ) / last byte was not complete snr_innbytes - 1 = snr_innbytes - 1 | MRcvBuffer0; byteOffset = 1; for ( i =0; i 0) nms=1000*nms; Delay_10us(nms); SetBitMask(RegTxControl,0x03); return status;void PcdSetTmo(unsigned char tmoLength) switch(tmoLength) / timer clock frequency 13,56 MHz case 1: / s

19、hort timeout (1,0 ms) WriteRC(RegTimerClock,0x07); / TAutoRestart=0,TPrescale=128 WriteRC(RegTimerReload,0x6a);/ TReloadVal = h6a =106(dec) break; case 2: / medium timeout (1,5 ms) WriteRC(RegTimerClock,0x07); / TAutoRestart=0,TPrescale=128 WriteRC(RegTimerReload,0xa0);/ TReloadVal = ha0 =160(dec) b

20、reak; case 3: / long timeout (6 ms) WriteRC(RegTimerClock,0x09); / TAutoRestart=0,TPrescale=4*128 WriteRC(RegTimerReload,0xa0);/ TReloadVal = ha0 =160(dec) break; case 4: / long timeout (19.2 ms) WriteRC(RegTimerClock,0x0a); / TAutoRestart=0,TPrescale=4*128 WriteRC(RegTimerReload,0xff);/ TReloadVal

21、= ff =255(dec) break; case 5: / long timeout (38.4 ms) WriteRC(RegTimerClock,0x0b); / TAutoRestart=0,TPrescale=4*4*128 WriteRC(RegTimerReload,0xff);/ TReloadVal = ff =255(dec) break; case 6: / long timeout (76.8 ms) WriteRC(RegTimerClock,0x0c); / TAutoRestart=0,TPrescale=2*4*4*128 WriteRC(RegTimerRe

22、load,0xff);/ TReloadVal = ff =255(dec) break; case 7: / long timeout (153.6 ms) WriteRC(RegTimerClock,0x0d); / TAutoRestart=0,TPrescale=2*2*4*4*128 WriteRC(RegTimerReload,0xff);/ TReloadVal = ff =255(dec) break; default: / short timeout (1,0 ms) WriteRC(RegTimerClock,0x07); / TAutoRestart=0,TPrescal

23、e=128 WriteRC(RegTimerReload,tmoLength);/ TReloadVal = tmoLength break; void ResetInfo(void) MInfo.cmd = 0; MInfo.status = MI_OK; MInfo.irqSource = 0; MInfo.nBytesSent = 0; MInfo.nBytesToSend = 0; MInfo.nBytesReceived = 0; MInfo.nBitsReceived = 0; MInfo.collPos = 0; unsigned char PcdSingleResponseCm

24、d(unsigned char cmd) unsigned char D_data status = MI_OK; unsigned char D_data tmpStatus ; unsigned char D_data lastBits; unsigned char D_data irqEn = 0x00; unsigned char D_data waitFor = 0x00; unsigned char D_data timerCtl = 0x00; unsigned int D_data ii=50000; WriteRC(RegInterruptEn,0x7F); / disabl

25、e all interrupts WriteRC(RegInterruptRq,0x7F); / reset interrupt requests WriteRC(RegCommand,PCD_IDLE); / terminate probably running command FlushFIFO(); / flush FIFO buffer haveset=1; / initialising the ISR-Function pointer for mifare / protocol - do this after initialising the MpXXXX variables MInfo.irqSource = 0x0; / reset interrupt flags / depending on the command code, appropria

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1