Interfacing LED with PIC Microcontroller
Now that we have studied various things about the PIC microcontroller, it is time to apply those concepts in some projects. So this article would explain about interfacing LED with PIC Microcontroller, Instead of using a physical microcontroller, we will be simulating it quickly, once you have completed a simulation, you are welcome to apply it on a physical board. Before the simulation, we are required to write code for the functionality for which we will be using MPLAB, and for simulation, we will use Proteus.
Aim:
Using PIC16F877A to blink an LED
Components:
PIC16F877A, LED (any color)
Procedure:
1. Open MPLAB and make a new project.
2. Make a new “main.c” file.
3. Write down the code for blinking LED.
4. Click on build.
5. Now go to Proteus and set up the components as seen in the video.
6. Double click on the microcontroller and set processor clock frequency as 20 Mhz and open the. hex file of the program you just wrote in the program file field.
7. On the bottom left corner, click on the run option.
Code
#include <xc.h>
#define _XTAL_FREQ 20000000
// CONFIG
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable bit (BOR disabled)
#pragma config LVP = ON // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3/PGM pin has PGM function; low-voltage programming enabled)
#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)
void main(void)
{
TRISB7 = 0;
while(1)
{
PORTBbits.RB7 = 1;
__delay_ms(1000);
PORTBbits.RB7 = 0;
__delay_ms(1000);
}
return;
}