;
; From Dallas Application note 27
;
; CRC-16 (x^16+x^15+x^2+x^0)
; No tables, No loops, No temporary registers used.
;
; This code is from Dallas Semiconductor Application Note 27:
;
; Understanding and Using Cyclic Redundancy Checks
; with Dallas Semiconductor iButton(TM) Products.
;
; This routine that calculates the same CRC as the hardware
; in the DS5001/2 secure micro.
;-----------------------------------------------------------------------
NAME CRC_test
?DT?CRC_test SEGMENT DATA
rseg ?DT?CRC_test
CRCH: ds 1
CRCL: ds 1
?CO?CRC_test SEGMENT CODE
RSEG ?CO?CRC_test
public CRC_test
CRC_test:
mov CRCH,#0
mov CRCL,#0
mov A,#080H
call CRC16
mov A,#075H
call CRC16
mov A,#08AH
call CRC16
mov A,#00BH
call CRC16
mov A,#075H
call CRC16
mov A,#0C7H
call CRC16
mov A,#0AAH
call CRC16
mov A,#075H
call CRC16
mov A,#0C7H
call CRC16
mov A,#055H
call CRC16
mov A,#043H
call CRC16
ljmp CRC_test
;CALCULATE CRC16 IN PARALLEL TO THE GREATEST EXTENT PRACTICAL
; INPUT: BYTE TO BE INCUDED IN CRC CALCULATION IS IN ACC
; OUTPUT: CRCH:CRCL UPDATED TO INCLUDE THE NEW BYTE
;
CRC16:
PUSH ACC ;save this in case the caller needs it
XRL A,CRCL
MOV CRCL,CRCH ;put the high byte of the crc in its dest..
MOV CRCH,A ;save data xor low(crc) for later
MOV C,P
JNC CRC0
XRL CRCL,#001H
CRC0:
RRC A ;get the low bit in c
JNC CRC1
XRL CRCL,#040H
CRC1:
MOV C,ACC.7
XRL A,CRCH ;compute the results for bits P...U
RRC A ;shift them into place
MOV CRCH,A ;and save them
JNC CRC2
XRL CRCL,#080H
CRC2:
POP ACC ;and restore everything and return
RET
end
| file: /Techref/8051/crc16.htm, 2KB, , updated: 2001/4/17 10:21, local time: 2025/10/24 15:58,
216.73.216.188,10-3-157-36:LOG IN
|
| ©2025 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://ecomorder.com/Techref/8051/crc16.htm"> 8051 crc16</A> |
| Did you find what you needed? |
Welcome to ecomorder.com! |
|
Ashley Roll has put together a really nice little unit here. Leave off the MAX232 and keep these handy for the few times you need true RS232! |
.