I've been trying simple program (listed below), and it doesn't work.
LEDs on P0 are lighting continuously and no frequency is present on
these pins. The same routine written in assembler works fine.
I'm new user of DSCC, can somebody help me?
Z, ProjectX@...
#include <reg51.h>
#define TIMER0_COUNT 0x0F841 /* 10000h - ((11,059,200 Hz / (12 *
FREQ)) - 17) */
unsigned char timer0_tick;
timer0_isr (void) interrupt 1 using 1
{
P1 |= 0x80;
/*------------------------------------------------
Adjust the timer 0 counter so that we get another
interrupt in 10ms.
------------------------------------------------*/
TR0 = 0; /* stop timer 0 */
TL0 = TL0 + (TIMER0_COUNT & 0x00FF);
TH0 = TH0 + (TIMER0_COUNT >> 8);
TR0 = 1; /* start timer 0 */
/*------------------------------------------------
Increment the timer tick. This interrupt should
occur approximately every 1ms. So, the resulotion
of the timer will be 1kHz not including interrupt
latency.
------------------------------------------------*/
timer0_tick++;
P1 &= ~0x80;
}
/*------------------------------------------------------------------------------
void timer0_initialize (void);
This function enables TIMER 0. TIMER 0 will generate a synchronous
interrupt
once every 1kHz.
------------------------------------------------------------------------------*/
void timer0_initialize (void)
{
EA = 0; /* disable interrupts */
timer0_tick = 0;
TR0 = 0; /* stop timer 0 */
TMOD &= ~0x0F; /* clear timer 0 mode bits */
TMOD |= 0x01; /* put timer 0 into 16-bit no prescale */
TL0 = (TIMER0_COUNT & 0x00FF);
TH0 = (TIMER0_COUNT >> 8);
PT0 = 0; /* set low priority for timer 0 */
ET0 = 1; /* enable timer 0 interrupt */
TR0 = 1; /* start timer 0 */
EA = 1; /* enable interrupts */
}
void main (void)
{
P0 = 0;
P3 = 0;
timer0_initialize ();
while (1)
{
P0 = timer0_tick;
}
}
|