--- In , "Wouter van Ooijen" <wouter@v...> wrote: > > This can be made to work but is very tricky to get exactly right. Any > > changes to the code require refiguring the exact clock count and you > > have to compute all the code paths. Being off by 0.1% is 86 seconds > > a day - pretty bad. > > > > A much better solution is to set up a timer to generate interrupts > > every, say, 10 mS. Actually, any period will work, within limits. In > > the interrupt routine, increment a counter and when it gets to 1 > > second (100 interrupts in this case), increment the seconds counter as > > well as bump minutes and hours when appropriate. There are techniques > > for ensuring no lost time if the interrupt handler is late. In the > > main loop, you compare the current second value with the one you wrote > > into the LCD. When they are different, save the new seconds count and > > update the LCD. very simple and very accurate. > > My Jal language has a library function for this: the interval delay. You > just set it up for a certain period, and then call await_next_interval > at the top of your loop. > > Wouter van Ooijen And definitely interval is a very clever library indeed. I really don't know why I like more a quite similar way with the methode presented above, even as an old Jal user (shame me!) :). Maybe just because interval reminds me about the high level languages which don't let you to modify a compiler defined (hidden) instruction (like some PIC basic compilers). Vasile |