CRC8 表记录

int sht75_crc_table[] =
{
0x00,0x31,0x62,0x53,0xc4,0xf5,0xa6,0x97,0xb9,0x88,0xdb,0xea,0x7d,0x4c,0x1f,0x2e,
0x43,0x72,0x21,0x10,0x87,0xb6,0xe5,0xd4,0xfa,0xcb,0x98,0xa9,0x3e,0x0f,0x5c,0x6d,
0x86,0xb7,0xe4,0xd5,0x42,0x73,0x20,0x11,0x3f,0x0e,0x5d,0x6c,0xfb,0xca,0x99,0xa8,
0xc5,0xf4,0xa7,0x96,0x01,0x30,0x63,0x52,0x7c,0x4d,0x1e,0x2f,0xb8,0x89,0xda,0xeb,
0x3d,0x0c,0x5f,0x6e,0xf9,0xc8,0x9b,0xaa,0x84,0xb5,0xe6,0xd7,0x40,0x71,0x22,0x13,
0x7e,0x4f,0x1c,0x2d,0xba,0x8b,0xd8,0xe9,0xc7,0xf6,0xa5,0x94,0x03,0x32,0x61,0x50,
0xbb,0x8a,0xd9,0xe8,0x7f,0x4e,0x1d,0x2c,0x02,0x33,0x60,0x51,0xc6,0xf7,0xa4,0x95,
0xf8,0xc9,0x9a,0xab,0x3c,0x0d,0x5e,0x6f,0x41,0x70,0x23,0x12,0x85,0xb4,0xe7,0xd6,
0x7a,0x4b,0x18,0x29,0xbe,0x8f,0xdc,0xed,0xc3,0xf2,0xa1,0x90,0x07,0x36,0x65,0x54,
0x39,0x08,0x5b,0x6a,0xfd,0xcc,0x9f,0xae,0x80,0xb1,0xe2,0xd3,0x44,0x75,0x26,0x17,
0xfc,0xcd,0x9e,0xaf,0x38,0x09,0x5a,0x6b,0x45,0x74,0x27,0x16,0x81,0xb0,0xe3,0xd2,
0xbf,0x8e,0xdd,0xec,0x7b,0x4a,0x19,0x28,0x06,0x37,0x64,0x55,0xc2,0xf3,0xa0,0x91,
0x47,0x76,0x25,0x14,0x83,0xb2,0xe1,0xd0,0xfe,0xcf,0x9c,0xad,0x3a,0x0b,0x58,0x69,
0x04,0x35,0x66,0x57,0xc0,0xf1,0xa2,0x93,0xbd,0x8c,0xdf,0xee,0x79,0x48,0x1b,0x2a,
0xc1,0xf0,0xa3,0x92,0x05,0x34,0x67,0x56,0x78,0x49,0x1a,0x2b,0xbc,0x8d,0xde,0xef,
0x82,0xb3,0xe0,0xd1,0x46,0x77,0x24,0x15,0x3b,0x0a,0x59,0x68,0xff,0xce,0x9d,0xac
};

