Well first I'd probably rename DisplayValue to be something more meaningful like DisplaySeconds.
Then I might add
if ( DisplaySeconds == 60 ) {
DisplaySeconds = 0;
DisplayMinutes++;
}
I gather from your code you have a pair of 7-segment displays for displaying seconds.
Do you have another pair for the minutes as well.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
Here's an algorhithm in C/C++. You can convert it into whatever you're using.
int sec = 0;
int min = 0;
int hour = 0;
while(1)
{
sleep(1000); //delay in milliseconds
++sec;
if(sec == 60)
{
sec = 0;
++min;
if(min == 60)
{
min = 0;
++hour;
if(hour == 24)
{
hour = 0;
}
}
}
display(hour, min, sec);
}
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
Well what you do in software depends entirely on what you've done with the hardware.
Say for example, you use 4 bits to drive one 7-segment display, then use the other 4 bits to choose one of 4 displays
Say
bit 7 selects the 10's for M
bit 6 selects the units for M
bit 5 selects the 10's for S
bit 4 selects the units for S
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
when your display value reaches 60, you add 1 to minutes, and
keep doing this until your minutes adds to 1 hour;
Try this circular loop :
displayValue = ++displayValue % 60;
min = displayValue % 60 + displayValue/60
hour = min % 60 + min/60
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608