From: MP on
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 <REG52.H> /* special function register
declarations */
#include <stdio.h> /* 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

From: martin griffith on
On 14 Sep 2006 09:12:42 -0700, in comp.arch.embedded "MP"
<peykanu(a)gmail.com> wrote:

>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 <REG52.H> /* special function register
>declarations */
>#include <stdio.h> /* 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
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
From: Neil on
MP wrote:
> 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 <REG52.H> /* special function register
> declarations */
> #include <stdio.h> /* 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
>
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

> P2 ^= 0x01; /*test pin*/
P2^1 ^= P2^1; MAY generate smaller code
From: Viktor on

MP wrote:
> 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
>

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