Searching \ for '32 bit and 24 bits to BCD' in subject line. ()
Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=bit+bits+bcd
Search entire site for: '32 bit and 24 bits to BCD'.

Truncated match.
'32 bit and 24 bits to BCD'
1999\03\31@044110 by

Hello!

I need to implement some 24 bits and a 32 bits counter in my
application, in Assembly.
I'm not ready yet to go into PIC C.

I have seen 16bit to BCD, from John Payson, but I couldn't find a way to
expand it
to 24 bit and 32 bits.

Does anyone have such routines?

I know I could use division by 10 and module 10, but if there's a more
efficient way, I would prefer it.

Thank you,
Nuno Pedrosa.
--
----  ~~~~~~~  -------  Nuno Filipe Freitas Pedrosa
--  ~~~~     ~~  -----  SIEMENS S.A. Portugal       TEL: +351 1 4242454
-  ~~~~       ~~  ----  Nuno.Pedrosaicn.siemens.de
-  ~~~~       ~~  ----  "MSWindows - Best run on a SlideShow"
=======================================================================

>
> Hello!
>
> I need to implement some 24 bits and a 32 bits counter in my
> application, in Assembly.
> I'm not ready yet to go into PIC C.
>
> I have seen 16bit to BCD, from John Payson, but I couldn't find a way to
> expand it
> to 24 bit and 32 bits.
>
> Does anyone have such routines?
>
> I know I could use division by 10 and module 10, but if there's a more
> efficient way, I would prefer it.

The most efficient way is to count in packed BCD. It'll take 4 bytes for
24 bits (up to 16000000 and change) and 5 bytes for 32 bits.

Here's how to count in packed BCD:

1) Start at the lowest byte. Add 1.
2) If the low nybble is A, do a BCD adjust by adding 6 to it.
3) If the high nybble is A, do another BCD adjust by adding h'60' to it.
4) Do the next higher byte if the carry is set.

So for example if you have
00001999
(note that this is 4 consecutive bytes in hexidecimal representing packed BCD)
0000199A
000019A0
00001900
Since the carry is set goto the next byte and add 1 to it.
00001A00
00002000
And voila! there's the incremented value.

Off the cuff is seems that using FSR/INDF and a tight loop could get this done
fairly efficiently since the adjustment process is the same for each nybble

Hope this helps,

BAJ

I sent it Private to Nuno.

Andy

At 10:28 AM 3/31/99 +0000, you wrote:
{Quote hidden}

\-----------------/
\     /---\     /
\    |   |    /          Andy Kunz
\   /---\   /           Montana Design
| /  |----|___|----|  \ |
\/___|      *      |___\/     Go fast, turn right,
and keep the wet side down!

Hello!

Yes, this seems like an option...
I had thought of this, but didn't like the idea of repeating N times the
increment code.
But, the way you put it seems feasible in an elegant way.
I'll try it. At least, I understand it, which is more than I can say of
those tricky BCD conversion routines! 8)

My ugliest problem here, is the comparison with the constant. Feels
quite cumbersome to be
subtracting values just to check if the value is equal...

Thanks,
Nuno Pedrosa.

Byron A Jeff wrote:
{Quote hidden}

--
----  ~~~~~~~  -------  Nuno Filipe Freitas Pedrosa
--  ~~~~     ~~  -----  SIEMENS S.A. Portugal       TEL: +351 1 4242454
-  ~~~~       ~~  ----  Nuno.Pedrosaicn.siemens.de
-  ~~~~       ~~  ----  "MSWindows - Best run on a SlideShow"
=======================================================================

On Wed, 31 Mar 1999 07:54:24 -0500 Byron A Jeff <byronCC.GATECH.EDU>
writes:

>> I know I could use division by 10 and module 10, but if there's a
>more
>> efficient way, I would prefer it.

The BCD multiply by 2 method is most efficient for large numbers.  It is
easy to expand.  If you already have a division routine in the program
for something else, reusing it for a modulo-10 method could save space.

>The most efficient way is to count in packed BCD.

Generally you are counting a lot and displaying the count only
occasionally.  So it is more efficient to count in binary and convert for
display purposes.  If you need to update the display after every count,
it would make sense to count in BCD.  But if you need to do any math with
the count, maybe binary would be better.  Of course, it is real simple to
convert from BCD to binary if necessary.

The PIC has a digit-carry flag which is useful for packed BCD operations.
The code below should add 1 to a BCD number.  I don't use BCD much at
all so it may be wrong.

movlw   h'67'           ;66 + 1
movlw   0               ;assume no correction needed
skpdc                   ;Carry out of low digit: it's OK.
movlw   h'06'           ; correct the low digit
skpc                    ;Carry out of high digit means don't
iorlw   h'60'           ; correct the high digit
subwf   bcd,f           ;Fix digits that didn't roll
over

To carry the count into higher digits, look at the carry out of the first
addition.  If it is set, then the higher digits need to be incremented
too.  I don't know offhand if the carry out of the subtraction means
anything useful.

___________________________________________________________________
Get completely free e-mail from Juno at http://www.juno.com/getjuno.html
or call Juno at (800) 654-JUNO [654-5866]

On Wed, 31 Mar 1999 14:35:58 +0000 Nuno Pedrosa
<Nuno.PedrosaOEN.SIEMENS.DE> writes:

>My ugliest problem here, is the comparison with the constant. Feels
>quite cumbersome to be
>subtracting values just to check if the value is equal...

To compare if equal, just XOR byte by byte.  If the numbers are equal,
all the xor's will result in zero.  It works for any format of number,
binary or BCD.

___________________________________________________________________
Get completely free e-mail from Juno at http://www.juno.com/getjuno.html
or call Juno at (800) 654-JUNO [654-5866]

'32 bit and 24 bits to BCD'
1999\04\01@054513 by
Thanks to all who replied to my question!
I got it working last night!

For now, I'll be using BCD arithmetics, but I'll change to binary and
use
a bin2bcd conversion routine later. Since I'd like to understand what
I'm doing,
I'll use the multiply by 2 method. I still don't know how it works, but
everything
should be clear with some study.

I now have an adjustable step counter with Clear, using five 7seg
displays.
Hardware is:
- 16f84
- some resistors
- 5 transistors
- 5 7seg displays
- 1 button
- 1 diode

Software is:
- Paul Webster idea for muxing 7segs displays. Great idea!
- Scott Dattalo debounce routine (still got to study this one a little
more)
- Jeff Byron and Mike Keitz ideas for BCD counters

Everything is working great, and I still have 4 (That's _four_) pins
available!

Program flow is based on semaphores, to avoid useless delays.
TMR0 is triggering every 125us on a 8192MHz Xtal, to provide base
delays.
The interrupt routine handles the delays and sets the semaphores.

I still have a lot of ideas to implement, and a lot of space to grow in
the Pic.
Which I had more RAM, though... 8)

Bye,
Nuno Pedrosa

--
----  ~~~~~~~  -------  Nuno Filipe Freitas Pedrosa
--  ~~~~     ~~  -----  SIEMENS S.A. Portugal       TEL: +351 1 4242454
-  ~~~~       ~~  ----  Nuno.Pedrosaicn.siemens.de
-  ~~~~       ~~  ----  "MSWindows - Best run on a SlideShow"
=======================================================================

1999\04\05@195219 by
Mike Keitz wrote:
{Quote hidden}

Check out my website below.  There is an efficient BCD
increment/decrement routine up to any number of digits there.  Also
found are binary to BCD conversion routines.

regards,
Reggie

--
e-mail: rberdinbigfoot.com
ICQ#:   31651436
URL:    http://www.bigfoot.com/~rberdin

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