|
发表于 2010-11-29 16:28:02
|
显示全部楼层
补充一个 汇编语言 测试成功的
.include "tn13def.inc"
.def polyhi = R16
.def polylo = R17
.def crchi = R18 ;crc高字节
.def crclo = R19 ;crc低字节
.def bitcnt = R20 ;
.def buflen = R21 ;数量
;-------------------------------------------------------------------------
.cseg
.org 0
;-------------------------------------------------------------------------
avr0000:
rjmp RESET
RESET: ldi ZL,RamEnd
out SPL, zl
ldi Zh, high(2*data)
ldi Zl, low(2*data)
ldi buflen, low(2*data_en)-low(2*data)
rcall crc_go
rjmp pc
;*********************************************************
; eXtreme compact CRC16 procedure (c) Gleb Daniloff
; 08/01/2007 harley@hotbox.ru
; registry usage: Z,r0,polylo,polyhi,crclo,crchi,bitcnt
; input: Z - pointer to string, buflen - buffer length
; output: crclo,crchi - CRC16
;*********************************************************
crc_go:
ldi polyhi,0xa0 ; polynom inilialization - once at all
ldi polylo,0x01
ldi crchi,0xff;clr crchi ; crc initialization - once per call
ldi crclo,0xff;clr crclo
crc16:
lpm
adiw ZL,1
ldi bitcnt,8
crc01:
eor crclo,r0
bst crclo,0
eor crclo,r0
lsr r0
lsr crchi
ror crclo
brtc crc02
eor crchi,polyhi
eor crclo,polylo
crc02:
dec bitcnt
brne crc01
dec buflen
brne crc16
ret
data: .db 0x01,0x02,0x00,0xc4,0x00,0x16
data_en: |
|