Searching \ for '[PIC]: Routine binary to BCD?' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/microchip/devices.htm?key=pic
Search entire site for: 'Routine binary to BCD?'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Routine binary to BCD?'
2000\08\04@155153 by Diana Cristina Franco

flavicon
face
Hello to every body,
I am looking for a routine to convert a 3 byte binary number (24 bits)
to
a 8 digit BCD number, to implement in a PIC16c7x.

I would appreciate any help.

Thanks.
  Diana Franco.

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

2000\08\05@065317 by Oliver Broad

flavicon
face
The following program is based on the binary to BCD code from the microchip
appnote. The method seems odd at first, compared to the more conventional
divide-by-10-and-output-the-remainder.

It was originally written to convert data from an AD7714 sigma delta ADC

Oliver.





; Looping version of Binary to BCD converter for 24 bit values
; Code is designed for MPSIM testing, so insert stimuli on ports
; B and B and B, and read out R0,R1,R2,R3.

; Code is based on the fact that a bcd number may be multiplied
; by two by a simple bit shift followed by a BCD fixup. The
; fixup is greatly simplified by performing it BEFORE the shift,
; which is why 3 and 30H are used instead of 6 and 60H.


       LIST P=16C73
       INCLUDE P16C73.INC
       CBLOCK  20H
       R3,R2,R1,R0        ;MUST START ON BINARY XXXXX000.
       COUNT, LBYTE, MBYTE, HBYTE
       ENDC
       ORG     0
MAIN    MOVFW   PORTB
       MOVWF   LBYTE
       MOVFW PORTB
       MOVWF MBYTE
       MOVFW   PORTB
       MOVWF   HBYTE
       CALL    BIN2BCD
       GOTO    MAIN
BIN2BCD MOVLW   18H
       MOVWF   COUNT
       CLRF    R0
       CLRF    R1
       CLRF    R2
       CLRF    R3
       BCF     STATUS,C
       GOTO    BIN2BC2
BIN2L   MOVLW   R3
       MOVWF   FSR
BCDADJ  MOVLW   03H
       ADDWF   INDF,F
       BTFSS   INDF,3
       SUBWF   INDF,F
       MOVLW   30H
       ADDWF   INDF,F
       BTFSS   INDF,7
       SUBWF   INDF,F
       INCF    FSR,F
       BTFSS   FSR,2
       GOTO    BCDADJ
BIN2BC2 RLF     LBYTE,F
       RLF  MBYTE,F
       RLF     HBYTE,F
       RLF R3,F
       RLF     R2,F
       RLF     R1,F
       RLF     R0,F
       DECFSZ  COUNT,F
       GOTO    BIN2L
       RETLW   0
       END






{Original Message removed}

More... (looser matching)
- Last day of these posts
- In 2000 , 2001 only
- Today
- New search...