We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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).
You'd have to let the simulator run >20x longer for the polling version to simulate the same number of instruction cycles (states).