Projects   /   Communication & Interfacing   /   PIC16F877A

PIC16F877 UART code and Proteus simulation

This post answers the question, "How to use interrupt based UART in PIC16F877" ?

Published

At a glance

CategoryCommunication & Interfacing
PIC modelPIC16F877A
IncludesCircuit diagram · Proteus · Download files
Reading time~3 min
Jump to a section
  1. Code
  2. Downloads
  3. Quick Solutions to Questions related to PIC16F877 UART interrupt example:
  4. Related projects

Summary of PIC16F877 UART code and Proteus simulation

This article explains using interrupt-driven UART on the PIC16F877, with C code written for MPLAB using the HI-TECH C compiler and testable in Proteus. It describes TX on RC6, RX on RC7, default 9600 bps, startup transmission of Hello World, and echoing received characters via an interrupt service routine. Downloads include source code and a Proteus simulation.

Parts used in the PIC16F877 UART interrupt example:

  • PIC16F877 microcontroller
  • Proteus simulation software (for circuit and virtual terminal)
  • MPLAB IDE (used to compile and build the project)
  • HI-TECH C compiler (v9.83 as used in example)
  • Virtual terminal in Proteus (for serial I/O)
  • Connections: RC6 (TX) and RC7 (RX) pins

PIC16F877 UART
Also, using PIC16 simulator (Proteus) you can verify this UART code and change it according to your needs. This code is written in C language using MPLAB with HI-TECH C compiler. You can download this code from the 'Downloads' section at the bottom of this page.

This PIC16F877 microcontroller tutorial provides the interrupt based UART functions which you can easily understand and use. After reading this page you can easily use PIC16F877 serial UART interface.

It is assumed that you know how to blink an LED with PIC16F877 microcontroller. If you don't then please read this page first, before proceeding with this article.

The following diagram (made in Proteus) shows the PIC microcontroller circuit diagram.

PIC16F877 UART schematic

In the above figure, UART baudrate is currently set to 9600 bps, but you can change it to your desired value. RC6 pin is the TX pin and RC7 pin is the RX pin the UART. Whenever a new character is received on the UART, then PIC16F877 goes into interrupt service routine and received character is echoed back.

When code starts to execute then PIC16F877 sends 'Hello World' to virtual terminal. After that PIC16F877 echos back whatever character is sent to it. 'Hi' was typed in the virtual terminal after the start up of the simulation in Proteus and PIC16F877 echoed it back.

Code

The code used to set different properties of UART is shown below. (From UART.h file)

Downloads

UART code for PIC16F877 was compiled in MPLAB v8.85 with HI-TECH C v9.83 compiler and simulation was made in Proteus v7.10. To download code and Proteus simulation click here.

 

For more detail: PIC16F877 UART code and Proteus simulation

  • How is UART baud rate set in this example?
    The baud rate is set to 9600 bps by default, and can be changed as desired in the code.
  • Can the UART code be tested without hardware?
    Yes, the code is tested and verifiable using Proteus simulation and its virtual terminal.
  • What pins are used for TX and RX on PIC16F877?
    RC6 is the TX pin and RC7 is the RX pin for UART.
  • Does the PIC16F877 use interrupts for UART reception in this project?
    Yes, UART reception triggers an interrupt service routine which handles received characters.
  • What does the PIC send when the code starts?
    On startup the PIC sends Hello World to the virtual terminal.
  • How does the PIC respond to characters typed in the terminal?
    The PIC echoes back any character received via UART from the virtual terminal.
  • Which tools and versions were used to compile and simulate the project?
    The code was compiled in MPLAB v8.85 with HI-TECH C v9.83 and simulated in Proteus v7.10.
Beginner Tutorials · PIC16F877A

PIC16F877 Driving LCD in 4-Bit Mode using PIC16F877 with Proteus Simulation

Introduction This microcontroller project shows how a PIC16F877 can drive an LCD display using 4-bit mode inside a Proteus simulation.The project demonstrates...

Programmers & ICSP · PIC16F877A

EPE PIC/LCD Demo using PIC16F877 with Proteus Simulation

IntroductionThe EPE PIC/LCD Demo is a classic microcontroller project that demonstrates how a PIC16F877 can fully control a PG12864F graphical LCD.Designed as...

Motors & Robotics · PIC16F877A

Efficient Sun-Following Robot: A Solar Tracker with Microcontroller Control

Abstract The impending global challenge of dwindling non-renewable fuel resources underscores the urgency of transitioning towards renewable energy alternatives like solar power....

Communication & Interfacing · PIC18F4520

CAN FD Node based on a PIC18 Microcontroller

The introduction sets the stage for an embedded systems project that involves developing a Embedded C CAN FD project using the MCP2517FD...

Communication & Interfacing

LAN9662 Gigabit Switch: Optimized for Industrial Ethernet

Introduction It should come as little surprise therefore that one element of what is now more commonly referred to in some circles...

Communication & Interfacing

PIC Microcontroller: Fundamentals & Applications for Students

Introduction Microcontrollers are the key components in the embedded systems market. A variety of embedded systems was formed and developed after the...

Ibrar Ayyub

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough...