Aqui te dejo una rutina que funciona a la perfección de cosecha propia:
Codigo:
;HEX2BDC: Transforma el código en Hexadecimal que viene en el w,
;en dos bcd que se retornan LSB=BP0, MSB=BP1
hex2bcd movwf contador1
clrf contador2
comf contador1,f
h2bcd1 movf contador1,w
addlw 0x0a
btfsc status,0
goto h2bcd2
movwf contador1
incf contador2,f
goto h2bcd1
h2bcd2 comf contador1,w
movwf BP0
movf contador2,w
movwf BP1
return
Esta es de microchip y transforma un número de 16 bits en 5 dígitos BCD:
Codigo:
;********************************************************************
; Binary To BCD Conversion Routine
; This routine converts a 16 Bit binary Number to a 5 Digit
; BCD Number.
; The 16 bit binary number is input in locations H_byte and
; L_byte with the high byte in H_byte.
; The 5 digit BCD number is returned in R0, R1 and R2 with R0
; containing the MSB in its right most nibble.
;
; Performance :
; Program Memory : 35
; Clock Cycles : 885
;
;*******************************************************************;
;
B2_BCD bcf status,c ;Borra el carry
movlw .16
movwf contador1
clrf R0
clrf R1
clrf R2
loop16 rlf L_byte,f
rlf H_byte,f
rlf R2,f
rlf R1,f
rlf R0,f
decfsz contador1,f
goto adjDEC
return
adjDEC movlw R2
movwf fsr
call adjBCD
movlw R1
movwf fsr
call adjBCD
movlw R0
movwf fsr
call adjBCD
goto loop16
adjBCD movlw 3
addwf indf,W
movwf temp
btfsc temp,3 ; test if result > 7
movwf indf
movlw 30
addwf indf,W
movwf temp
btfsc temp,7 ; test if result > 7
movwf indf ; save as MSD
return