Dados seriais recebidos do PC e exibidos em LCD 16×2 usando a porta UART do microcontrolador 8051(89c51,89c52)

Serial data received from PC and displayed on 16×2 LCD using UART port of 8051 microcontroller(89c51,89c52)

In this post I will explain how to receive serial data from your PC and display it on a 16×2 LCD using the UART port of the 89c51 microcontroller. The hardware components of the project include max232 (TTL to RS232 level converter/shifter), 8051 microcontroller (89c51,89c52) and 16×2 lcd. On the software side, I am using Hyper terminal. Hyper terminal is a program through which it is possible to transmit and receive data serially using the serial ports of a personal computer (PC). The standard PC has two serial ports, db-9 and db-25. We normally connect our printers, fax machines, mice and joysticks to these serial ports.
The block diagram of data transfer between UART port of 89c51 microcontroller and personal computer is shown below.

8051 microcontroller serial data transfer between PC and 89C51 UART port

8051 microcontroller serial data transfer between PC and 89C51 UART port

Max232 Level Converter

8051 microcontroller works on TTL logic and personal computers work on rs232 logic. For communication between the two modules, the data must be on the same carrier logic. Hence a level shifter like max232 is used. Which transforms data from one logic to another before sending it to the receiver. To learn more about the max232 transceiver, its pinout, operation and power requirements, follow the tutorial below.

Max232 pinout and operation

8051(89c51,89c52) UART Microcontroller

89c51 Uart microcontroller is used to receive data from PC. You can also use any other 8051 series microcontroller like 89c52 microcontroller. But first make sure it has built-in UART (universal asynchronous receiver transmitter) for serial communication.

Port 1 of our microcontroller is used as the output port. It is connected to the data pins of the 16×2 LCD.

  • Pin #5 of port 3 is connected to the rs (register select) pin of the 16×2 LCD.
  • Pin #6 of port 3 is connected to the en (enable) pin of the 16×2 LCD.
  • Pin #7 of port 3 is connected to rw (read and write) pin of 16×2 LCD.

If you don't know how to interface LCD with 8051 microcontroller (89c51,89c52), here are some good tutorials, just go through them.

  • LCD 16×2 WORKING.
  • DIFFERENCE BETWEEN COMMANDS AND SENDING DATA TO LCD.
  • DISPLAYING YOUR NAME ON LCD using 8051 MICROCONTROLLER.

serial data received from PC hyperterminal and displayed on LCD using 8051 microcontroller (89c51,89c52)

serial data received from PC hyperterminal and displayed on LCD using 8051 microcontroller (89c51,89c52)

Project code

In the main function, I first called the lcdinit function to initialize the 16×2 lcd. All commands used in the function are discussed in depth in the above tutorials. Then the timer mode is set. TMOD=0x02 means Timer1, Mode2 (8-bit auto reload) is selected. TH1=0xFD is actually a one byte high timer, providing hexadecimal value 0xFD to TH1 means setting the communication baud rate between 8051 microcontroller and PC to 9600 bps (bits per second). SCON=0x50 is actually defining our serial data bit format Total = 8 Data bit with 1 start bit and 1 stop bit. TR1=1 means running timer one. This entire phenomenon with the full meaning of the statements (SCON,TMOD,TH) is discussed in the two tutorials below. How to calculate baud rate values ​​is also discussed.

  • HOW TO SEND SERIAL DATA TO PC (Hyperterminal).
  • 8051(89c51) TIMER RECORDS.

while(RI==0) is checking the RI (receive interrupt) flag continuously. This flag automatically becomes one when 8051(89c51,89c52) receives any data on its RXD( P3^0 ) pin. When RI becomes 1, it means we have one byte of data in our SBUF register (serial buffer). Then in the next instruction I took the Byte from the SBUF register and saved it in character variable data. Then I left the RI flag low again to receive the next byte. The Byte that I saved in the data variable is now sent to the display function to be displayed on the 16×2 LCD.

Download the project files and the code (Hex, c++) compiled using the keil uvision 4 compiler. If you feel any problem in the code or do not understand any instruction in the code, just write your questions below. The code is hardware tested and is free from any bugs. << />iv>
Serial data received from PC

Related Content

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.