You are on page 1of 10

8051 HOW-TO GUIDE

Interfacing UART with


8051

Contents at a Glance
8051 Primer Board ...........................................................3
UART ...............................................................................3
RS-232 Level Converter ....................................................4
Interfacing UART .............................................................5
Interfacing UART with 8051 .............................................6
Pin Assignment with 8051 ................................................6
Circuit Diagram to Interface UART with 8051 ...................7
Source Code ....................................................................7
C Program to display a text in PC from 8051 .....................8

Join the Technical Community Today!


http://www.pantechsolutions.net

8051 Primer Board


The 8051 Primer board is specifically designed to help
students to master the required skills in the area of
embedded systems. The kit is designed in such way that all
the possible features of the microcontroller will be easily
used by the students. The kit supports in system
programming (ISP) which is done through serial port.
NXPs 8051 (AT89V51RD2), 8051 Primer Kit is proposed
to smooth the progress of developing and debugging of
various

designs

encompassing

of

speed

8-bit

Microcontrollers.
UART
UART (Universal Asynchronous Receiver Transmitter)
are one of the basic interfaces which provide a cost
effective simple and reliable communication between one
controller to another controller or between a controller and
PC.
Join the Technical Community Today!
http://www.pantechsolutions.net

RS-232 Level Converter


Usually all the digital ICs work on TTL or CMOS voltage
levels which cannot be used to communicate over RS-232
protocol. So a voltage or level converter is needed which
can convert TTL to RS232 and RS232 to TTL voltage levels.
The most commonly used RS-232 level converter is
MAX232.
This IC includes charge pump which can generate RS232
voltage levels (-10V and +10V) from 5V power supply. It also
includes two receiver and two transmitters and is capable
of full-duplex UART/USART communication.
RS-232 communication enables point-to-point data
transfer. It is commonly used in data acquisition
applications, for the transfer of data between the
microcontroller and a PC.
The voltage levels of a microcontroller and PC are
not directly compatible with those of RS-232, a level
transition buffer such as MAX232 be used.
Join the Technical Community Today!
http://www.pantechsolutions.net

Interfacing UART
Fig. 1 shows how to interface the UART to
microcontroller. To communicate over UART or USART, we
just need three basic signals which are namely, RXD
(receive), TXD (transmit), GND (common ground). So to
interface UART with 8051, we just need the basic signals.

Fig. 1 Interfacing UART to Microcontroller

Join the Technical Community Today!


http://www.pantechsolutions.net

Interfacing UART with 8051


We now want to display a text in PC from 8051 Primer
Board by using UART module. In 8051 Primer Board
contains two serial interfaces that are UART0 & UART1.
Here we are using UART0. The Transmitter pins send the
data into PC and the receiver pin receives the data from PC.
The PC and microcontroller speed are denoted by using
baud rate. When the baud rates of both PC and
Microcontroller are same, then only the data transmit and
receive correctly otherwise not.

8051
Processor Lines

ISP PGM

RXD0

P3.0

TXD0

P3.1

RXD1

P1.2

TXD1

P1.3

UART0(P1)

UART DB-9
Connector

UART1
(P2)

Pin Assignment with 8051


Serial Port Section

8051

MAX232

Note : RXD1 and TXD1 lines are only available in Maxim-Dallas Microcontrollers
DS89C4xx series.

Join the Technical Community Today!


http://www.pantechsolutions.net

Circuit Diagram to Interface UART with 8051

Source Code
The Interfacing UART with 8051 program is very simple
and straight forward, which display a text in PC from 8051
Primer Board through UART0. Some delay is occurring when
a single data is sent to PC. C programs are written in Keil
software. The baud rate of microcontroller is 9600.
Join the Technical Community Today!
http://www.pantechsolutions.net

C Program to display a text in PC from 8051


***************************************************************************************
Title : Program to display a text in PC from 8051 through UART0
***************************************************************************************
#include <REG51.H>
#include <stdio.h>

/* special function register declarations */


/* prototype declarations for I/O functions */

void serial_init(void);
//------------------------------------------------//Setup the serial port for 9600 baud at 11.0592MHz.
//------------------------------------------------void serial_init(void)
{
SCON = 0x50;
/* SCON: mode 1, 8-bit UART, enable rcvr
*/
TMOD |= 0x20;
/* TMOD: timer 1, mode 2, 8-bit reload
*/
TH1 = 0xFD;
/* TH1: reload value for 9600 baud @ 11.0592MHz*/
TR1 = 1;
/* TR1: timer 1 run
*/
TI = 1;
/* TI: set TI to send first char of UART
*/
}
//-------------------------//Main Program Starts Here
//-------------------------void main(void)
{
serial_init();
printf (" PS - PrimerC51 UART Demo\n\n\r");
while (1)
{
printf ("Hello World!! \n\r"); /* Print "Hello World" */
}
}

Join the Technical Community Today!


http://www.pantechsolutions.net

Did you enjoy the read?


Pantech solutions creates information packed technical
documents like this one every month. And our website is a rich
and trusted resource used by a vibrant online community of
more than 1, 00,000 members from organization of all shapes
and sizes.

Join the Technical Community Today!


http://www.pantechsolutions.net

What do we sell?
Our products range from Various Microcontroller
development boards, DSP Boards, FPGA/CPLD boards,
Communication Kits, Power electronics, Basic electronics,
Robotics, Sensors, Electronic components and much more . Our
goal is to make finding the parts and information you need
easier and affordable so you can create awesome projects and
training from Basic to Cutting edge technology.

Join the Technical Community Today!


http://www.pantechsolutions.net

You might also like