Searching \ for 'Bin to BCD' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page:
Search entire site for: 'Bin to BCD'.

Truncated match.
PICList Thread
'Bin to BCD'
1997\06\25@051958 by David BALDWIN

I need a 16 bit bin to BCD function. I saw one last week but Can't find
it anymore. Is it possible to get a copy? Thanks


1997\06\25@054728 by Andrew Warren


> I need a 16 bit bin to BCD function. I saw one last week but Can't
> find it anymore. Is it possible to get a copy?


   John Payson wrote the best binary-to-BCD routine that any of us
   has ever seen; he posted it here back in November.

   Since he posted it to the list, I don't think he'll mind if you
   use it in a non-commercial application (although it'd be nice to
   at least give him credit in your source code and send him a
   thank-you note).

   If you want to use it in a commercial application, decency
   demands that you ask his permission first; John's email address

   Anyway, here's his routine:


; Binary-to-BCD.  Written by John Payson.
; Enter with 16-bit binary number in NumH:NumL.
; Exits with BCD equivalent in TenK:Thou:Hund:Tens:Ones.

       org     $0010   ;Start of user files for 16c84

NumH:   ds      1
NumL:   ds      1
TenK:   ds      1
Thou:   ds      1
Hund:   ds      1
Tens:   ds      1
Ones:   ds      1

Convert:                        ; Takes number in NumH:NumL
                               ; Returns decimal in
                               ; TenK:Thou:Hund:Tens:Ones
       swapf   NumH,w
       andlw   $0F             ;*** PERSONALLY, I'D REPLACE THESE 2
       addlw   $F0             ;*** LINES WITH "IORLW 11110000B" -AW
       movwf   Thou
       addwf   Thou,f
       addlw   $E2
       movwf   Hund
       addlw   $32
       movwf   Ones

       movf    NumH,w
       andlw   $0F
       addwf   Hund,f
       addwf   Hund,f
       addwf   Ones,f
       addlw   $E9
       movwf   Tens
       addwf   Tens,f
       addwf   Tens,f

       swapf   NumL,w
       andlw   $0F
       addwf   Tens,f
       addwf   Ones,f

       rlf     Tens,f
       rlf     Ones,f
       comf    Ones,f
       rlf     Ones,f

       movf    NumL,w
       andlw   $0F
       addwf   Ones,f
       rlf     Thou,f

       movlw   $07
       movwf   TenK

                   ; At this point, the original number is
                   ; equal to
                   ; TenK*10000+Thou*1000+Hund*100+Tens*10+Ones
                   ; if those entities are regarded as two's
                   ; complement binary.  To be precise, all of
                   ; them are negative except TenK.  Now the number
                   ; needs to be normalized, but this can all be
                   ;done with simple byte arithmetic.

       movlw   $0A                             ; Ten
       addwf   Ones,f
       decf    Tens,f
       btfss   3,0
        goto   Lb1
       addwf   Tens,f
       decf    Hund,f
       btfss   3,0
        goto   Lb2
       addwf   Hund,f
       decf    Thou,f
       btfss   3,0
        goto   Lb3
       addwf   Thou,f
       decf    TenK,f
       btfss   3,0
        goto   Lb4

       retlw   0



=== Andrew Warren -
=== Fast Forward Engineering, Vista, California

1997\06\25@064905 by David BALDWIN

Thanks a lot, it's only for non commercial use. I'll try this with the
results coming out of my MAX186.


P.S.: In the USA, shouldn't you sleep...?

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