8051 problem with serial port and timer

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

Reply to
MP
Loading thread data ...

I'm not that clever with 8052etc, but I thought that T1 is set by the internal hardware. from an atmel datasheet:

"Transmit Interrupt flag Clear to acknowledge interrupt. Set by hardware at the end of the 8th bit time in mode 0 or at the beginning of the stop bit in the other modes. "

Maybe that is a problem?

martin

Reply to
martin griffith

You enabled the serial interrupt but have no function for it. Do not enable it if you are not using it. (TI will set either way).

You may want to add a "using 1" to the interrupt void timer0 (void) interrupt 1 using 1

Note the 8052 has bit instructions

Reply to
Neil

Try not using printf. Send the same character over and over by writing to SBUF directly.

Reply to
Viktor

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.