代码还是代码Modbus-rtu Crc半字节校验
本帖最后由 xcodes 于 2012-9-29 09:21 编辑static constUSHORT crc16L[] = {
0x0000,0xc0c1,0xc181,0x0140,
0xc301,0x03c0,0x0280,0xc241,
0xc601,0x06c0,0x0780,0xc741,
0x0500,0xc5c1,0xc481,0x0440,
};
static constUSHORT crc16H[] = {
0x0000,0xcc01,0xd801,0x1400,
0xf001,0x3c00,0x2800,0xe401,
0xa001,0x6c00,0x7800,0xb401,
0x5000,0x9c01,0x8801,0x4400,
};
USHORT usMBCRC16( UCHAR * pucFrame, USHORT usLen )
{
USHORT Crc;
UCHAR Dat;
Crc = 0xffff;
while(usLen--)
{
Dat=*pucFrame++;
Dat^=Crc;
Crc>>=8;
Crc ^= crc16L;
Crc ^= crc16H[(Dat>>4)&0x0f];
}
return(Crc);
}
顶下{:lol:}{:lol:} 顶起来!!!!1 找了好长时间了啊
页:
[1]