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

configure Timer 2 on P89C51RD2

I'll very appreciate if you can help me with the following issue: Configured Timer 2 on P89C51RD2 .

I'm getting around me and become confused from it ...

So, I configure Timer 2 / 16-bit timer (the timer overflows (goes from 0xFFFF to 0x0000)

An interrupt service routine (ISR) have to be invoked whan timer 2 have expired.

(In which register I have to set the interrupt number void timer2_ISR (void) interrupt xx ??)

Can you send me a 'C' example code which demonstrated this issue.

Thanks

Moshe

Parents
  • Previous Post continued..

    I just realise that there is a mistake on how I have shown the upper byte is calculated to be loaded into TH2 and RCAP2H, they should of been '/' rather than '%' so whe now have :-

    	TH2 = TIMER2_CLK_TICK_RELOAD / 0x0100;
    	RCAP2H = TIMER2_CLK_TICK_RELOAD / 0x0100;/* upper byte of 16 bit reload value. */
    

    I had originally created two macros called HIGH and LOW to give me the upper and lower byte of an unsigned int and in removing them, cut and pasted the wrong lines.

    Mark.

Reply
  • Previous Post continued..

    I just realise that there is a mistake on how I have shown the upper byte is calculated to be loaded into TH2 and RCAP2H, they should of been '/' rather than '%' so whe now have :-

    	TH2 = TIMER2_CLK_TICK_RELOAD / 0x0100;
    	RCAP2H = TIMER2_CLK_TICK_RELOAD / 0x0100;/* upper byte of 16 bit reload value. */
    

    I had originally created two macros called HIGH and LOW to give me the upper and lower byte of an unsigned int and in removing them, cut and pasted the wrong lines.

    Mark.

Children
  • Hi

    Thanks. It's works but u have to add EA=1

    Moshe


    /* init timer2 to required delay and start it*/
    static void timer2_init(void)
    {
    T2CON = 0x00; /* timer 2 16 bit auto-reload. */
    TL2 = TIMER2_CLK_TICK_RELOAD & 0xFF;
    TH2 = TIMER2_CLK_TICK_RELOAD % 0x0100;
    RCAP2L = TIMER2_CLK_TICK_RELOAD & 0xFF; /* lower byte of 16 bit reload value. */
    RCAP2H = TIMER2_CLK_TICK_RELOAD % 0x0100;/* upper byte of 16 bit reload value. */
    TR2 = 1; /* start timer 2. */
    ET2 = 1;

    EA = 1;
    }