8052

Aug 15, 2003 4 Replies

sounds like you might not be setting up the timer registers correctly. check out

formatting link
for the best info (and code) on the 8052

Hello,



I'm experimenting Keil C and an 8052 microcontroller and am having trouble getting the timer 2 to work properly as a timer. I have configured T2 as a standard timer and attached an ISR to catch overflows. I have verified the ISR is working. After starting the timer, neither TH2 or TL2 change. I may have a harware problem but am not sure. Could someone send example code?



Thanks,



Philip.


I'd guess you aren't loading the proper registers to load the timers with their initial values. Read the datasheet.

Hi,

You could try this bit of code. Worked on a philips 80c522 for me using Keil C51:

/* Init Timer 0, 10mS System Tick */ /* ------------------------------ */ void vTickInit (void) { ET0 = 0; /* Mask interrupt */ TR0 = 0; /* Stop timer 0 */

TMOD &= 0xf0; /* Clear timer 0 bits */ TMOD |= 0x01; /* Set timer 0 for mode 1 */ TL0 = (U8) RELOAD_10MS; TH0 = (U8) (RELOAD_10MS >> 8);

TR0 = 1; /* Start timer 0 */ ET0 = 1; /* Enable interrupt for timer 0 */ }

/* 10ms System Clock Interrupt Handler */ /* ----------------------------------- */ void vTickIsr(void) interrupt 1 using 1 {

TR0 = 0; /* Stop timer */ TL0 = (U8) RELOAD_10MS; TH0 = (U8) (RELOAD_10MS >> 8); TR0 = 1; /* Re-enable timer */

/* > */

}

Chris

My thanks for your post Chris. I have not had any trouble with either timer

0 or timer 1 and some of my test code looks very similar to yours. I have experimented with all of the modes described > >

trouble

a

the

may

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required