Embedded_Geek
Full Member level 6
what will happen if i don't clear timer flag in 8051? I mean will the timer continue to run even if timer flag is 1. I m talking about mode 2(autoreload).
Thanks in advance
Thanks in advance
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
what will happen if i don't clear timer flag in 8051?
"Once you have configured a timer in mode 2 you do not have to worry about checking to see if the timer has overflowed nor do you have to worry about resetting the value
there is no need to clear TF flag. after overflow, TH will be reloaded with the value of TL, TF resets and timer starts counting till you stops timer.
Nothing wrong with the statement, you can find the complete article form **broken link removed**.millwood said:that statement is not true.
millwood said:there is no need to clear TF flag. after overflow, TH will be reloaded with the value of TL, TF resets and timer starts counting till you stops timer.
what you said is only true if an interrupt is used. Otherwise, TFx is never cleared by hardware and you have to clear it manually.
eah, but it still does the Auto-reloading stuff, and the timer never stops...
Nothing wrong with the statement,
#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
}
}