Ответ:
(«Телесистемы»: Конференция «Микроконтроллеры и их применение»)

миниатюрный аудио-видеорекордер mAVR

Отправлено Gorelov 22 октября 2003 г. 14:03
В ответ на: перевод из двоичной в десятичную и отображение на hd44780 отправлено sa 22 октября 2003 г. 11:28

;***************************************************************************
;*
;* "bin4BCD32" - 32-bit Binary to BCD conversion
;*
;* This subroutine converts a 32-bit number (fbinH:fbinD:fbinC:fbinL)
;* to a 10-digit packed BCD number represented by 5 bytes
;* (tBCD4:tBCD3:tBCD2:tBCD1:tBCD0).
;* MSD of the 10-digit number is placed in the lowermost nibble of tBCD4.
;*
;* Number of words :30
;* Number of cycles :2550
;* Low registers used :5 (tBCD0,tBCD1,tBCD2,tBCD3,tBCD4)
;* High registers used :6(fbinL,fbinC,fbinHD,fbinH,temp,temp1)
;* Pointers used :Z
;*
;***************************************************************************
bin4BCD32:
ldi temp,32 ;Init loop counter
clr tBCD4
clr tBCD3
clr tBCD2 ;clear result (5 bytes)
clr tBCD1
clr tBCD0
clr ZH ;clear ZH
bBCDx_1:lsl fbinL ;shift input value
rol fbinC
rol fbinD
rol fbinH ;through all bytes
rol tBCD0 ;
rol tBCD1
rol tBCD2
rol tBCD3
rol tBCD4
dec temp ;decrement loop counter
brne bBCDx_2 ;if counter not zero
ret ; return

bBCDx_2:ldi r30,AtBCD4+1 ;Z points to result MSB + 1
bBCDx_3:
ld temp1,-Z ;get (Z) with pre-decrement
subi temp1,-$03 ;add 0x03
sbrc temp1,3 ;if bit 3 not clear
st Z,temp1 ; store back
ld temp1,Z ;get (Z)
subi temp1,-$30 ;add 0x30
sbrc temp1,7 ;if bit 7 not clear
st Z,temp1 ; store back
cpi ZL,AtBCD0 ;done all three?
brne bBCDx_3 ;loop again if not
rjmp bBCDx_1

Составить ответ  |||  Конференция  |||  Архив

Ответы



Перейти к списку ответов  |||  Конференция  |||  Архив  |||  Главная страница  |||  Содержание  |||  Без кадра

E-mail: info@telesys.ru