Searching \ for '[PIC]: Adding to time-of-day in BCD' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/time.htm?key=time
Search entire site for: 'Adding to time-of-day in BCD'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Adding to time-of-day in BCD'
2001\02\13@114432 by Brian Aase

flavicon
face
I've looked around for info on this, but can't seem to find an
appropriate link. Surely this has been done before and is
probably posted somewhere.  Can someone please point
me in the right direction?

Given: A set of 7 variables holding the time of day in BCD
format for eventual display on a LED readout, thus:

seconds
tensecs
minutes
tenmins
hours
tenhours
am_pm_bit

What I need to do is add an arbitrary number of seconds (in
the range of 0 to 240) to the time held in the above variables,
in order to make the time appear that much farther ahead.
The seconds to be added are originally held in a single (binary)
byte but could first be converted to BCD if that makes it any easier.

Hints? Pointers? Comments? Flames? Anyone?

Brian Aase

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


2001\02\13@120147 by Drew Vassallo

picon face
>seconds
>tensecs
>minutes
>tenmins
>hours
>tenhours
>am_pm_bit
>
>What I need to do is add an arbitrary number of seconds (in
>the range of 0 to 240) to the time held in the above variables,
>in order to make the time appear that much farther ahead.

My suggestion:

Divide by 60 to get minutes.  Remainder is total seconds to add.
Divide by 10.  Remainder is single digit seconds to add.
Add result to tensecs.  On overflow past 60, increment minutes, etc.
Add remainder of seconds to existing seconds.  On overflow past 10,
increment tensecs, etc. and on up.

I don't think there's an easy way.

--Andrew
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

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


2001\02\13@120521 by Andrew Warren

face
flavicon
face
Brian Aase <spam_OUTPICLISTTakeThisOuTspamMITVMA.MIT.EDU> wrote:

> Given: A set of 7 variables holding the time of day in BCD
> format for eventual display on a LED readout
> ....
> What I need to do is add an arbitrary number of seconds (in
> the range of 0 to 240) to the time held in the above variables,
> in order to make the time appear that much farther ahead.

Brian:

Presumably, you already have a routine which increments your time-of-
day variables.  Why not just call it 0-240 times?

If the time were stored as packed BCD, you could even use the routine
on my web page:

   http://www.geocities.com/siliconvalley/2499/code.html

-Andy


=== Andrew Warren - .....fastfwdKILLspamspam@spam@ix.netcom.com
=== Fast Forward Engineering - San Diego, California
=== http://www.geocities.com/SiliconValley/2499

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


2001\02\13@122304 by Brian Aase

flavicon
face
> Presumably, you already have a routine which increments your time-of-
> day variables.  Why not just call it 0-240 times?

Actually, I don't already have one.  The data comes in as unpacked
BCD just as shown.  Where can I find one?

> If the time were stored as packed BCD, you could even use the routine
> on my web page:
>
>     http://www.geocities.com/siliconvalley/2499/code.html
>

Will check it out, thanks.

Brian Aase

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


2001\02\13@172631 by Bob Ammerman

picon face
Examples below are in a "C" like syntax, but the concepts apply equally well
to assembly language.

If you have plenty of time to do the update, you could do it like this:

   while (delta--)
       IncrementTime();

an 'IncrementTime() routine is much simpler than a full add.

If you have to do a full add at one time, something like this could work:

   seconds += delta;
   delta = 0;
   while (seconds > 9)
   {
       ++delta;
       seconds -= 10;
   }

   tensecs += delta;
   delta = 0;
   while (tensecs > 5)
   {
        ++delta;
        tensecs -= 6;
   }

   minutes += delta;
   if (minutes > 9)
   {
       minutes -= 10;
       ++tenmins;

       if (tenmins > 5)
       {
           tenmins -= 6;

           // hours is tricky because the sequence is:
           // 12, 1, 2, 3...11 -> 12 and the carry to AM/PM
           // occurs on the transition from 11 to 12
           ++hours;
           if (tenhours == 0)
           {
                if (hours > 9)
                {
                       // from 9 to 10 o'clock
                       hours = 0;
                       tenhours = 1;
                }
           }
           else
           {
               if (hours == 2)
               {
                   // from 11 to 12 o'clock
                   ampm ^= 0x01;        // toggle AM/PM indicator
               }
               else if (hours == 3)
               {
                   // from 12 o'clock to 1 o'clock
                   hours = 1;
                   tenhours = 0;
               }
           }
       }
   }

The above has the advantage that it performs no multiplication or division.
Military (24-hour) time would be  a bit easier.

Warning: the above code is _not_ tested!

Bob Ammerman
RAm Systems
(contract development of high performance, high function, low-level
software)



{Original Message removed}

2001\02\13@205846 by Brian Aase

flavicon
face
Bob, many thanks for your kind suggestion.  In fact, I got a first
prototype going this afternoon using your (and Andy Warren's)
looped-increment idea and it does work.  But just out of
stubbornness, I want to at least try a once-through approach
as you have suggested, if only because it seems like "the
right thing to do".  I'll be studying your message in detail ;-)
and really appreciate the time you took to type it out.
Brian Aase

On 13 Feb 2001, at 17:05, Bob Ammerman wrote:

{Quote hidden}

> {Original Message removed}

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