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 Data Transfer to PC(Personal Computer) using PIC16f877 Microcontroller USART

By EG Projects April 9, 2019

Here is a simple project on How to transmit serial data to pc using built in usart(universal Syncronous-Asyncronous receiver transmitter)of PIC 16f877 microcontroller. The data Transmitted by PIC microcontroller is received by computer through its (Serial)DB-9 Port and is displayed on Hyperterminal window. Since microcontrollers works on TTL  wave form and standard PC(Personal Computers) works on RS-232 wave form so we have to convert our transmitted data from microcontroller into RS-232 wave form. The best way is to use MAX-232 ic. It converts TTL wave form in to RS-232 and RS-232 to TTL.To learn about its Pin out and working below is a good tutorial.

  • MAX-232 PIN CONFIGURATION AND WORKING.
Picture

TTL to RS-232C Level wave form

The TX or transmission line of Usart is at pin 25 of PIC 16f877. Connect this transmission line to pin 10(T2IN) of MAX-232. Connect Pin# 7(T2OUT) of MAX-232 to pin# 2 of DB-9 port of your PC. Connect four Capacitors to MAX-232. The Capacitors should range between 1uf to 10uf. I recommend 10uf because i used it in mine project and the circuit is working fine. Apply 5v to vcc pin of microcontroller and MAx-232. Ground Gnd pins of microcontroller and MAX-232. Inserst 20MHz crystal between pins 13 and 14 of PIC 16f877. Crystal should be in parallel to two 33Pf capacitors.The circuit diagram of the project is below.
Serial Data Transmission to PC(Personal Computer- Hyperterminal Program) using PIC16f877A USART

Serial Data Transmission to PC(Personal Computer- Hyperterminal Program) using PIC16f877A USART

Once you know about the registers associated with Usart transmission you can easily understand the code below.
First of all to enable the serial port or TX(Transmission) RX(Reception) line. The SPEN(Serial port enable bit) bit of register RCSTA(Receive status and control register) should be high.
SPEN Bit of RCTA Register of PICC16f877 Microcontroller

SPEN Bit of RCTA Register of PICC16f877 Microcontroller- SPEN enables Serial Port of PIC16f877 microcontroller

I loaded 0x80 in RCSTA register. Which is hexadecimal value. Its equivalent binary form is 10000000. This value is loaded in RCSTA register. Which only sets Serial Port Enabled.
RCSTA Register Bits

RCSTA Register Bits

All the other bits are reception bits. Since i am concerned only with Transmission so i only need to enable serial port.

Set the Transmission setting in TXSTA(Transmit Status and Control Register) register.

TXSTA register of PIC16f877 Microcontroller

TXSTA register of PIC16f877 Microcontroller

I loaded 0x06 in TXSTA. 0x06 is hexadecimal value its equivalent binary is 00000110. 
TXSTA Register Bits

TXSTA Register Bits

Set the Baud Rate in SPBRG Register. Their are two formulas for Baud Rates Calculation. Depending on the BRGH bit of TXSTA Register. Formula for BRGH=1 is Different for BRGH=0. Since this bit BRGH selects High or Low Baud Rates thats why Baud Rate depends on this bit. 
PIC 16f877 Baud Rate Calculation Formula

PIC 16f877 Baud Rate Calculation Formula

I loaded 0x81 hexadecimal in it. Its equivalent binary is 10000001 and decimal value is 129. Since mine BRGH bit is high so by using the formula for BRGH=1 the Baud Rate value for 9600 is 129. Loading the value 129 in SPBRG and keeping BRGH=1 sets our Baud Rate to 9600. 

The Data Which you want to transmit should be placed in TXREG(Transmit register) register. This register gives data to TSR Register. TSR then transmits the data serialy.  TSR Register is not available for user you can not access it. 

I write code in MP-Lab using High Tech C Compiler. The code is written in c language. First import the library htc.h. Always import this library in each project if you are writting code using high tech c compiler. Then Crystal frequency in defined. which is 20 MHz. In the main function first TRISC6=0 statement makes the Port-C bit 6 as output
pin. This pin is actually Multiplexed pin. It can be used as Digital I/O as well as TX line. So first make it as output pin. Then a string Array is defined. This Array contains my website name “www.microcontroller-project.com”. This String is displayed on Hyperterminal screen when the program runs. Then the registers are initialized i explaned their initialization above. 
While 1 loop is continuously printing my website name on hyperterminal. While(TRMT=0) statement checks if the TSR Register is empty. If TSR is full The control remains on while(TRMT=0) statement and when TSR becomes empty. TRMT becomes 1 and control jumps to next statement.

Before running the program. Just set the hperterminal.Goto 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 “www.microcontroller-project.com” on Hyperterminal screen.

Download the project files with code and simulation. Code is written in c language and simulation is made in proteaus. Please Give us your feed back on the project.

serial transmission using Pic16f877 USART


Filed Under: Microcontroller Projects, PIC Microcontroller

 

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

  • Collector Current Low side Has a large drop respect High Side during Miller during Double Pulse Test
  • Diode recovery test Irrm timing.
  • The Analog Gods Hate Me
  • How best to synchronise the UCC38C45?
  • floating node warning in LTSpice

RSS Electro-Tech-Online.com Discussions

  • The Analog Gods Hate Me
  • Display TFT ST7789 (OshonSoft Basic).
  • Fixing board, Easy question HEX SCHMITT
  • Can I make two inputs from one??
  • Home Smoke detectors are all Beeping Batteries are not dead.???

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 to monitor temperature and humidity on a TFT display with graphics
  • Tria modules integrate edge AI processing with multi-core processors
  • pSemi introduces RF switch with 52 dBm PMAX,PEAK and 90-dBm IIP3 linearity
  • XP Power launches 1.3 kW power supply with 58.9 W/cmÂł density
  • How to enable Wi-Fi provisioning in ESP32-based IoT products

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