Home / Tutorials / PIC Tutorial / PIC16F877A – More Microcontroller Features

PIC16F877A – More Microcontroller Features

We have managed to blink a LED, use interrupts and timers with the PIC16F84A. Sadly, that’s almost all we can do with that microcontroller as it lacks features that most microcontrollers or an Arduino has. From here on, we will now be using the PIC16F877A.

The PIC16F877A is a 40-pin (DIP) microcontroller which Microchip describes as powerful based on having a 200 nanosecond instruction speed. It’s old and Microchip itself is not recommending it for new designs but its features and price make it still a popular microcontroller.

[the_ad id=”3059″]

PIC16F877A Specs

Here’s a few of its specifications:

  • Bus width – 8 bits
  • Pin Count – 40 (PDIP, SOIC) / 44 (QFN, PLCC, TQFP)
  • Program Memory – 14.3 kilobytes
  • CPU Speed – 5 million instructions per second
  • RAM Size – 368 bytes
  • EEPROM Size – 256 bytes

Obviously, the PIC16F877A trumps the PIC16F84A based on the numbers above. But what separates this microcontroller are these features:

  • 10-bit, up to 8-channel Analog-to-Digital
    Converter (A/D)
  • Synchronous Serial Port (SSP) with SPI™
    (Master mode) and I2C™ (Master/Slave)
  • Universal Synchronous Asynchronous Receiver
    Transmitter (USART/SCI) with 9-bit address

We will discuss each of these features as we continue with this tutorial.

LED Blink Code in Assembly

For now, we will create a simple assembly language program using the PIC16F877A.
The code is very similar to the one using PIC16F84A:

[the_ad id=”3059″]

The code above simply toggles the state of pin RB0. So when an LED is attached to this pin, it will blink. You can simulate this code in Proteus using the schematic diagram below:

PIC16F877A Blink a LED circuit

Of course, the advantage of using this microcontroller is you can attach a lot more LEDs!

Switch a LED in Assembly

For input using a switch, you can freely use any pin except those that have AN labels. These analog pins that includes all PORTA and PORTE pins are meant for analog to digital conversion and needs a bit of additional code to make them digital.

To turn these analog pins to digital, we must write 0x07 or 0x06 to the ADCON1 register. Details about this is found on my analog to digital conversion tutorial.

Here’s a code that uses a switch to RA0 to turn on/off a LED:

Here’s the schematic diagram for the code above:

PIC16F877A LED Switch circuit

[the_ad id=”3059″]

Those are the basic assembly language programs we can do with the PIC16F877A. Up next, we will look at the features that separate this microcontroller from the PIC16F84A, starting with serial communication.

Check Also

Curiosity HPC Buttons

Using Buttons and LEDs on the Curiosity HPC

Last time, I showed how to get started with Microchip’s Curiosity HPC board. I will …