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

plz any one tell me how to work with timer.

plz any one tell me how to work with timer.

i m working with p89v51rd2.
in that i m trying to a simple program which showing the numbers on led as counter.

logic of my program is when one cycle is complete of timer than number have to change.

but i m not able to do this.

TMOD=0x20; that is for timer for 2 mode which 16 bit
TH1=0xf3; that is for 2400 bugd rate but convert to 9600

any one help me plz.....

Parents
  • That's still a bit of a mess!

    Your code would be a whole lot easier for you & others to read if you take time to lay it out carefully; eg,

    void main()
    {
       P2  = 0xff; //Commissioner of all the lights
    
       TMOD= 0x01; //Timer/Counter 0 work in a way
       TH0 = 0x4C;
       TL0 = 0x00; //50ms time constants
    
       EA  = 1;    //A total interruption
       ET0 = 1;    //Allow time / Counter 0 interrupted
       TR0 = 1;    //Start time / Counter 0 interrupted
    
       move = 0xfe;
    
       while(1);
    }
    

    Any particular reason why you use #define instead of typedef?

    Are you sure that those comments will really be meaningful when you look at this again in 6 months...?

    Avoid the use of "Magic Numbers" - define constants with meaningful names.

Reply
  • That's still a bit of a mess!

    Your code would be a whole lot easier for you & others to read if you take time to lay it out carefully; eg,

    void main()
    {
       P2  = 0xff; //Commissioner of all the lights
    
       TMOD= 0x01; //Timer/Counter 0 work in a way
       TH0 = 0x4C;
       TL0 = 0x00; //50ms time constants
    
       EA  = 1;    //A total interruption
       ET0 = 1;    //Allow time / Counter 0 interrupted
       TR0 = 1;    //Start time / Counter 0 interrupted
    
       move = 0xfe;
    
       while(1);
    }
    

    Any particular reason why you use #define instead of typedef?

    Are you sure that those comments will really be meaningful when you look at this again in 6 months...?

    Avoid the use of "Magic Numbers" - define constants with meaningful names.

Children