TIMER INTERRUPTS If you want to keep a time-of-day clock by counting timer interrupts, then you must keep the interrupt timing very accurate, i.e. never lose time while reloading the timer. That means running it in auto-reload mode. Unfortunately auto-reload mode on the 8031 means that you only get an 8-bit timer so you have to generate an interrupt every 256 machine cycles. With an 11.0592MHz crystal, that produces 3600 interrupts/second. The interrupt routine must be very lean. In my programs, the interrupt routine looks like this: int_entry: djnz tickcount1,isr_exit mov tickcount1,#36 ... isr_exit: reti Now the stuff at "..." only runs 100 times per second. But the 8031 has interrupts disabled because the "reti" instruction has not been executed yet so if the code takes more than about 512 machine cycles, the next interrupt will be missed. Therefore we enable interrupts again before continuing. Naturally the subsequent code must take less than 1/100 second to run. int_entry: djnz tickcount1,isr_exit mov tickcount1,#36 push PSW push ACC push DPL push DPH mov dptr,#int100 push DPL push DPH isr_exit: reti int100: mov PSW,#08h ... pop DPH pop DPL pop ACC pop PSW ret Now the code at "..." runs 100 times per second, can take much longer than 256 machine cycles to run, and can freely use the registers that were saved. Moreover the modified PSW selects memory locations 8-15 as registers R0-R7, so if the mainline uses locations 0-7, the interrupt routine gets its own set of registers that even maintain their contents between interrupts.