您的位置:首页 > 其它

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

2017-04-28 19:48 183 查看
/*******************************************

函数名称: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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息