Pular para o conteúdo principal

📄 Baixar este manual em PDF

Algoritmo de Cálculo do Checksum

O checksum é calculado utilizando o método de tabela descrito na Dallas APPLICATION NOTE 27: Understanding and Using Cyclic Redundancy Checks with Dallas Semiconductor iButton Products.

Podem ser utilizados os seguintes algoritmos para calcular o checksum com o polinómio x⁸ + x⁵ + x⁴ + 1 (linguagem C):

Versão 1:

1 U8 CRC8 (U8 b, U8 crc)
2 {
3 U8 i = 8;
4 do {
5 if ( (b ^ crc) & 0x01) {
6 crc = ( (crc ^ 0x18) >> 1 ) | 0x80;
7 } else {
8 crc >>= 1;
9 }
10 b >>= 1;
11 } while (--i);
12 return crc;
13 }

Versão 2:

1 U8 CRC8(U8 data, U8 crc)
2 {
3 U8 i = data ^ crc;
4 crc = 0;
5 if(i & 0x01) crc ^= 0x5e;
6 if(i & 0x02) crc ^= 0xbc;
7 if(i & 0x04) crc ^= 0x61;
8 if(i & 0x08) crc ^= 0xc2;
9 if(i & 0x10) crc ^= 0x9d;
10 if(i & 0x20) crc ^= 0x23;
11 if(i & 0x40) crc ^= 0x46;
12 if(i & 0x80) crc ^= 0x8c;
13 return crc;
14 }