PIC16F877A LED Interfacing

by Ramatronics Laboratory in Circuits > Microcontrollers

1316 Views, 4 Favorites, 0 Comments

PIC16F877A LED Interfacing

IMG_20220908_155242.jpg

In this instructables I am going to show you how you can interface an LED with PIC16F877A microcontroller. We shall create a simple C program to turn on the LED for one second and turn off for another one second and this will repeat over and over again. Let's get started.

Supplies

H7aea8d8c969744a0ab0eee7f92e9d982f.jpg
22PF.jpg
20MHz.jpg
PIC16F877A-microcontroller.jpg
pickit3.jpg

Hardware List:


https://quartzcomponents.com/


  1. PIC16F877A Microcontroller

https://quartzcomponents.com/products/pic16f877a?_pos=4&_sid=383448472&_ss=r


  1. 20MHz Quartz Crystal


  1. Red LED (5mm)

https://quartzcomponents.com/products/red-5mm-led?_pos=1&_sid=b42d8afce&_ss=r


  1. PICKIT3 Programmer

https://quartzcomponents.com/products/pickit3-usb-pic-programmer-and-debugger?_pos=2&_sid=f50beb7d7&_ss=r


  1. Bread Board

https://quartzcomponents.com/products/colored-breadboard-mb-102-830-point?_pos=3&_sid=b69fcf56b&_ss=r


  1. 10K Resistor (1)

https://quartzcomponents.com/products/10k-ohm-1-4-watt-resistor-with-1-tolerance-pack-of-10?_pos=4&_sid=93826e6b4&_ss=r


  1. 330 Ohm Resistor (1)

https://quartzcomponents.com/products/330-ohm-1-4-watt-resistor-with-1-tolerance-pack-of-10?_pos=2&_sid=eb33e23c4&_ss=r


  1. Jumper Wires (male to male)

https://quartzcomponents.com/products/65pcs-breadboard-jumper-cable?_pos=2&_sid=26e3bdce1&_ss=r


  1. 22PF Capacitor (2)

https://quartzcomponents.com/products/22pf-ceramic-capacitor-pack-of-5?_pos=1&_sid=633ebb3e4&_ss=r



https://www.amazon.in/


  1. PIC16F877A Microcontroller

https://www.amazon.in/Generic-ST-CO0440-PIC16F877A-Microcontroller/dp/B08P5B7W43/ref=sr_1_1?crid=2ZY1QHLLE9GVE&keywords=pic16f877a+microcontroller&qid=1662880821&sprefix=PIC16F%2Caps%2C413&sr=8-1

  1. 20MHz Quartz Crystal

https://www.amazon.in/20-Mhz-Crystal-Pack-4/dp/B08NV9G9XJ/ref=sr_1_1?crid=3JIC0S793E8AH&keywords=20mhz+crystal&qid=1662880904&sprefix=20MHz%2Caps%2C441&sr=8-1


  1. PICKIT3 Programmer

https://www.amazon.in/PICkit3-PIC-KIT3-Debugger-Programmer/dp/B08V23J5B7/ref=sr_1_1?crid=710GYNYCZFAC&keywords=pic+kit+3&qid=1662880997&sprefix=pic+kit+%2Caps%2C387&sr=8-1


  1. Bread Board

https://www.amazon.in/Robotbanao-Solderless-MB102-Breadboard-Points/dp/B08GG6ZC41/ref=sr_1_1_sspa?crid=2NFO7BWMP6OYC&keywords=breadboard&qid=1662881066&sprefix=Brea%2Caps%2C470&sr=8-1-spons&psc=1&spLa=ZW5jcnlwdGVkUXVhbGlmaWVyPUExUU0xQ05WVk8wRk5SJmVuY3J5cHRlZElkPUEwMTU5ODc2MU40VzlPT05VTFM1SSZlbmNyeXB0ZWRBZElkPUEwODkyNTQ2MjVUWDlWV1UwOTBEUiZ3aWRnZXROYW1lPXNwX2F0ZiZhY3Rpb249Y2xpY2tSZWRpcmVjdCZkb05vdExvZ0NsaWNrPXRydWU=


  1. 10K Resistor (1)

https://www.amazon.in/INSIGNIA-LABS-100-RESISTORS-TOLERANCE/dp/B0991XR919/ref=sr_1_1?crid=2T72SKS5JI4Y9&keywords=10k+resistor&qid=1662881127&sprefix=10K%2Caps%2C535&sr=8-1

  1. 330 Ohm Resistor (1)

https://www.amazon.in/330-ohm-Watt-Resistor-Pieces/dp/B08WX5B8W5/ref=sr_1_1?crid=2PAUK6RUW52YT&keywords=330+ohm+resistor&qid=1662881195&sprefix=330+resistor%2Caps%2C487&sr=8-1

  1. Jumper Wires (male to male)

