EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / Interrupt Service routine and Timers

Interrupt Service routine and Timers

|

Microcontroller › 8051 › Interrupt Service routine and Timers

  • This topic has 2 replies, 2 voices, and was last updated 9 years, 5 months ago by Sreerag.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • December 22, 2016 at 8:54 pm #4590
    Sreerag
    Participant

    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

     

    December 23, 2016 at 5:27 am #14292
    GANEEV SINGH
    Participant

    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.

    December 23, 2016 at 10:46 am #14293
    Sreerag
    Participant

    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

  • Author
    Posts
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • What is the most suitable light source for making a book light like this? June 9, 2026
  • How charging is done in Transformer Inverters June 9, 2026
  • extracting material properties from open load resonance June 9, 2026
  • Oshon Basic, programing IF statements June 8, 2026
  • USBASP Programming problems June 8, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise