1、终端向ESAM发送一个字节函数
/**************************************
函数名称:EsamSendChar
函数功能:向Esam发送一个字节
入口参数:cSendChar,要发送的字节
出口参数:无
描述:发送10位,第一位起始位(始终为低),第10位是校验位,
最多发3次,
***************************************/
void EsamSendChar(unsigned char cSendChar)
{
unsigned int iTempTran,iErrCoun;
unsigned int iTemp=cSendChar;
iTemp=iTemp<<1;
iTemp=iTemp&(~BIT0);
CardWorkFlag=~(ICXOR+MXOR)&CardWorkFlag;
PorCheckBit(cSendChar);
if(CardWorkFlag&0x80) iTemp=iTemp|BIT9;
else iTemp=iTemp&(~BIT9);
EsamSDAOutput;
for(iErrCoun=0;iErrCoun<3;iErrCoun++)
{
for(iTempTran=0;iTempTran<10;iTempTran++)
{
if(iTemp&0x01)
{
EsamSDAOutputHigh;
}
else
{
EsamSDAOutputLow;
}
iTemp=iTemp>>0x01;
Delay1ETU();
}
EsamSDAInput;
Delay05XETU();
//发送OK
if(EsamSDAInputCheck)
{
Delay1ETU();
Delay05XETU();
goto EsamSendCharOk;
}
//发送错误
else
{
CardError=ErrorRWBIT|CardError;
Delay1ETU();
EsamSDAOutput;
Delay1ETU();
}
}
EsamSendCharOk:;
}
2、终端向CPU卡发送一个字节函数
/**************************************
函数名称:CardSendChar
函数功能:向CPU卡发送一字节
入口参数:cSendChar,要发送的字节
出口参数:无
描述:发送10位,第一位起始位(始终为低),第10位是校验位,
最多发3次,
***************************************/
void CardSendChar(unsigned char cSendChar)
{
unsigned int iTempTran,iErrCoun;
unsigned int iTemp=cSendChar;
iTemp=iTemp
<<1;iTemp=iTemp&(~BIT0);
//清除校验位,然后计算校验位
CardWorkFlag=~(ICXOR+MXOR)&CardWorkFlag;
PorCheckBit(cSendChar);
if(CardWorkFlag&0x80) iTemp=iTemp|BIT9;
else iTemp=iTemp&(~BIT9);
//开始数据发送
CardSDAOutput;
for(iErrCoun=0;iErrCoun<3;iErrCoun++)
{
//发送1个字节,8位
for(iTempTran=0;iTempTran<10;iTempTran++)
{
if(iTemp&0x01)
{
CardSDAOutputHigh;
}
else
{
CardSDAOutputLow;
}
iTemp=iTemp>>0x01;
Delay1ETU();
}
CardSDAInput;
Delay05XETU();
//发送OK
if(CardSDAInputCheck)
{
Delay1ETU();
Delay05XETU();
goto SendCharOk;
}
//发送错误
else
{
CardError=ErrorRWBIT|CardError;
Delay1ETU();
CardSDAOutput;
Delay1ETU();
}
}
SendCharOk:;
}
3、待发送字节的偶校验生成函数
/**************************************
函数名称:PorCheckBit
函数功能:计算待发送字符的偶校验
输入参数:cSendChar,要发送的字符
输出参数:无
描述:生成偶校验位
**************************************/
void PorCheckBit(unsigned char cSendChar)
{
unsigned char SendCommandBufBit=cSendChar;
int itemp;
for(itemp=0;itemp<8;itemp++)
{
if(SendCommandBufBit&0x01)
{
CardWorkFlag=CardWorkFlag^0x80;
}
SendCommandBufBit=SendCommandBufBit>>0x01;
}
}