# How to ensure serial transmission and reception of required data without any garbage values in the 8051?

I'm trying to continuously transmit the character 'L' from the microcontroller 8051 to the PC at a baud rate of 9600. The frequency of the 8051 is 16 MHz, and I accordingly loaded the BRL register with "0XFC" for baud rate generation. However, I can see a stream of garbage values on the hyper terminal; I even tried changing the auto reload values from 0xFB to 0xFF to no avail. Is there any way for me to generate the exact Baud Rate in the microcontroller or a way for me to fix this problem?

Edit: Also, even if I transmit just a single alphabet from the PC to the controller, and the code is written in a way for the controller to echo everything sent from the PC sometimes the character the controller sends in response is different from what I'd sent.

My code is as follows:

#include "reg_c51.h"

char uart_data='L';

void main (void)
{
SCON = 0x40;
BDRCON &=0xE0;
BDRCON |=0x08;
BRL=0xFC;
IEN0 = 0xF0;
BDRCON |=0x10;

while(1)
{
SBUF = uart_data;
while(TI==0);
TI=0;
}
}

• Which 8051 (manufacturer, part number) are you using, exactly? – Dave Tweed Jul 24 '14 at 13:37
• I'm using the AT89C5131A-L. – user3491636 Jul 25 '14 at 4:09
• Might not be the issue here, but never underestimate the ability of plain old wiring to mess things up. In one lab I work in we have numerous 'serial cables' that are made from CAT5 patches clipped into DB9-to-RJ45 ends. I can get glitchy comms on these even at 9600, but replace with a 'real' serial cable and the same setup can run glitch free at 115200. Just sayin' – JustJeff Jul 25 '14 at 4:40