8051 timer doubt
eah, but it still does the Auto-reloading stuff, and the timer never stops...
that's correct. the only time TFx is cleared by hardware is if you vector to a (tmr) interrupt.
Nothing wrong with the statement,
it is wrong because it is not consistent with how the device works. you can easily test it on your own.
whether there is a webpage suggesting it is irrelevant.
Added after 2 hours 44 minutes:
to show that TFx isnot clear when the timer overflows in mode 2 (8-bit timer + auto reload), here is a simple example.
Code:
#include <REGX51.H>
#include "gpio.h"
#define LED_PORT P2
#define LED (1<<0)
void t0_init(void) { //initiate tmr0 - no interrupt enabled
TMOD = (TMOD & 0xf0) | 0x02; //tmr0: mode 2, not gated, internal clock
TH0=256-0xff; //autorelated to tho's content
TR0=1; //turn on tmr0
}
void mcu_init(void) { //initiate the mcu
}
int main(void) {
mcu_init(); //initiate the mcu
t0_init(); //initiate tmr0
while (1) {
while (!TF0) continue; //wait for tmr0 to overflow
TF0=0; //reset trf0
IO_FLP(LED_PORT, LED); //flip led
P3=TF0; //output the value of TF0 on P3.0
}
}
it essentially wait for the timer to overflow, reset the flag, and then flip LED (on p2.0).
as the auto reload is TH0=1, the code counts 255 cycles before it overflows. on a 12-state 8051 with 12Mhz xtal, it should overflows every 255us, and LED should be producing a square wave of 1/255us/2=1961hz.
try it on your 8051 and see for yourself if it is true.
Added after 1 minutes:
Notice that in the above program, we had to manually reset TF0 (since we are not using an interrupt here).
if you were to comment out that line - ie not resetting TF0 after tmr0 overflows, you will get much faster flipping on LED.
alternatively, you can observe P3.0's level as it represents the value of TF0.