I have done some exhausted search for ASM code for implementing MODBUS CRC calculation. I finally gave up and developed this simple code that works.
Code ASM - [expand]
1
2
3
4
5
6
; The registrars where the CRC results will reside have to be set to 0xFFFF.
CRC16_Init:; Reset CRC RegistarMOV D_CRC16_Hi, #0FFhMOV D_CRC16_Lo,#0FFhRET
Once this is done the string of bytes to be transmitted are processed by calling the routine below.
CRC16_AddCalc:; Calc CRCPUSH R_0 ; Save Reg 0PUSH Acc ; Save AccMOV R0,#08h; 8 Bits
XRL D_CRC16_Lo,A ; Lo ^=Data
L?P1:
CLR C ; Clear CarryMOV A,D_CRC16_Hi ; D_CRC << 1
RRC A ; Shift LeftMOV D_CRC16_Hi,A ; Store BackMOV A,D_CRC16_Lo ; Get Hi Byte
RRC A ; Shift LeftMOV D_CRC16_Lo,A ; Store BackJNC L?P2 ; Skip if Bit 15 wasn't set
XRL D_CRC16_Hi,#0A0h; XOR in Polynomial High
XRL D_CRC16_Lo,#01h; XOR in Polynomial Lo
L?P2:
DJNZ R0,L?P1
POP Acc
POP R_0
RET