https://www.amazon.in/Scriptronics%C2%AE-Breadboard-Jumper-Dupont-Wire/dp/B09M7KFQ6S/ref=sr_1_31?crid=227V7UYJILZE9&keywords=jumper+wires&qid=1662881256&sprefix=jumper+wires%2Caps%2C539&sr=8-31


  1. 22PF Capacitor (2)

https://www.amazon.in/100pcs-22pF-Ceramic-Capacitor-50V/dp/B08FB32WPD/ref=sr_1_3?crid=1F2B6G7R59UDR&keywords=22pf+capacitor&qid=1662881328&sprefix=22P%2Caps%2C515&sr=8-3


  1. Red LED (5mm)

https://www.amazon.in/AVS-COMPONENTS-5mm-Color-Defused/dp/B08L3N6MD7/ref=sr_1_5?crid=3C6NDPI2XR9BO&keywords=red+led+5mm&qid=1662881399&sprefix=RED+LED+5%2Caps%2C467&sr=8-5



Making the Circuit on a Bread Board

IMG_20220908_155921.jpg
IMG_20220908_151403.jpg
IMG_20220908_155638_1.jpg
IMG_20220908_155819_2.jpg
IMG_20220908_160008.jpg
IMG_20220908_155417.jpg
IMG_20220908_155514.jpg
IMG_20220908_155242.jpg
df99595eb3eebd3f7b0cf38e5205976c.jpg
Screenshot (20).png

Procedure:

First we create a prototyping circuit on a breadboard. We fix the PIC16F877A microcontroller chip on the bread board and then we also insert 22PF ceramic capacitor and 20MHz Quartz crystal on the 13 and 14 pins of the PIC16F877A.

We connect the Vdd and Vss pin of PICKIT3 to Pin 11 and 12 of PIC16F877A respectively. After this we connect the PGD, PGC and MCLR pins of the PICKIT3 to 40, 39 and 1 pins of PIC16F877A respectively. we also connect a 10K Ohm pull up resistor on the first pin(MCLR) of the 16F877A so that microcontroller will not reset(clear itself).

We connect a 5mm RED LED along with a 330 Ohm current limiting resistor on the pin 10 (RB4) of the PIC16F877A.

Connect all the GND Pins of the circuit to the Vss pin of PICKIT3.

Downloading the Software and Compilier

Screenshot (7).png
1447-mplab-xc-compiler-6834.jpg
Screenshot (9).png

To program the PIC16F877A Microcontroller, we need two software and a compiler. That are-

MPLAB X IDE:

you can download the latest version of MPLAB X IDE from the link given below:

https://www.microchip.com/en-us/tools-resources/develop/mplab-x-ide


MPLAB XC8 Compiler:

you can download the latest version of MPLAB XC8 Compiler from the link given below:

https://www.microchip.com/en-us/tools-resources/develop/mplab-xc-compilers


PICKIT3 Programmer:

You can download the PICKIT3 Programming Software from the given link:

https://pickit.software.informer.com/3.1/

Creating a C Program in MPLAB X IDE

Screenshot (13).png
Screenshot (14).png
Screenshot (15).png
Screenshot (16).png
Screenshot (17).png
Screenshot (18).png

Open the MPLAB X IDE software on your computer and then go to file tab and then choose new project. a new box will open, there choose standalone project and click on next. Now choose the following as mentioned below:

Family: - All Families

Device: Select the microcontroller chip that you want to program (PIC16F877A in my case)

Tool: select the Programming tool such as PICKIT3


after select the above three options click on next option

In select header we choose none and click on next.

now choose the XC8 Compiler and click on next.

name your project such as LEDblink in my case.

Now go to source files and click on new and then choose main.c option.

again create a file name such as LEDblink in my case and click on finish.

Now copy the following C program in your LEDblink.c and click on clean and build main project.



C Program:



/*
 * File:  newmain.c
 * Author: Ram Patel
 *
 * Created on 7 September, 2022, 8:16 PM
 */

// CONFIG
#pragma config FOSC = HS    // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF    // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = ON   // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = ON    // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF    // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF    // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF    // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF     // Flash Program Memory Code Protection bit (Code protection off)

#include <xc.h>

#define _XTAL_FREQ 20000000
#define LED RD2

void main(void) {
   
  TRISD2 = 0;
   
  while (1)
  {
    LED = 0;
    __delay_ms(1000);
    LED = 1;
    __delay_ms(1000);
  }
  return;
}



if we did not get any compilation error then connect the PICKIT3 to the computer and open the PICKIT3 application on the computer.

Now click on Device family and click on midrange option and then choose Standard.

now the PICKIT3 will automatically identify your microcontroller chip.

Now adjust the voltage level to 5.0 V

Now click on write option to upload the hex file on PIC16F877A.

Tick the on option of the Vdd PICKIT3 . So your microcontroller will use the 5V of USB of your laptop.



Uploading the LED Blink Hex File on PIC16F877A