I'm doing a modbus project & needs to read some data from a PIC driven driver.I'm confused with the CRC routine.I'm not getting the correct CRC values from PC simulator (Hyper terminal). like in the top comment the correct CRC values are "77" & "03".I'm not getting it. I get some other values
May be I'm doing wrong.
May be I'm doing wrong.
Code:
;==================================================================
Modbus RTU request for the content of analog output holding registers #40108 to #40110 from the slave device with address 21.
;15 03 00 6B 00 03 77 03
;movlw 0xFF
;movwf crcL
;movwf crcH
;
movlw 0x15
call CRC_16_Upd
movlw 0x03
call CRC_16_Upd
movlw 0x00
call CRC_16_Upd
movlw 0x6B
call CRC_16_Upd
movlw 0x00
call CRC_16_Upd
movlw 0x03
call CRC_16_Upd
;
;send higher CRC to PC Terminal
swapf crcH,W
andlw b'00001111'
call Ascii_Table
call TX_RS232_PC
movf crcH,W
andlw b'00001111'
call Ascii_Table
call TX_RS232_PC
movlw .10 ;LF
call TX_RS232_PC
movlw .13 ;CR
call TX_RS232_PC
;send lower CRC to PC Terminal
swapf crcL,W
andlw b'00001111'
call Ascii_Table
call TX_RS232_PC
movf crcL,W
andlw b'00001111'
call Ascii_Table
call TX_RS232_PC
movlw .10 ;LF
call TX_RS232_PC
movlw .13 ;CR
call TX_RS232_PC
;
Wait_Here nop
goto Wait_Here
;John Paysons CRC Routine
CRC_16_Upd xorwf crcH,F
; Compute the LSB first [based upon MSB]
movlw .0
btfsc crcH,0
xorlw .33
btfsc crcH,1
xorlw .66
btfsc crcH,2
xorlw .132
btfsc crcH,3
xorlw .8
btfsc crcH,4
xorlw .49
btfsc crcH,5
xorlw .98
btfsc crcH,6
xorlw .196
btfsc crcH,7
xorlw .136
; Swap crcL with W
xorwf crcL,f
xorwf crcL,w
xorwf crcL,f
; Next compute the MSB [note W holds old LSB]
btfsc crcH,0
xorlw .16
btfsc crcH,1
xorlw .32
btfsc crcH,2
xorlw .64
btfsc crcH,3
xorlw .129
btfsc crcH,4
xorlw .18
btfsc crcH,5
xorlw .36
btfsc crcH,6
xorlw .72
btfsc crcH,7
xorlw .145
movwf crcH
return
;========================================================
Ascii_Table addwf PCL,F
retlw '0'
retlw '1'
retlw '2'
retlw '3'
retlw '4'
retlw '5'
retlw '6'
retlw '7'
retlw '8'
retlw '9'
retlw 'A'
retlw 'B'
retlw 'C'
retlw 'D'
retlw 'E'
retlw 'F'