智能卡RC500读卡程序Word格式文档下载.docx

上传人:b****6 文档编号:17209204 上传时间:2022-11-28 格式:DOCX 页数:31 大小:22.30KB
下载 相关 举报
智能卡RC500读卡程序Word格式文档下载.docx_第1页
第1页 / 共31页
智能卡RC500读卡程序Word格式文档下载.docx_第2页
第2页 / 共31页
智能卡RC500读卡程序Word格式文档下载.docx_第3页
第3页 / 共31页
智能卡RC500读卡程序Word格式文档下载.docx_第4页
第4页 / 共31页
智能卡RC500读卡程序Word格式文档下载.docx_第5页
第5页 / 共31页
点击查看更多>>
下载资源
资源描述

智能卡RC500读卡程序Word格式文档下载.docx

《智能卡RC500读卡程序Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《智能卡RC500读卡程序Word格式文档下载.docx(31页珍藏版)》请在冰豆网上搜索。

智能卡RC500读卡程序Word格式文档下载.docx

RST_RC500=1;

//resetRC500

Delay_10us(200);

//wait

RST_RC500=0;

//clearresetpin

st_data=ReadRC(RegPage);

if(st_data==0x80)break;

}while(--ii);

ii=5000;

do

WriteRC(RegPage,0x00);

//Dummyaccessinordertodeterminethebus

st_data=ReadRC(RegCommand);

if(!

st_data)break;

//configuration

//necessaryreadaccess

//afterfirstwriteaccess,thereturnedvalue

//shouldbezero==>

interfacerecognized

if(st_data)

status=MI_INTERFACEERR;

else

status=0;

if(!

status)

XBYTE[RegClockQControl]=0x0;

XBYTE[RegClockQControl]=0x40;

Delay_10us(5);

ClearBitMask(RegClockQControl,0x40);

//clearbitClkQCalibfor

XBYTE[RegBitPhase]=0xAd;

XBYTE[RegRxThreshold]=0xFF;

XBYTE[RegRxControl2]=01;

XBYTE[RegFIFOLevel]=0x1A;

//initializeto26d

XBYTE[RegTimerControl]=0x02;

//TStopRxEnd=0,TStopRxBeg=0,

XBYTE[RegIRqPinConfig]=0x3;

//interruptactivelowenable

status=PcdRfReset

(1);

//Rf-resetandenableoutputdriver

}

returnstatus;

}

unsignedcharMf500PiccRequest(unsignedcharreq_code,unsignedchar*atq)

unsignedcharD_datastatus=MI_OK;

PcdSetTmo

(2);

WriteRC(RegChannelRedundancy,0x03);

//RxCRCandTxCRCdisable,parityenable

ClearBitMask(RegControl,0x08);

//disablecrypto1unit

WriteRC(RegBitFraming,0x07);

//setTxLastBitsto7

ResetInfo();

MSndBuffer[0]=req_code;

MInfo.nBytesToSend=1;

status=PcdSingleResponseCmd(PCD_TRANSCEIVE);

if(status)//erroroccured

atq[0]=0;

{

if(MInfo.nBitsReceived!

=16)//2bytesexpected

atq[0]=0;

status=MI_BITCOUNTERR;

}

else

status=MI_OK;

memcpy(atq,MRcvBuffer,2);

returnstatus;

unsignedcharMf500PiccCascSelect(unsignedcharselect_code,unsignedchar*snr,unsignedchar*sak)

//if(CardSortChar==102)//1102卡不需要

//return0;

WriteRC(RegChannelRedundancy,0x0F);

//RxCRC,TxCRC,Parityenable

MSndBuffer[0]=select_code;

MSndBuffer[1]=0x70;

//numberofbytessend

memcpy(MSndBuffer+2,snr,4);

MSndBuffer[6]=MSndBuffer[2]^MSndBuffer[3]^MSndBuffer[4]^MSndBuffer[5];

MInfo.nBytesToSend=7;

sak[0]=0;

if(status==MI_OK)//notimeoutoccured

=8)//lastbyteisnotcomplete

sak[0]=MRcvBuffer[0];

//memcpy(MLastSelectedSnr,snr,4);

unsignedcharMf500PiccAnticoll(unsignedcharbcnt,unsignedchar*snr)

returnMf500PiccCascAnticoll(0x93,bcnt,snr);

//firstcascadelevel

unsignedcharMf500PiccCascAnticoll(unsignedcharselect_code,unsignedcharbcnt,unsignedchar*snr)

unsignedcharD_datasnr_in[4];

//copyoftheinputparametersnr

unsignedcharD_datanbytes=0;

//howmanybytesreceived

unsignedcharD_datanbits=0;

//howmanybitsreceived

unsignedcharD_datacomplete=0;

//completesnrrecived

unsignedcharD_datai=0;

unsignedcharD_databyteOffset=0;

unsignedcharD_datasnr_crc;

//checkbytecalculation

unsignedcharD_datasnr_check;

unsignedcharD_datadummyShift1;

//dummybyteforsnrshift

unsignedcharD_datadummyShift2;

memcpy(snr_in,snr,4);

WriteRC(RegDecoderControl,0x28);

//ZeroAfterCollaktivieren

complete=0;

while(!

complete&

&

(status==MI_OK))

nbits=bcnt%8;

if(nbits)

WriteRC(RegBitFraming,nbits<

<

4|nbits);

//TxLastBits/RxAlignaufnb_bi

nbytes=bcnt/8+1;

if(nbits==7)

MInfo.cmd=PICC_ANTICOLL1;

