[an error occurred while processing this directive]
|
; function calculate CRC-16
; with 0x1021 polynome = x16 + x12 + x5 + 1 - direct calculation
; It uses direct calculation (bits' shifting for each byte)
; MODIFY : CRC_LO, CRC_HI,B,ACC,PSW
; crc_hi and crc_lo contain the CRC16 result
CRC_modul_P:
; calculate crc with accumulator
CLR C
PUSH B ; save value of b
MOV B, #08h ; number of bits to crc.
CRC_GET_BIT_P:
RLC A
; RRC A ; get low order bit into carry
PUSH ACC ; save a for later use
JC CRC_IN_1_P ;got a 1 input to crc
MOV C, CRC_LO.0 ;xor with a 0 input bit is bit
SJMP CRC_CONT_P ;continue
CRC_IN_1_P:
MOV C, CRC_LO.0 ;xor with a 1 input bit
CPL C ;is not bit.
CRC_CONT_P:
JNC CRC_SHIFT_P ; if carry set, just shift
CPL CRC_HI.3 ;complement bit 15 of crc
CPL CRC_LO.4 ;complement bit 2 of crc
CRC_SHIFT_P:
MOV A, CRC_HI ; carry is in appropriate setting
RRC A ; rotate it
MOV CRC_HI, A ; and save it
MOV A, CRC_LO ; again, carry is okay
RRC A ; rotate it
MOV CRC_LO, A ; and save it
POP ACC ; get acc back
DJNZ B, CRC_GET_BIT_P ; go get the next bit
POP B ; restore b
RET