Posted on

Interfacing LED with PIC Microcontroller

Interfacing LED with PIC Microcontroller is the very first tutorial in a series of tutorials on Design Embedded System with PIC Microcontroller.

In case you are new to PIC Microcontroller and MPLAB X IDE I strongly suggest to visit the tutorial – Getting started with MPLAB X IDE.

For interfacing LED with PIC Microcontroller we will require the following components which can be purchased in OpzLab web store. Links to the individual components are also provided.

  1. PICKIT3 Debugger / Programmer
  2. PIC16F15325
  3. Mini Breadboard
  4. Power Supply
  5. 470 ohms Resistor
  6. LED
  7. Jumper Wires

Follow the below tutorial to blink LED from MPLAB X IDE


Create New Project

Select PIC microcontroller device.

Select PICKIT 3 debugger.

Select XC8 compiler.

Provide project name and finish.

Open MPLAB Code Configurator.

Save Code Configurator settings.

Uncheck Low-voltage Programming Enable under Project Resource -> System Module -> Easy Setup -> Programming.

Set MCLRE to port defined function under Project Resource – > System Module – > Registers -> Register Config 2.

Set Pin 8 to GPIO Output.

Disable Analog I/O on pin 8 from Project Resource -> Pin Module.

Click Generate button to generate MCC_Project files and main.c source file.

Click on MCC Button to close the MCC editor.

Open main.c from Project Window.

Update main.c to match the below code.

#include "mcc_generated_files/mcc.h"

#define LED RC2

void main(void)

    while (1)
        LED = 0;
        LED = 1;

Circuit – Interfacing LED with PIC16F15325

Connect PICKIT3 to the PIC16F15325 as shown below

Hit the Download button to program and run the device from MPLAB X IDE.

Select Do not show this message again and press OK button.

The pic microcontroller will be programmed after few downloads, the program will start running and blink the LED.