CPU卡程序设计实例(二十一)4字节随机数读取

来源:互联网 发布:It 门槛 编辑:程序博客网 时间:2024/06/03 17:16

/*******************************************

函数名称:Get_RandNum4Byte

函数功能:从卡或者ESAM取4字节随机数

输入参数:无

输出参数:*pcRandBuff

描述:发命令头-接收到的数据等于命令头中的第二字节后,接下来的4个字节是随机数

*******************************************/

unsigned char *Get_RandNum4Byte(void)

{

unsigned char cRandBuff[6]={0};

unsigned char *pcRandBuff;

unsigned int itemp;

cCommandLen=0x05;

TxAndRxBuff[0]=0x00;

TxAndRxBuff[1]=0x84;

TxAndRxBuff[2]=0x00;

TxAndRxBuff[3]=0x00;

TxAndRxBuff[4]=0x04;

SendCommandHead_Pro();

if(CardORESAM&CardWorkFlag)

{

for(itemp=0;itemp<6;itemp++)

{

cRandBuff[itemp]=CardReceChar();

if(ErrorRWBIT&CardError) goto GetRandNum4ByteEnd;

}

}

else

{

for(itemp=0;itemp<6;itemp++)

{

cRandBuff[itemp]=EsamReceChar();

if(ErrorRWBIT&CardError) goto GetRandNum4ByteEnd;

}

}

if((cRandBuff[4]!=0x90)&&(cRandBuff[5]!=0x00))

{

CardError=ErrorRandBIT|CardError;

}

GetRandNum4ByteEnd:

delay_ms2M(5);

pcRandBuff=&cRandBuff[0];

return pcRandBuff;

}


0 0
原创粉丝点击