// One Wire CRC
static uns8 OneWireCrc;
// Updates crc at OneWireCrc variable, parameter value is an input data byte
void UpdateOneWireCrc( uns8 value @ W )
{
OneWireCrc ^= value;
#pragma update_RP 0 /* OFF */
value = 0;
if ( OneWireCrc.7 )
value ^= 0x8c; // 0x8C is reverse polynomial representation
if ( OneWireCrc.6 ) // (normal is 0x31)
value ^= 0x46;
if ( OneWireCrc.5 )
value ^= 0x23;
if ( OneWireCrc.4 )
value ^= 0x9d;
if ( OneWireCrc.3 )
value ^= 0xc2;
if ( OneWireCrc.2 )
value ^= 0x61; // …
if ( OneWireCrc.1 ) // 1 instruction
value ^= 0xbc; // 1 instruction
if ( OneWireCrc.0 ) // 1 instruction
value ^= 0x5e; // 1 instruction
OneWireCrc = value; // 1 instruction
#pragma update_RP 1 /* ON */
}