#Picaxe 20X2
#Terminal 9600
Symbol crc = w1
Symbol polynomial = w2
Symbol k = w3
Symbol data_byte = b0
Symbol crc.lsb = b2
Symbol crc.msb = b3
Do
Gosub CrcSpec : SerTxd("Spec = ", #crc, CR, LF )
Gosub CrcBits : SerTxd("Bits = ", #crc, CR, LF )
Gosub CrcByte : SerTxd("Byte = ", #crc, CR, LF, CR, LF )
Pause 5000
Loop
CrcSpec:
crc = $FFFF
polynomial = $A001
data_byte = $F2 : Gosub CrcSpecAdd
data_byte = $1C : Gosub CrcSpecAdd
data_byte = $33 : Gosub CrcSpecAdd
data_byte = $C2 : Gosub CrcSpecAdd
Return
CrcSpecAdd:
k = bit0 ^ bit16 : crc = crc >> 1 : If k <> 0 Then : crc = crc ^ polynomial : End If
k = bit1 ^ bit16 : crc = crc >> 1 : If k <> 0 Then : crc = crc ^ polynomial : End If
k = bit2 ^ bit16 : crc = crc >> 1 : If k <> 0 Then : crc = crc ^ polynomial : End If
k = bit3 ^ bit16 : crc = crc >> 1 : If k <> 0 Then : crc = crc ^ polynomial : End If
k = bit4 ^ bit16 : crc = crc >> 1 : If k <> 0 Then : crc = crc ^ polynomial : End If
k = bit5 ^ bit16 : crc = crc >> 1 : If k <> 0 Then : crc = crc ^ polynomial : End If
k = bit6 ^ bit16 : crc = crc >> 1 : If k <> 0 Then : crc = crc ^ polynomial : End If
k = bit7 ^ bit16 : crc = crc >> 1 : If k <> 0 Then : crc = crc ^ polynomial : End If
Return
CrcBits:
crc = $FFFF
polynomial = $A001
data_byte = $F2 : Gosub CrcBitsAdd
data_byte = $1C : Gosub CrcBitsAdd
data_byte = $33 : Gosub CrcBitsAdd
data_byte = $C2 : Gosub CrcBitsAdd
Return
CrcBitsAdd:
k = bit0 ^ bit16 * Polynomial : crc = crc >> 1 ^ k
k = bit1 ^ bit16 * Polynomial : crc = crc >> 1 ^ k
k = bit2 ^ bit16 * Polynomial : crc = crc >> 1 ^ k
k = bit3 ^ bit16 * Polynomial : crc = crc >> 1 ^ k
k = bit4 ^ bit16 * Polynomial : crc = crc >> 1 ^ k
k = bit5 ^ bit16 * Polynomial : crc = crc >> 1 ^ k
k = bit6 ^ bit16 * Polynomial : crc = crc >> 1 ^ k
k = bit7 ^ bit16 * Polynomial : crc = crc >> 1 ^ k
Return
CrcByte:
crc = $FFFF
polynomial = $A001
data_byte = $F2 : Gosub CrcByteAdd
data_byte = $1C : Gosub CrcByteAdd
data_byte = $33 : Gosub CrcByteAdd
data_byte = $C2 : Gosub CrcByteAdd
Return
CrcByteAdd:
data_byte = data_byte ^ crc.lsb : Read data_byte, crc.lsb
crc.lsb = crc.lsb ^ crc.msb : ReadTable data_byte, crc.msb
Return
Eeprom ( $00,$C1,$81,$40,$01,$C0,$80,$41,$01,$C0,$80,$41,$00,$C1,$81,$40 )
Eeprom ( $01,$C0,$80,$41,$00,$C1,$81,$40,$00,$C1,$81,$40,$01,$C0,$80,$41 )
Eeprom ( $01,$C0,$80,$41,$00,$C1,$81,$40,$00,$C1,$81,$40,$01,$C0,$80,$41 )
Eeprom ( $00,$C1,$81,$40,$01,$C0,$80,$41,$01,$C0,$80,$41,$00,$C1,$81,$40 )
Eeprom ( $01,$C0,$80,$41,$00,$C1,$81,$40,$00,$C1,$81,$40,$01,$C0,$80,$41 )
Eeprom ( $00,$C1,$81,$40,$01,$C0,$80,$41,$01,$C0,$80,$41,$00,$C1,$81,$40 )
Eeprom ( $00,$C1,$81,$40,$01,$C0,$80,$41,$01,$C0,$80,$41,$00,$C1,$81,$40 )
Eeprom ( $01,$C0,$80,$41,$00,$C1,$81,$40,$00,$C1,$81,$40,$01,$C0,$80,$41 )
Eeprom ( $01,$C0,$80,$41,$00,$C1,$81,$40,$00,$C1,$81,$40,$01,$C0,$80,$41 )
Eeprom ( $00,$C1,$81,$40,$01,$C0,$80,$41,$01,$C0,$80,$41,$00,$C1,$81,$40 )
Eeprom ( $00,$C1,$81,$40,$01,$C0,$80,$41,$01,$C0,$80,$41,$00,$C1,$81,$40 )
Eeprom ( $01,$C0,$80,$41,$00,$C1,$81,$40,$00,$C1,$81,$40,$01,$C0,$80,$41 )
Eeprom ( $00,$C1,$81,$40,$01,$C0,$80,$41,$01,$C0,$80,$41,$00,$C1,$81,$40 )
Eeprom ( $01,$C0,$80,$41,$00,$C1,$81,$40,$00,$C1,$81,$40,$01,$C0,$80,$41 )
Eeprom ( $01,$C0,$80,$41,$00,$C1,$81,$40,$00,$C1,$81,$40,$01,$C0,$80,$41 )
Eeprom ( $00,$C1,$81,$40,$01,$C0,$80,$41,$01,$C0,$80,$41,$00,$C1,$81,$40 )
Table ( $00,$C0,$C1,$01,$C3,$03,$02,$C2,$C6,$06,$07,$C7,$05,$C5,$C4,$04 )
Table ( $CC,$0C,$0D,$CD,$0F,$CF,$CE,$0E,$0A,$CA,$CB,$0B,$C9,$09,$08,$C8 )
Table ( $D8,$18,$19,$D9,$1B,$DB,$DA,$1A,$1E,$DE,$DF,$1F,$DD,$1D,$1C,$DC )
Table ( $14,$D4,$D5,$15,$D7,$17,$16,$D6,$D2,$12,$13,$D3,$11,$D1,$D0,$10 )
Table ( $F0,$30,$31,$F1,$33,$F3,$F2,$32,$36,$F6,$F7,$37,$F5,$35,$34,$F4 )
Table ( $3C,$FC,$FD,$3D,$FF,$3F,$3E,$FE,$FA,$3A,$3B,$FB,$39,$F9,$F8,$38 )
Table ( $28,$E8,$E9,$29,$EB,$2B,$2A,$EA,$EE,$2E,$2F,$EF,$2D,$ED,$EC,$2C )
Table ( $E4,$24,$25,$E5,$27,$E7,$E6,$26,$22,$E2,$E3,$23,$E1,$21,$20,$E0 )
Table ( $A0,$60,$61,$A1,$63,$A3,$A2,$62,$66,$A6,$A7,$67,$A5,$65,$64,$A4 )
Table ( $6C,$AC,$AD,$6D,$AF,$6F,$6E,$AE,$AA,$6A,$6B,$AB,$69,$A9,$A8,$68 )
Table ( $78,$B8,$B9,$79,$BB,$7B,$7A,$BA,$BE,$7E,$7F,$BF,$7D,$BD,$BC,$7C )
Table ( $B4,$74,$75,$B5,$77,$B7,$B6,$76,$72,$B2,$B3,$73,$B1,$71,$70,$B0 )
Table ( $50,$90,$91,$51,$93,$53,$52,$92,$96,$56,$57,$97,$55,$95,$94,$54 )
Table ( $9C,$5C,$5D,$9D,$5F,$9F,$9E,$5E,$5A,$9A,$9B,$5B,$99,$59,$58,$98 )
Table ( $88,$48,$49,$89,$4B,$8B,$8A,$4A,$4E,$8E,$8F,$4F,$8D,$4D,$4C,$8C )
Table ( $44,$84,$85,$45,$87,$47,$46,$86,$82,$42,$43,$83,$41,$81,$80,$40 )