Even though I'm not a PBP developer, I've always enjoyed exchanging ideas and experiences with members here. That said, I wonder if anyone is interested in my zero overhead CRC8 method, even if it isn't a PBP example?
In my zero overhead CRC8 method I use a portion of the 60-usec read/write 'slot' time to implement CRC8 at the bit level within the OneWire read bit routine. Here's the tail end of a read bit routine from code for an enhanced mid-range 16F device;
Code:
;
; bit level cumulative CRC (data bit in Carry at entry & exit)
;
clrf WREG ; |00
rlf WREG,W ; save C in wreg (0x00 or 0x01) |00
xorwf crc,F ; xor b0 bits, result in 'crc' |00
rrf crc,F ; is xor result 0 (Carry = 0)? |00
skpnc ; yes, skip, else |00
iorlw 0x18 ; w = x8+x5+x4+1 poly and bit 0 |00
rrf WREG,W ; restore C, wreg = 0x8C or 0x00 |00
xorwf crc,F ; apply the polynomial or not |00
;
; remainder of 60-usec read/write 'slot'
;
DelayCy(46*usecs-14) ; 46-usecs minus 14 cycles |00
banksel owtris ; bank 1 |01
bsf owtris,owpin ; output hi-z '1' @ 61-usecs |01
banksel 0 ; bank 0 |00
bsf INTCON,GIE ; interrupts on |00
return ; Carry = data bit |00
Using CRC in my DS18x20 programs is simply a matter of clearing the 'crc' variable before reading the 9 byte DS18x20 'scratchpad' or an 8 byte ROMID and verifying that the 'crc' variable equals zero afterwards. You must read all 9 'scratchpad' bytes to have a valid 'crc'. Just ignore or throw away the bytes you don't need.
I admit I have no idea if this method could be implemented in PBP with its intrinsic OneWire commands but I suspect you gurus will find a way to use it if you think the method is worthwhile.
Have fun. Cheerful regards, Mike (K8LH)
Bookmarks