- This topic has 2 replies, 2 voices, and was last updated 8 years ago by .
Viewing 3 posts - 1 through 3 (of 3 total)
Viewing 3 posts - 1 through 3 (of 3 total)
- You must be logged in to reply to this topic.
|
Microcontroller › 8051 › Interrupt Service routine and Timers
Hi,
I am a newbie to this world, so please excuse me and explain it to me if I am asking blunders. The piece of code giving me headache is given below
void Timer0_Init()
{
TMOD&=0xF0;
TMOD|=0x01;
TR0=0;
TF0=0;
TH0=0;
TL0=0;
ET0=1;
TR0=1;
EA=1;
}
void Timer0_Sleep()
{
PCON|=0x01;
}
void Timer0_ISR() interrupt 1
{
TR0=0;
TF0=0;
TH0=0;
TL0=0;
TR0=1;
}
From this section of code I expect Timer 0 to set TF0 flag when it overflows but in simulator (Kiel uVision) this piece of code is never setting TF0 flag before going to ISR. Instead the program calls ISR without even setting TF0 and then loading TH0 with 0x00 and TL0 with 0x04. I don't understand why this is happening. I believe the reason for calling interrupt service routine is the setting of TF0 but here ISR is being called magically without even setting TF0. I don't know if I am missing something… Please help
Hi Sreerag
This code snippet seems to be fine. Could you please share the entire code, I mean the main() as well. Also comment on how you are checking the TF0 bit's status.
The main () is as follows
void main()
{
Timer0_Init();
while(1)
{
void Timer0_Sleep();
}
}
I tried to monitor TF0 flag via simulator in Keil uVision. On step by step simulation it can be seen that till 0xFFFF Timer0 register is incrementing properly. But after 0xFFFF instead of 0x0000, 0x0004 is getting loaded on to Timer0 register ie. TH0 and TL0 and Flag is not setting