C
caixike
Unregistered / Unconfirmed
GUEST, unregistred user!
/*****************************************************************************************************
* 函数名称:unsigned char SELCrc8( unsigned char accum,unsigned char *pbuf,unsigned int count )
** 功 能: 计算8位CRC
* 入口参数:unsigned char accum初值 ,unsigned char *ptr数据指针,unsigned int count 数据长度
* 出口参数: unsigned char 8位CRC值
******************************************************************************************************/
extern "C" unsigned char FAR PASCAL EXPORT SELCrc8( unsigned char accum,unsigned char *pbuf,unsigned int count )
{
unsigned int i;
unsigned int j;
for ( i = 0 ; i<count ; i++)
{
accum = accum ^ *pbuf;
for ( j = 0 ; j<8 ; j++ )
{
if ( accum & 0x80 )
{
accum = ( accum << 1 ) ^ 0x1D;
}
else
{
accum = accum << 1 ;
}
}
pbuf++;
}
return ( accum );
}
调用举例:
SendCrc = SELCrc8(0x0a,&SendBuff[0],20) ;用0AH的初值,计算SendBuff数据序列中,20个字节的CRC8PWD,结果送入SendCrc。
告知:EMail:caixike@163.com 先谢谢!!!
* 函数名称:unsigned char SELCrc8( unsigned char accum,unsigned char *pbuf,unsigned int count )
** 功 能: 计算8位CRC
* 入口参数:unsigned char accum初值 ,unsigned char *ptr数据指针,unsigned int count 数据长度
* 出口参数: unsigned char 8位CRC值
******************************************************************************************************/
extern "C" unsigned char FAR PASCAL EXPORT SELCrc8( unsigned char accum,unsigned char *pbuf,unsigned int count )
{
unsigned int i;
unsigned int j;
for ( i = 0 ; i<count ; i++)
{
accum = accum ^ *pbuf;
for ( j = 0 ; j<8 ; j++ )
{
if ( accum & 0x80 )
{
accum = ( accum << 1 ) ^ 0x1D;
}
else
{
accum = accum << 1 ;
}
}
pbuf++;
}
return ( accum );
}
调用举例:
SendCrc = SELCrc8(0x0a,&SendBuff[0],20) ;用0AH的初值,计算SendBuff数据序列中,20个字节的CRC8PWD,结果送入SendCrc。
告知:EMail:caixike@163.com 先谢谢!!!