Mike - K8LH
Well-Known Member
A puzzle to share with members, if you please. The following routine is used in the tail end of a readbit() routine for DS18B20 1-wire temperature sensors. It's basically my implementation of a "zero overhead" bit level CRC method. As you can see, the routine is limited to use in 18F and "enhanced mid-range" 16F devices which provide access to WREG. I'd like an alternative routine that will work for normal 16F devices and I'm looking for ideas. Note that the Carry bit must be preserved.
Thanks for taking a peek.
Cheerful regards, Mike
<added>
Oops! I suppose I could just use a variable to replace WREG. Anyone see a better way to do it?
Thanks for taking a peek.
Cheerful regards, Mike
Code:
clrf wreg ;
rlf wreg,W ; save C (wreg = 0x00 or 0x01)
xorwf crc,F ; xor b0 bits, result in 'crc'
rrf crc,F ; is xor result 0 (C=0)?
skpnc ; yes, skip, else
iorlw 0x18 ; wreg = x8+x5+x4+1 poly and b0 bit
rrf wreg,W ; restore C (wreg = 0x8C or 0x00)
xorwf crc,F ; apply the polynomial, or not
<added>
Oops! I suppose I could just use a variable to replace WREG. Anyone see a better way to do it?
Code:
clrf work ;
rlf work,F ; save C (work = 0x00 or 0x01)
movf work,W ;
xorwf crc,F ; xor b0 bits, result in 'crc'
rrf crc,F ; put xor result in C
movlw 0 ;
skpnc ; C=0? yes, skip, else
movlw 0x8C ; x8+x5+x4+1 polynomial
xorwf crc,F ; apply the polynomial, or not
rrf work,W ; restore C
Last edited: