Searching \ for '32bit 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/index.htm?key=32bit+binary+bcd
Search entire site for: '32bit binary to bcd'.

Truncated match.
PICList Thread
'32bit binary to bcd'
1997\11\26@040917 by Mike Watson

flavicon
picon face
Hi,

I have a need for an unsigned 32 bit binary to bcd routine.

A number have been posted in the past, and there is the 16 bit
version in ECH which could be extended,

but what would be really nice is a routine that produces the
decimal digits in turn starting from the left. This way they
can be sent to an LCD display or rs232 port without having to
be stored in memory.

Any ideas anyone?


Regards,

Mike Watson

1997\11\26@104325 by Bob Fehrenbach

picon face
Mike Watson <spam_OUTmikeTakeThisOuTspamD-M-G.DEMON.CO.UK> wrote:
>I have a need for an unsigned 32 bit binary to bcd routine.
>
>what would be really nice is a routine that produces the
>decimal digits in turn starting from the left. This way they
>can be sent to an LCD display or rs232 port without having to
>be stored in memory.

Mike,

  A conventional subtract and increment routine will generate the
  decimal digits one at a time but would be very slow for numbers of
  this size.

  Since a 32 bit number can be over 4E10, you would start with
  subtracting 1E10 and incrementing the 'billions' digit each time the
  result is still positive.  Then move on to the next power of ten.

  The following is an extension of the approach in the Microchip app
  note.


   ;Binary - BCD   32 bits
   ;Input in buff_4|buff_3|buff_2|buff_1,
   ;
   ;Converts to packed bcd in temp_a, temp_b, temp_c, temp_d and temp_e
   ;with the MSD temp_a.

   ;Also uses temp_f and count.

   ;2940 cycles including call and return.

bin2bcd:
  bcf     STATUS, C
  movlw   32
  movwf   count
  clrf    temp_a
  clrf    temp_b
  clrf    temp_c
  clrf    temp_d
  clrf    temp_e

bin2bcd_loop:
  rlf     buff_1, f
  rlf     buff_2, f
  rlf     buff_3, f
  rlf     buff_4, f
  rlf     temp_e, f
  rlf     temp_d, f
  rlf     temp_c, f
  rlf     temp_b, f
  rlf     temp_a, f

  decfsz  count, f
  goto    adj_dec
  goto    done

adj_dec:
  movlw   temp_e
  movwf   FSR
  call    adj_bcd

  movlw   temp_d
  movwf   FSR
  call    adj_bcd

  movlw   temp_c
  movwf   FSR
  call    adj_bcd

  movlw   temp_b
  movwf   FSR
  call    adj_bcd

  movlw   temp_a
  movwf   FSR
  call    adj_bcd

  goto    bin2bcd_loop

adj_bcd:
  movlw   h'3'
  addwf   INDF, w
  movwf   temp_f
  btfsc   temp_f, 3
  movwf   INDF
  movlw   h'30'
  addwf   INDF, w
  movwf   temp_f
  btfsc   temp_f, 7
  movwf   INDF
  return

done:
  return


--
Bob Fehrenbach    Wauwatosa, WI     .....bfehrenbKILLspamspam@spam@execpc.com

1997\11\27@053203 by STEENKAMP [M.ING E&E]

flavicon
picon face
Hi,

> I have a need for an unsigned 32 bit binary to bcd routine.
>
> A number have been posted in the past, and there is the 16 bit
> version in ECH which could be extended,
>
> but what would be really nice is a routine that produces the
> decimal digits in turn starting from the left. This way they
> can be sent to an LCD display or rs232 port without having to
> be stored in memory.
>
If you are writing the number out on a an LCD character module, you can
command the LCD to move its cursor from right to left.  This gives you
the added advantage of neat, right alligned numbers.  If you are looking
for a compact 32bit divide by 10 routine, mail me and I'll send it to you.

Niki

1997\11\27@072026 by akdavid

flavicon
face
> If you are looking
> for a compact 32bit divide by 10 routine, mail me and I'll send it to
you.
>
> Niki


       Would it be possible to take a look?




- Andy.
---------------------------------------------
Andrew David, Software Manager, Ultronics Ltd.
AKDavidspamKILLspamUltronics.co.uk
---------------------------------------------

1997\11\27@092216 by Mike Watson

flavicon
picon face
In message  <.....450FBF322C2KILLspamspam.....firga.sun.ac.za> EraseMEPICLISTspam_OUTspamTakeThisOuTMITVMA.MIT.EDU writes:
> Hi,
>
> > I have a need for an unsigned 32 bit binary to bcd routine.
> >
> > A number have been posted in the past, and there is the 16 bit
> > version in ECH which could be extended,
> >
> > but what would be really nice is a routine that produces the
> > decimal digits in turn starting from the left. This way they
> > can be sent to an LCD display or rs232 port without having to
> > be stored in memory.
> >
> If you are writing the number out on a an LCD character module, you can
> command the LCD to move its cursor from right to left.  This gives you
> the added advantage of neat, right alligned numbers.

Niki,

I was aware of this, but have no idea how to achieve it with the
CCS compiler.

Anyone else know?


Regards,

Mike Watson

1997\11\27@204149 by Mike Henning

flavicon
face
>Hi,
>
>> I have a need for an unsigned 32 bit binary to bcd routine.
>>
>> A number have been posted in the past, and there is the 16 bit
>> version in ECH which could be extended,
>>
>> but what would be really nice is a routine that produces the
>> decimal digits in turn starting from the left. This way they
>> can be sent to an LCD display or rs232 port without having to
>> be stored in memory.


I use a 32 bit subtract routine that works well for me.
It's outputs each digit from left to right. It's not all that
fast, but works well. (i.e. max instructions per digit is
about 200 and the min is about 30)

Let me know if you want the source for it?

Mike H.
mikeh1spamspam_OUTfuse.net

1997\11\28@015442 by STEENKAMP [M.ING E&E]

flavicon
picon face
Hi,

> > If you are looking
> > for a compact 32bit divide by 10 routine, mail me and I'll send it to
> you.
> >
> > Niki
>
>
>         Would it be possible to take a look?
>
Here is the routine I use:

;=========================================================================
;Divide the 32 bit number in N_3:N_2:N_1:N_0 by 10 and store the result
;in N_3:N_2:N_1:N_0 and the remainder in Rem.  If the quotient and the
;remainder is 0, the Z flag is set.  This is useful for leading zero
;suppression.
;Additional register used: C1
;=========================================================================
Div10:
      movlw  32
      movwf  C1                        ;Repeat for 32 bits
      clrf   Rem
Div10Loop:
      rlf    N_0,W
      rlf    N_1,F
      rlf    N_2,F
      rlf    N_3,F
      rlf    Rem,F                     ;Move MSB of Number into Temp
      movlw  10
      subwf  Rem,W                     ;Does 10 go in?
      btfsc  STATUS,C
       movwf Rem                       ;If so, update remainder
      rlf    N_0,F                 ;If 10 went in, shift in a 1, if not
                                       ;shift in a 0
      decfsz C1,F
       goto  Div10Loop                 ;Repeat for all bits

      movf   N_0,W                     ;Test if Quotient is 0
      iorwf  N_1,W                     ;Test if Quotient is 0
      iorwf  N_2,W                     ;Test if Quotient is 0
      iorwf  N_3,W                     ;Test if Quotient is 0
      iorwf  Temp,W                    ;Test if Remainder is also 0
      return

16 words without the leading zero detection, 21 with it.
Each consecutive call to the divide routine will return the next digit in
the number.  If the Z flag is set, then the digit returned is a leading
zero.  Main advantage of the divide approach against the subtract
approach is that it is more compact.

Niki

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