The result is already cumulative. If you compare the results
to the assembly version in your link, you'll see the last version
I posted outputs the same values. crc_hi & crc_lo are only
cleared at the start - so they are cumulative until cleared.
If you change any value, the final result will also change since
crc_hi & crc_low hold the cumulative values from every byte
passed to the assembly routine.
To change the order of the final result, simply change the order
you send them out in. crc_hi holds the high byte. crc_lo holds the
low byte. You can send them both out serially in any order you
need.
This doesn't return crc_hi = $D5 & crc_lo = $50 though. I getCode:crc_hi VAR BYTE bank0 crc_lo VAR BYTE bank0 temp VAR BYTE bank0 ToCrc VAR BYTE bank0 C_Vars VAR BYTE[3] ' Holds byte data passed to crc_8408 X VAR BYTE Main: crc_lo = 0 crc_hi = 0 FOR X = 0 TO 2 LOOKUP X,[$AA,$05,$01],ToCrc C_Vars[X] = ToCrc ' Stash each value for Show output CALL crc_8408 NEXT X GOSUB Show PAUSE 1000 GOTO Main Show: HSEROUT [IHEX2 C_Vars[0],IHEX2 C_Vars[1],_ IHEX2 C_Vars[2],IHEX crc_lo,IHEX2 crc_hi,13,10] RETURN ASM _crc_8408 movf _ToCrc,W ;Load value into W xorwf _crc_lo,W ;W = CD ^ ab ==> xy movwf _temp ;temp = xy swapf _temp,F ;W = yx rrf _temp,w andlw 0x78 ;y<<3 xorwf _crc_hi,W ;W = AB ^ (y<<3) movwf _crc_lo ;LO = AB ^ (y<<3) swapf _temp,W ;W = xy xorwf _temp,W ;W = (y^x) | (x^y) = kk movwf _crc_hi ;HI = kk andlw 0x0f ;W = 0k xorwf _crc_lo,W ;W = AB ^ (y<<3) ^ k btfsc _crc_hi,0 ; xorlw 0x80 ;W = AB ^ (y<<3) ^ k ^ (k<<7) movwf _crc_lo ;LO = AB ^ (y<<3) ^ k ^ (k<<7) swapf _temp,W ;W = xy andlw 0xf0 ;W = x0 xorwf _crc_hi,F ;W = y<<4 | x^y rrf _crc_hi,W ;W = (y<<4 | x^y) >> 1 andlw 7 ;W = x^y >> 1 swapf _crc_hi,F ;W = x^y<<4 | y xorwf _crc_hi,F ;HI = kx ^ k>>1 = (k<<4) ^ y ^ (k>>1) return ENDASM
crc_lo = $4F & crc_hi = $7F.
The above returns: $AA$05$01$7F$4F with your hi & lo bytes
swapped around.
If you change it, and plug-in the same values shown in the assembly
version, it returns eactly the same results as the assembly version
shows for each value passed to crc_8408.
Maybe there's a difference in your PC version & the PIC version?




Bookmarks