Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
03/21/01 07:31
Read: times


 
#10225 - RE: CRC 16 - endian problem !
In general, you may need only swap MSB
and LSB of calculated CRC16 either on
PC or on 8052 (does not matter) before
comparison. Try it.

I use the following code to calculate
CRC on-line during reception of data
stream. The corresponding "C" code is
commented (the same routine for 8052
was coded at first in C, and optimized
after disassembly).

; One CRC iteration
; -------------------
; R3:R4 -- CRC16 (must be initialized to 0FFFFh for the first time)
; ACC -- data byte
CRC16Iter:
push PSW ; saving F0, CY
push B
mov B,#8
; crc ^= datab;
xrl A,R3
mov R3,A

; for (j = 8; j; j--)
; {
; flag = crc & 1;
nextbit: mov A,R3
jb ACC.0,odd
clr F0
sjmp shift
odd: setb F0

; crc >>= 1;
shift: clr C
mov A,R4
rrc A
mov R4,A
mov A,R3
rrc A
mov R3,A

; if (flag) crc ^= 0xA001;
jnb F0,increment
mov A,#1
xrl A,R3
mov R3,A
mov A,#0A0h
xrl A,R4
mov R4,A

; }
increment: djnz B,nextbit

pop B
pop PSW
ret



List of 4 messages in thread
TopicAuthorDate
CRC 16 - endian problem !            01/01/70 00:00      
RE: CRC 16 - endian problem !            01/01/70 00:00      
RE: CRC 16 - endian problem !            01/01/70 00:00      
RE: CRC 16 - endian problem !            01/01/70 00:00      

Back to Subject List