'Another way to do BCD'
There is currently a discussion on the list regarding Binary to
BCD conversion. For the sake of people who are new to programming
I would just like to mention an alternative to Binary to BCD
conversion: Accumulate the data in BCD to begin with!
While this method is not always applicable, there are many cases
where the binary value isn't used for anything except conversion
to BCD. So why not set up some file registers as places to hold the
Units, Tens, Hundreds, etc.? When you update the counter set you
check for ten (0AH) and reset the current digit to zero and perform
a carry. Indirect addressing gives you a simple way to move from
digit to digit when a carry occurs. Such carrys can ripple through
multiple digits when there are several '9's in a row.
If a binary count is *also* desired, accumulate that in a separate
binary counter file register set.
This method works well if you have adequate time during accumulation
of the counts to perform the BCD additions and carrys.
As a further note, each 8 bit byte can hold TWO BCD nibbles, so
storing a number like 999,999 only requires three file registers.
The same methods can be used to store things like time-of-day which
require certain digit sets to have modulo 60, modulo 12 and the like.
While purists may turn up their noses at such techniques, these
methods do have the advantage of being easy to understand and
implement. Although not "optimal" solutions for all cases, they
are easy for beginners to use, so they *do* have their place.
Respectfully submitted for the sake of those who want to learn,
Fr. Tom McGahee
part 0 935 bytes
Definitely. Depending upon the application and the relative
frequencies of displaying the data vs updating it, working
with "native format" numbers can make many types of operations
On a somewhat related note, it's sometimes a good idea to
configure the physical aspects of your system and/or sampling
intervals to allow optimal numeric display. For example, if
you have an motor tach input that pulses once each rev and you
wish to display the motor speed in RPMx100, counting the number
of pulses every 1/100 minute will be easier and more accurate
than counting the number every second and multiplying by 0.6.
Or, if you're trying to measure temperature with a 10mV/degC
temperature chip/op amp feeding an A/D, it may be a good idea
to adjust your op-amp's gain so that full-scale on the A/D is
640mV (to convert the A/D into temperature Celcius, just divide
by four; no fractional maths required).
More... (looser matching)
- Last day of these posts
- In 1998
, 1999 only
- New search...