im currently syudying 8051 from mazidi, i have a doubt in this particular problem
inside the do while loop as soon as the counter starts the tl0 register is incremented
which is passed as value to the totime function now the current value of value will 197(decimal) it will not show the correct min and sec?
intially as the timer is in mode 2 the value tlo(256-60) hence as the counter starts(tr0=1) tlo will be incremented by the first clock pulse and assigned to value
The program should be likethis:
....
val=0;
while(1)
{
TR0=1; // start timer0
while(TF0==0); // wait till timer flag 0 overflow
TR0=0; // stop timer0
TF0=0; // clear timer flag 0
val++; // increament val by 1
ToTime(val); // function calculate min & sec and output to P2 and P1
}