Hello,
I have a two source codes that may return the same result but they dont.
1.interrupt version:
#include <AT892051.H> unsigned long timer0_tick; void timer0_isr (void) interrupt 1 { timer0_tick++; } int main (void) { TMOD |= 0x1; // 16b mode timer 0 ET0 = 1; timer0_tick = 0; TL0 = 0x0; TH0 = 0x0; TR0 = 1; EA = 1; while (1) ; }
After 5 seconds simulating, timer0_tick is about 1970 (ticks)
2.polling version
#include <AT892051.H> unsigned long timer0_tick; int main (void) { TMOD |= 0x1; // 16b mode timer 0 timer0_tick = 0; TL0 = 0x0; TH0 = 0x0; TR0 = 1; while (1) { while (TF0 == 0) ; TF0 = 0; timer0_tick++; } }
In this case, after 5 seconds simulating timer0_tick is about 79(ticks).