//passcommandflagtoISR

WriteRC(RegBitFraming,nbits);

//resetRxAligntozero

nbytes=bcnt/8;

MSndBuffer[1]=0x20+((bcnt/8)<

4)+nbits;

//numberofbytessend

memcpy(MSndBuffer+2,snr_in,nbytes);

MInfo.nBytesToSend=2+nbytes;

//inordertosolveaninconsistancyintheanticollisionsequence

//(willbesolvedsoon),thecaseof7bitshastobetreatedina

//separateway

if(nbits==7)

//reorderreceivedbits

dummyShift1=0x00;

for(i=0;

i<

MInfo.nBytesReceived;

i++)

dummyShift2=MRcvBuffer[i];

MRcvBuffer[i]=(dummyShift1>

>

(i+1))|(MRcvBuffer[i]<

(7-i));

dummyShift1=dummyShift2;

MInfo.nBitsReceived-=MInfo.nBytesReceived;

//subtractreceivedparitybits

//recalculationofcollisionposition

if(MInfo.collPos)MInfo.collPos+=7-(MInfo.collPos+6)/9;

if(status==MI_OK||status==MI_COLLERR)//nootheroccured

//ResponseProcessing

if(MInfo.nBitsReceived!

=40)//not5bytesanswered

status=MI_BITCOUNTERR;

byteOffset=0;

if(nbits!

=0)//lastbytewasnotcomplete

snr_in[nbytes-1]=snr_in[nbytes-1]|MRcvBuffer[0];

byteOffset=1;

for(i=0;

(4-nbytes);

snr_in[nbytes+i]=MRcvBuffer[i+byteOffset];

if(status!

=MI_COLLERR)//noerrorandnocollision

//SerChcheck

snr_crc=snr_in[0]^snr_in[1]^snr_in[2]^snr_in[3];

snr_check=MRcvBuffer[4];

if(snr_crc!

=snr_check)

status=MI_SERNRERR;

complete=1;

else//collisionoccured

bcnt=bcnt+MInfo.collPos-nbits;

status=MI_OK;

if(status==MI_OK)

memcpy(snr,MRcvBuffer,4);

ClearBitMask(RegDecoderControl,0x20);

//ZeroAfterColldisable

voidSetBitMask(unsignedintreg,unsignedcharmask)

{

XBYTE[reg]|=mask;

}//clearbitmask

voidClearBitMask(unsignedintreg,unsignedcharmask)

XBYTE[reg]&

=~mask;

voidFlushFIFO(void)

SetBitMask(RegControl,0x01);

voidWriteRC(unsignedintAddress,unsignedcharvalue)

XBYTE[Address]=value;

}//writevalueatthespecified

unsignedcharReadRC(unsignedintAddress)

returnXBYTE[Address];

}//readvalueatthespecified

unsignedcharPcdRfReset(unsignedintnms)

ClearBitMask(RegTxControl,0x03);

//Tx2RF-En,Tx1RF-Endisablen

if(nms>

0)

nms=1000*nms;

Delay_10us(nms);

SetBitMask(RegTxControl,0x03);

voidPcdSetTmo(unsignedchartmoLength)

switch(tmoLength)

{//timerclockfrequency13,56MHz

case1:

//shorttimeout(1,0ms)

WriteRC(RegTimerClock,0x07);

//TAutoRestart=0,TPrescale=128

WriteRC(RegTimerReload,0x6a);

//TReloadVal='

h6a=106(dec)

break;

case2:

//mediumtimeout(1,5ms)

WriteRC(RegTimerReload,0xa0);

ha0=160(dec)

case3:

//longtimeout(6ms)

WriteRC(RegTimerClock,0x09);

//TAutoRestart=0,TPrescale=4*128

case4:

//longtimeout(19.2ms)

WriteRC(RegTimerClock,0x0a);

WriteRC(RegTimerReload,0xff);

ff=255(dec)

case5:

//longtimeout(38.4ms)

WriteRC(RegTimerClock,0x0b);

//TAutoRestart=0,TPrescale=4*4*128

WriteRC(RegTimerReload,0xff);

break;

case6:

//longtimeout(76.8ms)

WriteRC(RegTimerClock,0x0c);

//TAutoRestart=0,TPrescale=2*4*4*128

case7:

//longtimeout(153.6ms)

WriteRC(RegTimerClock,0x0d);

//TAutoRestart=0,TPrescale=2*2*4*4*128

default:

WriteRC(RegTimerClock,0x07);

WriteRC(RegTimerReload,tmoLength);

//TReloadVal=tmoLength

voidResetInfo(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;

}

unsignedcharPcdSingleResponseCmd(unsignedcharcmd)

unsignedcharD_datatmpStatus;

unsignedcharD_datalastBits;

unsignedcharD_datairqEn=0x00;

unsignedcharD_datawaitFor=0x00;

unsignedcharD_datatimerCtl=0x00;

unsignedintD_dataii=50000;

WriteRC(RegInterruptEn,0x7F);

//disableallinterrupts

WriteRC(RegInterruptRq,0x7F);

//resetinterruptrequests

WriteRC(RegCommand,PCD_IDLE);

//terminateprobablyrunningcommand

FlushFIFO();

//flushFIFObuffer

haveset=1;

//initialisingtheISR-Functionpointerformifare

//protocol-dothisafterinitialisingtheMpXXXXvariables

MInfo.irqSource=0x0;

//resetinterruptflags

//dependingonthecommandcode,appropria

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 总结汇报 > 实习总结

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

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