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

set timer as counter

Hi, my name is hardian and i have some problem with setting timer as counter, and i already wrote a code :
TR0=1;
TMOD=0x06;
ET0=1;
EA=1;

but it still doesnt work, can anyone tell me how to set it?


sincerly,
hardian

Parents
  • Hardian,

    Your code is working, you can see it working with your debuger.

    Take a look at the gererated assembly code and you'll notice that the first instruction is running the Timer0 as a 13-Bit Timer because of the TMOD reset value 0x00h, so to avoid future problems always configure whatever you need before turn the things on.

    Here's your gererated code:

    0000 D28C           SETB    TR0 
    0002 758906            MOV     TMOD,#06H
    0005 D2A9              SETB    ET0
    0007 D2AF              SETB    EA
    

    If you want a T0 operating as a 8-Bit Auto-Reload Counter this pice of code may help you:

    ...
    TMOD= 0x06;
    TH0 = recharge_value;
    TL0 = inicial_value;
    ET0 = 1;
    EA  = 1;
    TR0 = 1;
    

    Maybe you'll need a interrupt function to do something with your counter...

    void counter0 ( void ) interrupt 1 using 2 {
    ...
    }
    

    A pulse in the P3.4 pin will tick your counter.

    Alex

Reply
  • Hardian,

    Your code is working, you can see it working with your debuger.

    Take a look at the gererated assembly code and you'll notice that the first instruction is running the Timer0 as a 13-Bit Timer because of the TMOD reset value 0x00h, so to avoid future problems always configure whatever you need before turn the things on.

    Here's your gererated code:

    0000 D28C           SETB    TR0 
    0002 758906            MOV     TMOD,#06H
    0005 D2A9              SETB    ET0
    0007 D2AF              SETB    EA
    

    If you want a T0 operating as a 8-Bit Auto-Reload Counter this pice of code may help you:

    ...
    TMOD= 0x06;
    TH0 = recharge_value;
    TL0 = inicial_value;
    ET0 = 1;
    EA  = 1;
    TR0 = 1;
    

    Maybe you'll need a interrupt function to do something with your counter...

    void counter0 ( void ) interrupt 1 using 2 {
    ...
    }
    

    A pulse in the P3.4 pin will tick your counter.

    Alex

Children
No data