This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Timer in autoload mode

I use Keil sometimes and while using a timer in autoload mode, the TH0 is loaded with the calculated value but TL0 starts incrementing from 00 instead of the calculated value F0.Am I missing something while using or configuring the keil simulator?

Parents
  • "show some actual, complete, indented, commented code"

    his code is actual and complete, sufficient to get you to his "problem", as is.

    but here is his code presented in a nicer way, per your request.

    #include <reg51.h>
    
    void delay();
    sbit mybit = P1^5;
    
    main()
    {
            while(1)
            {
                    mybit = mybit^1;
                    delay();
            }
    }
    
    void delay()
    {
            TMOD = 0x02;
            TH0 = 0xF0;
            TL0 = 0xF0;
            TR0 = 1;
            while (TF0==0);
            TR0 = 0;
            TF0 = 0;
    }
    

Reply
  • "show some actual, complete, indented, commented code"

    his code is actual and complete, sufficient to get you to his "problem", as is.

    but here is his code presented in a nicer way, per your request.

    #include <reg51.h>
    
    void delay();
    sbit mybit = P1^5;
    
    main()
    {
            while(1)
            {
                    mybit = mybit^1;
                    delay();
            }
    }
    
    void delay()
    {
            TMOD = 0x02;
            TH0 = 0xF0;
            TL0 = 0xF0;
            TR0 = 1;
            while (TF0==0);
            TR0 = 0;
            TF0 = 0;
    }
    

Children