Hi everybody, I am using a AT89C51ED2 in my design and I have a problem with its timer and UART simultanous function. Timer and serial port work fine seperatly but when they are gathered in one code, timer ISR stops functioning. here is sample of the code written in keil.
#include /* special function register declarations */ #include /* prototype declarations for I/O functions */
void main (void) { SCON = 0x50; /*UART mode 2*/ BRL= 243; /* 12Mhz X1; 4800*/ BDRCON = 0x1D; /* Set SPD = 0, BRG run on uart*/ PCON = 0X80; /*Set SMOD1=0 : double baud rate*/ EA = 1; /* Enable global interrupt */ ES = 1; /* Enable serial interrupt*/ TI=1; /* set TI to send first char of UART */
TH0= 0xD8; /*Timer 0 intialization*/ TL0= 0xEF; IEN0 = 0x92; TMOD = 0x01; TR0= 0x00; /*Starting the timer*/ TR0= 0x01;
while (1) { printf ("Hello World\n"); /* Print "Hello World" */ } }
void timer0 (void) interrupt 1 {
TF0 = 0x00; /*Timer 0 reintialization*/ TR0= 0x00; TH0= 0xD8; TL0= 0xEF; TR0= 0x01;
P2 ^= 0x01; /*test pin*/
return; }
Actullay when I set the TI bit to 1 in order to start the serial port output, although the timer continoues to run in the debugger, the timer ISR is not executed anymore and the test pin stops oscillating and if the bit TI is not set to 1, UART won't function.
help me PLZ!
MP