This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

C51: Problem with serial communication

Hello!
I am trying to establish serial communication between the PC and the AT89C5131 at a baudrate of 9600. The microcontroller has a clock frequency of 16 MHz. According to the baud rate calculator by Keil, 0xFC is the value to be loaded into the BRL register for generating baud rate closest to 9600. However this is not exact, so mostly garbage values are being transmitted. I have attached my code below; please help me figure out if there is any other way to ensure the transmission and reception does not involve unwanted data. The 8051 echoes whatever is sent from the computer - the code is a slightly modified version of something I found on the Atmel website.

#include "reg_c51.h"

char uart_data;


void main (void)
{
   SCON = 0x50;
   BDRCON &=0xEC;
   BDRCON |=0x0C;
   BRL=0xFC;
        ES = 1;
        EA = 1;
   BDRCON |=0x10;

   while(1);
}


void serial_IT(void) interrupt 4
{

        if (RI == 1)
        {
          RI = 0;
          uart_data = SBUF;
          SBUF = uart_data;
        }
        else TI = 0;
}