8052

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

Reply to
Will B.
Loading thread data ...

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.

Reply to
Philip Miles

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

Reply to
Gary Kato

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

Reply to
Chris Quayle

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

Reply to
Philip Miles

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.