/* binary to 6 digits BCD */unsigned long bin2Bcd(unsigned long dataBin){unsigned long dataBcd=0; dataBcd = (dataBin / 100000) * 1048576; dataBin %= 100000; dataBcd |= (dataBin / 10000) * 65536; dataBin %= 10000; dataBcd |= (dataBin / 1000) * 4096; dataBin %= 1000; dataBcd |= (dataBin / 100) * 256; dataBin %= 100; dataBcd |= (dataBin / 10) * 16; dataBcd |= dataBin % 10; return(dataBcd);}but maybe this isn't fast enough ?
Message Edited by bigmac on 2006-11-0112:54 AM
Message Edited by bigmac on 2006-11-0107:12 AM
; Condition: The table UW_TBL_BinBCD musst be placed in a; 256-Byte-Page (no Change of MSB); INPUT: (H:X) = Pntr. MSB binary valueBIN20_BCD: clr TMP6 ;BCD-Reg =0 clr TMP5 ; clr TMP4 ; ; BIN20 -> BCD6-Convert.BCD6: lda ,x ; sta TMP1 ; lda 1,x ; sta TMP2 ; lda 2,x ; sta TMP3 ; ldx #4 ;BCD61: rol TMP3 ;4-times shift rol TMP2 ;(20 instead of 24-Bits) rol TMP1 ; dbnzx BCD61 ; ldhx #(BinBCD_TOP-1) ; bra BCDL3BCDL1: aix #-3 ;BCDL2: cpx #LOW (BinBCD_Bot) ; bpl BCDL3 ; clc ; rtsBCDL3: rol TMP3 ; rol TMP2 ; rol TMP1 ; bcc BCDL1ADD_BCD: lda ,x ; add TMP6 ; daa ; sta TMP6 ; decx ; lda ,x ; adc TMP5 ; daa ; sta TMP5 ; decx ; lda ,x ; adc TMP4 ; daa ; sta TMP4 ; decx ; bcs BCDovf ; bra BCDL2 ; BCDovf: sec rtsUW_TBL_BinBCD:BinBCD_Bot: equ * DC.B $00,$00,$01 ;Bit0 DC.B $00,$00,$02 ; DC.B $00,$00,$04 ; DC.B $00,$00,$08 ;Bit3 DC.B $00,$00,$16 ; DC.B $00,$00,$32 ; DC.B $00,$00,$64 ; DC.B $00,$01,$28 ;Bit7 DC.B $00,$02,$54 ; DC.B $00,$05,$12 ; DC.B $00,$10,$24 ; DC.B $00,$20,$48 ;Bit11 DC.B $00,$40,$96 ; DC.B $00,$81,$92 ; DC.B $01,$63,$84 ; DC.B $03,$27,$68 ;Bit15 DC.B $06,$55,$36 ; DC.B $13,$10,$72 ; DC.B $26,$21,$44 ; DC.B $52,$42,$88 ;Bit19BinBCD_TOP: equ * ;