Serial Communication between 8051 Microcontroller and PC The

Microprocessor Systems (EE 271)
Lab Manual #12
4th Semester (Session 2011)
Name: _____________________________________________Reg. #:2011 -EE-_________ _Date: ______________________________
Serial Communication between 8051 Microcontroller and PC
After this lab you will be able to:
Interface PC Serial port with 8051 microcontroller.
PC Serial Ports
The RS-232 serial communication standard is probably the most popular serial communication scheme in the
world. The PC supports up to four RS-232 compatible devices using the COM1, COM2, COM3, and COM4
devices.
The UART
UART stands for Universal Asynchronous Receiver / Transmitter. It’s the little box of tricks found on your serial
card which plays the little games with your modem or other connected devices. The 8250 series, which includes
the 16450, 16550, 16650, & 16750 UARTS, are the most commonly found type in your PC.
Types of UARTS
8250
First UART in this series. It contains no scratch register. The 8250A was an improved version of
the 8250 which operates faster on the bus side.
8250A
This UART is faster than the 8250 on the bus side. Looks exactly the same to software than
16450.
8250B
Very similar to that of the 8250 UART. 16450 Used in AT's (Improved bus speed over 8250's).
Operates comfortably at 38.4KBPS. Still quite common today.
16550
This was the first generation of buffered UART. It has a 16 byte buffer, however it doesn't work
and is replaced with the 16550A.
16550A
It’s the most common UART used for high speed communications e.g. 14.4K & 28.8K Modems.
The Serial Communications Chip (SCC)
The 8250 and compatible chips (like the 16450 and 16550 devices) provide nine I/O registers. Certain upwards
compatible devices (e.g., 16450 and 16550) provide a tenth register as well. These registers consume eight I/O
port addresses in the PC’s address space. The hardware and locations of the addresses for these devices are the
following:
Port
COM1
COM2
Address (in hex)
3F8
2F8
1/5
Microprocessor Systems (EE 271)
Lab Manual #12
4th Semester (Session 2011)
2/5
Microprocessor Systems (EE 271)
Lab Manual #12
4th Semester (Session 2011)
3/5
Microprocessor Systems (EE 271)
Lab Manual #12
4th Semester (Session 2011)
The SCON Register:
The following C program for 8051 transfers the letter “A” serially at 4800 baud continuously using
8-bit data and 1 stop bit.
#include <reg51.h>
void main(void)
{
TMOD=0x20; //use Timer 1, mode 2
TH1=0xFA; //4800 baud rate
SCON=0x50;
TR1=1;
4/5
Microprocessor Systems (EE 271)
Lab Manual #12
4th Semester (Session 2011)
while (1)
{
SBUF=‘A’; //place value in buffer
while (TI==0);
TI=0;
}
}
This program in C receives bytes of data serially and puts them in P1 using baud rate of 4800, 8-bit
data, and 1 stop bit.
#include <reg51.h>
void main(void)
{
unsigned char mybyte;
TMOD=0x20; //use Timer 1, mode 2
TH1=0xFA; //4800 baud rate
SCON=0x50;
TR1=1; //start timer
while (1)
{
while (RI==0); //wait to receive
mybyte=SBUF; //save value
P1=mybyte; //write value to port
RI=0;
}
}
5/5