byte[] crc8_tab =
{ (byte) 0, (byte) 94, (byte)188, (byte)226, (byte) 97, (byte) 63, (byte)221, (byte)131, (byte)194, (byte)156, (byte)126, (byte) 32, (byte)163, (byte)253, (byte) 31, (byte) 65,
(byte)157, (byte)195, (byte) 33, (byte)127, (byte)252, (byte)162, (byte) 64, (byte) 30, (byte) 95, (byte) 1, (byte)227, (byte)189, (byte) 62, (byte) 96, (byte)130, (byte)220,
(byte) 35, (byte)125, (byte)159, (byte)193, (byte) 66, (byte) 28, (byte)254, (byte)160, (byte)225, (byte)191, (byte) 93, (byte) 3, (byte)128, (byte)222, (byte) 60, (byte) 98,
(byte)190, (byte)224, (byte) 2, (byte) 92, (byte)223, (byte)129, (byte) 99, (byte) 61, (byte)124, (byte) 34, (byte)192, (byte)158, (byte) 29, (byte) 67, (byte)161, (byte)255,
(byte) 70, (byte) 24, (byte)250, (byte)164, (byte) 39, (byte)121, (byte)155, (byte)197, (byte)132, (byte)218, (byte) 56, (byte)102, (byte)229, (byte)187, (byte) 89, (byte) 7,
(byte)219, (byte)133, (byte)103, (byte) 57, (byte)186, (byte)228, (byte) 6, (byte) 88, (byte) 25, (byte) 71, (byte)165, (byte)251, (byte)120, (byte) 38, (byte)196, (byte)154,
(byte)101, (byte) 59, (byte)217, (byte)135, (byte) 4, (byte) 90, (byte)184, (byte)230, (byte)167, (byte)249, (byte) 27, (byte) 69, (byte)198, (byte)152, (byte)122, (byte) 36,
(byte)248, (byte)166, (byte) 68, (byte) 26, (byte)153, (byte)199, (byte) 37, (byte)123, (byte) 58, (byte)100, (byte)134, (byte)216, (byte) 91, (byte) 5, (byte)231, (byte)185,
(byte)140, (byte)210, (byte) 48, (byte)110, (byte)237, (byte)179, (byte) 81, (byte) 15, (byte) 78, (byte) 16, (byte)242, (byte)172, (byte) 47, (byte)113, (byte)147, (byte)205,
(byte) 17, (byte) 79, (byte)173, (byte)243, (byte)112, (byte) 46, (byte)204, (byte)146, (byte)211, (byte)141, (byte)111, (byte) 49, (byte)178, (byte)236, (byte) 14, (byte) 80,
(byte)175, (byte)241, (byte) 19, (byte) 77, (byte)206, (byte)144, (byte)114, (byte) 44, (byte)109, (byte) 51, (byte)209, (byte)143, (byte) 12, (byte) 82, (byte)176, (byte)238,
(byte) 50, (byte)108, (byte)142, (byte)208, (byte) 83, (byte) 13, (byte)239, (byte)177, (byte)240, (byte)174, (byte) 76, (byte) 18, (byte)145, (byte)207, (byte) 45, (byte)115,
(byte)202, (byte)148, (byte)118, (byte) 40, (byte)171, (byte)245, (byte) 23, (byte) 73, (byte) 8, (byte) 86, (byte)180, (byte)234, (byte)105, (byte) 55, (byte)213, (byte)139,
(byte) 87, (byte) 9, (byte)235, (byte)181, (byte) 54, (byte)104, (byte)138, (byte)212, (byte)149, (byte)203, (byte) 41, (byte)119, (byte)244, (byte)170, (byte) 72, (byte) 22,
(byte)233, (byte)183, (byte) 85, (byte) 11, (byte)136, (byte)214, (byte) 52, (byte)106, (byte) 43, (byte)117, (byte)151, (byte)201, (byte) 74, (byte) 20, (byte)246, (byte)168,
(byte)116, (byte) 42, (byte)200, (byte)150, (byte) 21, (byte) 75, (byte)169, (byte)247, (byte)182, (byte)232, (byte) 10, (byte) 84, (byte)215, (byte)137, (byte)107, (byte) 53
};

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
crc8校验的原理,程序和检验软件 CRC即循环冗余校验码(Cyclic Redundancy Check):是数据通信领域中最常用的一种差错校验码,其特征是信息字段和校验字段的长度可以任意选定。 CRC校验可以简单地描述为:例如我们要发送一些数据(信息字段),为了避免一些干扰以及在接收端的对读取的数据进行判断是否接受的是真实的数据,这时我们就要加上校验数据(即CRC校验码),来判断接收的数据是否正确。在发送端,根据要传送的k位二进制码序列,以一定的规则(CRC校验有不同的规则。这个规则,在差错控制理论中称为“生成多项式”。)产生一个校验用的r位校验码(CRC码),附在原始信息后边,构成一个新的二进制码序列数共k+r位,然后发送出去。在接收端,根据信息码和CRC码之间所遵循的规则(即与发送时生成CRC校验码相同的规则)进行检验,校验采用计算机的模二除法,即除数和被除数(即生成多项式)做异或运算,进行异或运算时除数和被除数最高位对齐,进行按位异或运算,若最终的数据能被除尽,则传输正确;否则,传输错误。 CRC8即最终生成的CRC校验码为1字节,其生成多项式,生成多项式为g(x)=x8+x5+x4+1,相当于g(x)=1•x8+0•x7+0•x6+1•x5+1•x4+0•x3+0•x2+0•x1+1•x0,即对应的二进制数为100110001。 CRC8校验算法: 1.CRC8校验的一般性算法: 例如: 信息字段代码为: 00000001 00000010 ———— 对应m(x)=x8+x 生成多项式为:g(x)=x8+x5+x4+1 ———— 对应g(x)的二进制代码为:100110001 现在我们将要对2字节数据0x0102生成CRC8校验码,并最终将生成的1字节CRC校验码跟在0x0102的后面,即 0x01 02 ##,(##即8为CRC码),最终生成的3字节数据就是经CRC8校验生成的数据。 先计算x8m(x)=x16+x9,对应的2进制数为:100000010 00000000 。可以看到这样运算所得到的结果其实就是将信息字段代码的数左移8位。因为最终要将生成的8位CRC8校验码附在信息字段的后面,所以要将信息字段的数左移8位。最后用x8m(x)得到的二进制数对生成多项式g(x)进行模二运算,最终的余数(其二进制数的位数一定比生成多项式g(x)的位数小)就是所要的CRC8校验码。 100000010 00000000 ^ 100110001 --------------------------- 000110011 00000000 ^ 100110 001 --------------------------- 010101 00100000 ^ 10011 0001 --------------------------- 00110 00110000 ^ 100 110001 --------------------------- 010 11110100 ^ 10 0110001 --------------------------- 00 10010110 对x8m(x)做模二运算取余得10010110(0x96),这个8位的二进制数就是CRC8校验码。所以,经CRC8校验后研发送的数据就是0x010296。 2.CRC8校验在DS18B20中的应用: 以上分析的是常规的CRC8校验方法。在DS18B20中,有两处用到CRC。一是DS18B20的8字节的序列号,最后一字节是前面七个字节的CRC码,这是为了保证序列号的唯一性与正确性;另一个是在DS18B20内部9字节的高速温度存储器,其第9字节是前面8个字节的CRC校验码,这是为了温度数据传输的正确性。而在DS18B20中生成CRC码所用到的方法不同于常规生成算法,它采用的是逆序CRC信息单元编码算法,该CRC的生成是由DS18B20中的多项式寄存器通过其中所包含的移位寄存器以及异或门对输入该多项式寄存器的每一位二进制数做一定的运算所得到的CRC码(可以查看Maxim官网上DS18B20的应用笔记Note27,专门介绍DS18B20CRC详细生成过程)。在此列举两种DS18B20CRC校验的C程序。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值