Hi,

I also had the same wish, but then for MicroPascal. I assume mE did not implement this in their libraries. Finally I found (on the web, in this forum or others) a routine for MicroC, for MicroBasic and I derived one myself for MicroPascal.

To help those struggling (as I did) with CRC computation, here they are:

**Basic:**`'=======================================================`

'CRC8 without table

'All you have to do is to initialise the crc variable (to zero or $FFFF)

' and then call the procedure for every byte of your data.

'=======================================================

sub procedure ByteCRC(dim byref CRC as byte,dim CRCData as byte)

dim i,TstBit as byte

For i = 0 to 7 ' Do for all 8 bits in data byte

TstBit = CRC xor CRCData 'CRC.0 xor CRCData.0 ' XOR bit0 of data byte and crc

TstBit = TestBit(TstBit,0)

CRCData = CRCData >> 1 ' Position data byte for next bit test

If TstBit = 1 then ' If test bit not set, just shift CRC

CRC = CRC xor $18 ' If set, account for EXOR feedback

end if ' Shift right the CRC byte

CRC = CRC >> 1 ' CRC bit 0 to bit bucket

CRC.7 = TstBit ' Test bit rotates into CRC bit 7

Next i

end sub

**C:**`byte calc_crc(byte buff[], byte num_vals)`

{

byte shift_reg=0, data_bit, sr_lsb, fb_bit, i, j;

for (i=0; i<num_vals; i++) /* for each byte */

{

for(j=0; j<8; j++) /* for each bit */

{

data_bit = (buff[i]>>j)&0x01;

sr_lsb = shift_reg & 0x01;

fb_bit = (data_bit ^ sr_lsb) & 0x01;

shift_reg = shift_reg >> 1;

if (fb_bit)

{

shift_reg = shift_reg ^ 0x8c;

}

}

}

return(shift_reg);

}

**Pascal** (derived from the basic one above):

`function CalcCrc: byte;`

var I, J: byte;

TmpBit: boolean;

begin

Result := 0; // temporary CRC

for I := 0 to 8 do // for each byte

begin

for J := 0 to 7 do // for each bit

begin

TmpBit := Result.0 xor Buff[I].J; // XOR bit0 of data byte and temporary crc

Result := Result shr 1; // Shift right the temporary CRC byte

if TmpBit then Result := Result xor $8c; // If set, account for EXOR feedback

end;

end;

end;

p.s. The Pascal code assumes the read in data of the DS1820 to be present in global variable Buff[0..8]. You can of course make a parameter for this.