View previous topic :: View next topic |
Author |
Message |
Guest Guest
|
Time over |
Posted: Wed Jun 08, 2005 10:07 am |
|
|
How to check if the time is over 24?
I want to register 2 hours over (26).
Code: |
#INT_TIMER1
void clock_isr()
{
if(--int_count==0)
{
++sec;
int_count = INTS_PER_SECOND;
if(sec==60)
{
sec=0;
min++;
}
if(min==60)
{
min = 0;
++hour;
}
if (hour==24)
{
//hour = 0;
}
}
} |
|
|
|
valemike Guest
|
|
Posted: Wed Jun 08, 2005 10:17 am |
|
|
if (hour==24)
{
hour = 0;
day++;
}
I figure you could introduce a variable called "day". So if you want to see 2 hours past 24 hours, then you'll have day = 1 and hour = 2. |
|
|
Guest Guest
|
|
Posted: Wed Jun 08, 2005 11:07 am |
|
|
If i want to count days and if i still want to see over time, what then ?
I have problems with understending what will be after :
if (hour==24)
{
hour = 0;
day++;
}
if (day==60)
{
day = 0;
}
When i reach 24 hours, i set the hour=0; so that the timer can correctly count the days. Where can i now define 2 hours over time ?
This is now extended version of my last post.. Now im counting hours and days... |
|
|
valemike Guest
|
|
Posted: Wed Jun 08, 2005 11:29 am |
|
|
I think you want to see how much time has elapsed since a certain time-stamped event.
After an event, just save the seconds, minutes, hours, and days snapshot, and then you can do arithmetic to see how much time has elapsed. |
|
|
Guest Guest
|
|
Posted: Thu Jun 09, 2005 2:23 am |
|
|
So, if i get you right...
Code: |
if (hour==24)
{
hour = 0;
day++;
time_stamp_hours=TRUE;
}
if (day==60)
{
day = 0;
}
...
if (time_stamp_hours && hour==2)
{
do something
else
do something else
}
|
this should work ? |
|
|
Guest Guest
|
|
Posted: Thu Jun 16, 2005 8:56 am |
|
|
Becuse the poster has already ask the "almost" same thing... this is my question...
How to count under hours ( 5 hours over ).
With other words when i reach 0 hours, how can i count hours that are "under" 0. Im making countdown and i must use hours as const and i can not change the value ( it must be 24 ).
Wenn i reach 0 i can not find the way how to corectly count negative hours... |
|
|
valemike Guest
|
|
Posted: Thu Jun 16, 2005 11:28 am |
|
|
Well then you'll need an identical set of variables, and use the prefix
"negative_" so you can meaningfully name those variables.
When your regular counter hits 00:00:00, then start counting up on your second set of of counters. |
|
|
Guest Guest
|
|
Posted: Fri Jun 17, 2005 1:37 am |
|
|
Quote: | When your regular counter hits 00:00:00, then start counting up on your second set of of counters. |
That's the part that i dont understand...
Code: |
if (hour==0)
{
hour = 24;
}
|
now what ?. The hour is 0 and now i must start the second counter. Ok, but how will the second counter knows how many times he must count to take one hour over..
Simpler language :-):
Code: |
if(min==60)
{
min = 0;
hour--;
}
|
This will give me correct countdown till 0 but i can not define another counter inside the min part to count negative time ...
I hope you get what i want to say :-)) |
|
|
Guest Guest
|
|
Posted: Fri Jun 17, 2005 1:40 am |
|
|
.... and then again, how will i get correct time?. Something like -2:15:20 ?
If i set time stamp in each part ( sec, min, hour ) i still dont get it...Must i define 3 different additional counters.. |
|
|
Guest_ Guest
|
|
Posted: Sat Jun 18, 2005 2:38 am |
|
|
On the behalf of those who dont know ( including me :-)) can some of you gurus give some code example / solution for solving problem in last post ? |
|
|
Guest_ Guest
|
|
Posted: Sat Jun 18, 2005 2:39 am |
|
|
On the behalf of those who dont know ( including me :-)) can some of you gurus give some code example / solution for solving problem in last post ? |
|
|
Guest_ Guest
|
|
Posted: Sun Jun 19, 2005 4:08 am |
|
|
What's up gurus, no one has answer to this ..... anyone? |
|
|
|