Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

Serial communication data transmission to pc using USART of 8051(89c51,89c52) Microcontroller

By EG Projects May 4, 2019

This is a simple project on how to transfer serial data to PC(personal computer) using 8051(89c51) microcontroller usart(universal synchronous asynchronous receiver transmitter). Learning about 8051 microcontroller serial communication is the main task of the tutorial. Serial data can be transferred to PC(personal computer) using serial port of the computer. Serial port of computers are used to connect printers, scanners, fax machines and old shaped/pined round shaped mouse and keypad connectors. 

There are two serial ports in all the systems(computer, laptop) DB-9 and DB-25. You can transfer data serially to PC using these ports, DB-9 has 9 pins and DB-25 has 25 pins, both ports comes in male and female package. Below is pin out of both the male and female connectors 

db9 , db25

db9 , db25 serial ports of personal computers

How serial data can be transferred using 8051 microcontroller?

In order to transfer serial data between two systems both must have a single UART(universal synchronous asynchronous receiver transmitter) port. Serial communication is accomplished using this UART protocol and serial port. In UART serial communication we have to set few things on both the receiver and transmitter side. First both must be working on the same BAUD RATE. Baud rate is data transfer rate. Such as 9600 bps OR 9600 bits per second. Secondly we have to define the code bits in transfer data. Like 8- bit data transfer, stop bits and parity etc. Once on the both the side we defined the same settings its time to talk with each other. 

Why use of Level converter – Max232

8051 series microcontrollers works on TTL(transistor transistor logic) and our PC(personal computers) works on rs-232 level wave form. 8051 microcontroller outputs data serially as TTL wave form, and our PC works on rs-232 level so we have to convert TTL level wave form in to equivalent rs-232 level wave form before sending it to PC. To carry out this task we use MAX-232. It is an ic whic converts TTL wave form in its equivalent rs-232 level and rs232 signal in to its equivalent TTL signal. I recommend you to first take a small tutorial on MAX-232 ic its pin-out and working etc.

  • Max-232 pin out and working

8051 microcontroller serial data transfer – Project code

Coming to the code first i included necessary header file reg51.h, this header file must be included in every project that uses keil as software to compile the code and generating hex file for 89c51 microcontroller.
 
Now about the internal registers of 8051 which are used in the code. TMOD (Timer mode) this register is used to initialize the mode of the timer. The only mode which can be used to transfer data serially to pc is 8-bit auto reload. To initialize the timer in this mode use command 0x20 which loads the timer 1 in 8-bit auto reload mode. I am using timer 1 in my program so i used the command 0x20, but if you want to use timer 0 you can use it and the command for it is different its 0x02 take a look at the diagram below.
TMOD register

TMOD register of 89c51 microcontroller – Timer settings register

Then the timer 1 high byte TH1 is loaded with 0xFD to generate a baud rate of 9600 bps(bits per second). Now what does baud rate means. Its actually the protocol between the two machines which are going to transfer data between them serially. Baud rate is measured in bps bits per second, both of the systems should be at the same baud rates for successful data transfer. There are many baud rates now how to calculate the value for each baud rate below is a simple formula for it.  

8051 microcontrollers completes one machine cycle after every 12 clock cycles. So our Instruction execution frequency is crystal frequency/12. Now if our crystal is of 11.0592 MHz then our effective frequency is  11.0592/12 MHz => 921.6 KHz. 8051 UART further divides this frequency (921.6 KHz) by 32 to generate its baud rate. Therefore effective frequency available to generate baud rates is 921.6 KHz/32 = 28800 Hz.

For different baud rates the values of TH1 will be different for Baud Rate 9600 TH1 will be=0xFD because 28800/9600 = 3. 3 is 11 in binary take its two’s complement -3 and load the value in TH1 for 9600 baud rate. Calculate different baud rates for different crystals using the same above formula. Different baud rates with 11.0592 MHz crystal are below. SCON(serial control) register is used to control the flow of data. This is an 8-bit register and also it is bit addressable  You can access its single bit. Here is a diagram of SCON with individual bits and modes which you can specify.

SCON serial control register

SCON serial control register – 8051 microcontroller

I am using mode 1, to select Scon in mode 1 make SM0=0 and SM1=1, you can also use other modes mentioned in the above diagram. SM2 enables the multiprocessing capability of the 8051, here we make SM2=0 because we are not dealing with 8th bit. REN is Receive Enable, when REN=1 it allows the 8051 to receive data . If you want 8051 to both transfer and receive data, REN must be set to ‘1’. when REN=0 it means receiver is disabled. TB8 and RB8 is used for serial modes 2 and 3, so here we make them 0. TI and RI are important bits.

TI is Transmit Interrupt flag, When 8051 microcontroller finishes the transfer of 8-bit character, it raises the TI flag to indicate that it is ready to transfer another byte.

RI is Receive Interrupt flag, When 8051 receive data via RxD, it get rid of the start and stop bits and places the byte in the SBUF. Then it raises the RI flag to indicate that a byte has been received and should be picked up before it is lost.
SBUF(serial buffer) is an 8-bit register it is not bit addressable  when we have to transfer character we place it in SBUF register and poles the TI flag. When data is received which is sended by some other source it is also placed in SBUF register, and we pick it from here.
The circuit diagram is simple and is shown below.

serial data transmission to pc with 8051

serial data transmission to pc with 8051

After you make connections go to Start->Programs->Accessories->Communications->HyperTerminal open new connection name it what ever you want then click OK.  Now a window appears select COM1 from connect using drop down menu click OK  Now set COM1 properties bits per second as you specified in your program in mine case 9600, Data bits=8, Parity=none, Stop bits=1, Flow control=none then click OK. Now switch on the power of your circuit, you will see what you specified in your code. 
I am sending my web site name www.microcontroller-project.com to PC on UART protocol. The final output received on Hyperterminal of PC is given below.
Hyper terminal data recieved

Hyper terminal data recieved

Download the project files and code compiled in keil uvision 4 with hex file , and if you have any queries let me know that.Please Write your comments below.

Serial data Transmission code/files


Filed Under: 8051 Microcontroller, Microcontroller Projects

 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: 5G Technology
This Tech Toolbox covers the basics of 5G technology plus a story about how engineers designed and built a prototype DSL router mostly from old cellphone parts. Download this first 5G/wired/wireless communications Tech Toolbox to learn more!

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Industrial Relay Board Design for Motorcycle Use
  • Finding past posts on edaboard?
  • I think i have devised a new type of "super_transformer" for the Electricity grid?
  • What is the purpose of this relay?
  • mosfet driver problem in regeneration mode

RSS Electro-Tech-Online.com Discussions

  • Pic18f25q10 osccon1 settings swordfish basic
  • Sump pit water alarm - Kicad 9
  • Anyone jumped from Easyeda std to Easyeda pro?
  • turbo jet fan - feedback appreciated.
  • More fun with ws2812 this time XC8 and CLC

Featured – LoRa/LoRaWan Series

  • What is the LoRaWAN network and how does it work?
  • Understanding LoRa architecture: nodes, gateways, and servers
  • Revolutionizing RF: LoRa applications and advantages
  • How to build a LoRa gateway using Raspberry Pi
  • How LoRa enables long-range communication
  • How communication works between two LoRa end-node devices

Recent Articles

  • How IoT network topologies work
  • The top five AI startups to watch in 2025
  • STMicroelectronics unveils SoC based on secure MCU
  • Nexperia’s 48 V ESD diodes support higher data rates with ultra-low capacitance design
  • Taoglas releases Patriot antenna with 18 integrated elements covering 600 to 6000 MHz

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe