PDA

View Full Version : Crc Hserout Implementation



brainless
- 30th May 2020, 00:54
Hi To All

i,m reading about crc on this thread http://www.picbasic.co.uk/forum/showthread.php?t=11790 and crc8 implementation for this code:
CRC VAR BYTECRC_IDX VAR BYTE
CRC_IN VAR BYTE
CRC_Poly CON $31


CRC8:
FOR CRC_IDX = 0 to 7
IF (CRC.7 ^ CRC_IN.7) THEN
CRC = (CRC << 1) ^ CRC_Poly
ELSE
CRC = CRC << 1
ENDIF
CRC_IN = CRC_IN << 1
NEXT CRC_IDX
RETURN
X VAR BYTE


CRC = 0
FOR X = 0 TO 8
LOOKUP X,[$AD, $42, $CB, $16, $05, $06, $00, $6C, $0E], CRC_IN
HSEROUT [HEX2 CRC_IN," "]
GOSUB CRC8
NEXT X
HSEROUT ["= ",HEX2 CRC,13,10,13,10]


CRC = 0
FOR X = 0 TO 8
LOOKUP X,[$AD, $42, $CC, $16, $05, $08, $00, $6C, $0C], CRC_IN
HSEROUT [HEX2 CRC_IN," "]
GOSUB CRC8
NEXT X
HSEROUT ["= ",HEX2 CRC,13,10,13,10]

This Works with the values stored previously in lookup, however this could be implemented in a similar way for Hserin or Hserout in runtime ?, searching in the forum mostly of the examples involves data previously stored on program i,m building a vending machine that process information about rs232 and the data is changing constantly my project involves a 16f1938 microcontroller, i aprreciatte any advice about this issue.



Best Regards


Brainless

richard
- 30th May 2020, 02:33
however this could be implemented in a similar way for Hserin or Hserout

yes , the simplest way is store data to be sent or received data in a buffer before processing the crc of the buffered data

what have you tried ?

brainless
- 30th May 2020, 02:49
Hello Richard

Thanks for reply, still don´t tried something because my first step was confirm the behavior of conversion lookup against runtime data now reading you´re explanation i´m try to build the routine to store and process data and get the properly Crc value to the entire data at the end.


Thanks Again

Best Regards

Brainless