Here as a code snippet that converts 16, 24 or 32 bit binary numbers to bcd. It has been only slightly tested Include p16f84.inc BitCount set 16 ;(must be 16, 24 or 32) CBLOCK 0x0C R0 ;BCD byte 9 (upper nibble) R1 R2 R3 R4 ;BCD byte 0 (lower nibble) Byte3 ;BIN Inputs 2^32 (MSB) Byte2 Byte1 Byte0 ;BIN (LSB) Temp Count endc org 0000 movlw 0FFH ;test code with 0FFFFFFFFh movwf Byte0 movwf Byte1 movwf Byte2 movwf Byte3 call BIN2BCD nop goto $ BIN2BCD ; Binary to BCD conversion If BitCount == 16 movlw .16 endif If BitCount == 24 clrf R3 movlw .24 endif If BitCount == 32 clrf R3 clrf R4 movlw .32 endif movwf Count bcf STATUS,0 ; clear the carry bit clrf R0 clrf R1 clrf R2 BCDLoop rlf Byte0,F rlf Byte1,F if BitCount == 24 rlf Byte2,F rlf R3,F endif if BitCount == 32 rlf Byte2,F rlf Byte3,F rlf R4,F rlf R3,F endif rlf R2,F rlf R1,F rlf R0,F decfsz Count,F goto adjDEC return adjDEC if BitCount == 32 movlw R4 movwf FSR call adjBCD call adjBCD endif if BitCount == 24 movlw R3 movwf FSR call adjBCD endif if BitCount == 16 movlw R2 movwf FSR endif call adjBCD call adjBCD call adjBCD goto BCDLoop adjBCD movlw 3 addwf INDF,W ; add 3 movwf Temp ; save it btfsc Temp,3 ; test if result > 7 movwf INDF ; get back the original number if < 8 movlw 30 addwf INDF,W ; add 30 movwf Temp btfsc Temp,7 ; test if result > 7 movwf INDF ; save decf FSR,F retlw 0 end Goodluck Dave dave@mumert.com ----- Original Message ----- From: Gabriel Gonzalez Sent: Friday, June 04, 1999 9:17 PM Subject: 24-bit binary to BCD? > Hi, > > several months ago I remember seeing a nice'n'tight little routine to > convert a 16 bit binary number to BCD. > > Can anybody post a similar one for a 24 bit number? > > This will be great help. > > TIA > > Gabriel >