Truncated match.
PICList
Thread
'CRC program for PIC 16CXX'
1995\10\05@115052
by
Falstaff
|
Thanks for all those who responded. In return, here I present a
debugged and tested CRC routine for y'all.
Program to calculate CRC-16 on a 16Cxx. The resulting CRC value is
identical to that calculated by common archive programs, such as ZOO.
Fast table-based CRC calculators for this polynomial are available
as C source.
Note that the resulting CRC has its bits reversed in comparison to
the sources posted yesterday; this is to be compatible with ZOO and
ARC and others (most of all, with the CRC16 routine in my standard
library), and also is compatible with serial transmission if the
least significant bit is sent first.
----- C source --------------------------------------------------------
unsigned CRC;
unsigned crc_16(char c)
{
int i,j;
for(i=0;i!=8;c>>=1,i++)
{
j=(c^CRC)&1;
CRC>>=1;
if(j)
CRC^=0xa001;
}
return CRC;
}
----- 16CXX source ----------------------------------------------------
Temp = 0x20
Count = 0x21
CRC_High = 0x22
CRC_Low = 0x23
loop macro reg,label
decfsz reg
goto label
endm
movlw "h"
call CalcCRC
movlw "e"
call CalcCRC
movlw "l"
call CalcCRC
movlw "l"
call CalcCRC
movlw "o"
call CalcCRC
Halt goto Halt
; result=0x34d2 (you can check that with ZOO)
----- CRC subroutine --------------------------------------------------
CalcCRC movwf Temp ; about 125 cycles on average
movlw 8
movwf Count
CRC_Loop movf CRC_Low,w
xorwf Temp,w
clrc
rrf CRC_High
rrf CRC_Low
andlw 1
bz CRC_Skip
movlw 0xa0
xorwf CRC_High
movlw 0x01
xorwf CRC_Low
CRC_Skip rrf Temp
loop Count,CRC_Loop
return
-----------------------------------------------------------------------
Share And Enjoy.
Frank
"It's justice, Jim, but not as we know it."
------------------------------------------------------------------------
Frank A. Vorstenbosch +31-(70)-355 5241 spam_OUTfalstaffTakeThisOuT
xs4all.nl
More... (looser matching)
- Last day of these posts
- In 1995
, 1996 only
- Today
- New search...