[密码交流] 请各位帮助看一下,多谢啦

[复制链接]
2502|1
 楼主| onixya 发表于 2013-5-9 10:31 | 显示全部楼层 |阅读模式
  最近拿到一个通讯协议去做。CRC16,约好是LSB,多项式8408,初始值FFFF。我的程序是大致这样的:
unsigned  char Tx_Bytes[10]={0x11,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
void do_crc(unsigned char *message, unsigned int len)
{
    int i, j;
    unsigned int crc_reg = 0xffff;
    unsigned char  index;
    unsigned int to_xor;
      
    for (i = 0; i < len; i++)
    {
        index = (crc_reg ^ message[i]) & 0xff;
        to_xor = index;      
        for (j = 0; j < 8; j++)
        {
            if (to_xor & 0x0001)
                to_xor = (to_xor >> 1) ^ 0x8408;
            else
                to_xor >>= 1;           
        }
        crc_reg = (crc_reg >> 8) ^ to_xor;
    }
  // return crc_reg;

                        Tx_Bytes[8]=crc_reg&0xff;
                        Tx_Bytes[9]=crc_reg>>8;   
}
这样吧数据的最后2个作为CRC的结果,但是和对方通讯总是接不上,CRC校验有问题,麻烦各位帮看看这段程序,是我这边有问题不?多谢多谢~
 楼主| onixya 发表于 2013-5-9 20:15 | 显示全部楼层
自己顶下,已经解决了,不过是在看着菜农的帖子摸索着完成的。
菜农大叔有时间把分拿走哈~~多谢啦
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

8

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部