How to Blink an Led Using PIC Microcontroller ?
by AXR AMAR in Circuits > Electronics
17635 Views, 12 Favorites, 0 Comments
How to Blink an Led Using PIC Microcontroller ?
![temp_-1327850795.jpg](/proxy/?url=https://content.instructables.com/FVK/IJ85/IOSPEPOJ/FVKIJ85IOSPEPOJ.jpg&filename=temp_-1327850795.jpg)
This tutorial is for PIC microcontroller beginners.
*steps to install MP Lab
*steps to install xc8 compiler
*program to Blink
*Building project and Burning it to the pic Mc
*steps to install MP Lab
*steps to install xc8 compiler
*program to Blink
*Building project and Burning it to the pic Mc
Components Required
![temp_-12488654.jpg](/proxy/?url=https://content.instructables.com/F76/IZI2/IOSPEPR9/F76IZI2IOSPEPR9.jpg&filename=temp_-12488654.jpg)
![temp_1477322198.jpg](/proxy/?url=https://content.instructables.com/FY1/7TD7/IPWWS3IP/FY17TD7IPWWS3IP.jpg&filename=temp_1477322198.jpg)
1) PIC16F886-1
2) 8Mhz crystal -1
3) 22pF capacitor -2
4) jumpers
5) Breadboard
6) 10K Resistor -2
7) Pic kit2 or pic kit3
2) 8Mhz crystal -1
3) 22pF capacitor -2
4) jumpers
5) Breadboard
6) 10K Resistor -2
7) Pic kit2 or pic kit3
Circuit !
![temp_-1182914462.jpg](/proxy/?url=https://content.instructables.com/FDC/UR66/IOSPEPTR/FDCUR66IOSPEPTR.jpg&filename=temp_-1182914462.jpg)
Connect the circuit on your breadboard as shown in diagram
Note: here MCLR is pin1
Note: here MCLR is pin1
Code
#define _XTAL_FREQ 8000000
#include
// BEGIN CONFIG
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = ON // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF // 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)
//END CONFIG
int main()
{
TRISB0 = 0; //RB0 as Output PIN
while(1)
{
RB0 = 1;
__delay_ms(1000);
RB0 = 0;
__delay_ms(1000);
}
return 0;
}
#include
// BEGIN CONFIG
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = ON // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF // 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)
//END CONFIG
int main()
{
TRISB0 = 0; //RB0 as Output PIN
while(1)
{
RB0 = 1;
__delay_ms(1000);
RB0 = 0;
__delay_ms(1000);
}
return 0;
}
Install MPLab X Ide
![temp_271860390.jpg](/proxy/?url=https://content.instructables.com/FES/XZ9R/IOSPEPWD/FESXZ9RIOSPEPWD.jpg&filename=temp_271860390.jpg)
MPLab IDE is used to program PIC microcontrollers,Here IDE stands for Integrated development environment.
Download it from here ::
en.freedownloadmanager.org/Windows-PC/MPLAB-X-IDE-FREE.html
Download it from here ::
en.freedownloadmanager.org/Windows-PC/MPLAB-X-IDE-FREE.html
Install Xc8 Compiler !
Xc8 compiler is used to compile the codes which are written in the MPLAB X IDE .
Download XC8 compiler from here ::
www.microchip.com/mplab/compilers
Download XC8 compiler from here ::
www.microchip.com/mplab/compilers
Steps to Write Programs on MPLab IDE
![temp_-652123604.jpg](/proxy/?url=https://content.instructables.com/FAA/3L2H/IOSPEQ65/FAA3L2HIOSPEQ65.jpg&filename=temp_-652123604.jpg)
![temp_2140212422.jpg](/proxy/?url=https://content.instructables.com/F87/2O26/IOSPEQCJ/F872O26IOSPEQCJ.jpg&filename=temp_2140212422.jpg)
![temp_2040415685.jpg](/proxy/?url=https://content.instructables.com/FOW/IVR2/IOSPEQGT/FOWIVR2IOSPEQGT.jpg&filename=temp_2040415685.jpg)
![temp_-601305088.jpg](/proxy/?url=https://content.instructables.com/F4B/C0TF/IOSPEQYF/F4BC0TFIOSPEQYF.jpg&filename=temp_-601305088.jpg)
![temp_-59965989.jpg](/proxy/?url=https://content.instructables.com/FS5/9IN8/IOSPEQZP/FS59IN8IOSPEQZP.jpg&filename=temp_-59965989.jpg)
![temp_-1708254452.jpg](/proxy/?url=https://content.instructables.com/FLD/PFBW/IOSPER2R/FLDPFBWIOSPER2R.jpg&filename=temp_-1708254452.jpg)
![temp_-754007542.jpg](/proxy/?url=https://content.instructables.com/FUE/BWDM/IOSPER4K/FUEBWDMIOSPER4K.jpg&filename=temp_-754007542.jpg)
![temp_1486020405.jpg](/proxy/?url=https://content.instructables.com/F62/CPSJ/IOSPER6Q/F62CPSJIOSPER6Q.jpg&filename=temp_1486020405.jpg)
![temp_534639446.jpg](/proxy/?url=https://content.instructables.com/FD7/JE0J/IOSPER77/FD7JE0JIOSPER77.jpg&filename=temp_534639446.jpg)
![temp_-1335509966.jpg](/proxy/?url=https://content.instructables.com/F71/WFFC/IOSPER7M/F71WFFCIOSPER7M.jpg&filename=temp_-1335509966.jpg)
![temp_757227682.jpg](/proxy/?url=https://content.instructables.com/FV1/FPH5/IOSPER7U/FV1FPH5IOSPER7U.jpg&filename=temp_757227682.jpg)
Step 1 : open MPlabx click >file >new project
Step 2 : select standalone Project
Step 3 : select PIC16f886 (or your IC)
Step4: select your programmer in my case its pickit2 ,click next
Step5: select XC8 compiler
Step6: project name
Step7 : See the 7th Picture ..there select source files ,Right click >new>c main file !!
Step8 : Give name !
Step 9 : paste your program here !
Step10: Build main project
Step11: Run main project (or press F6)
Pickit will upload to your IC successfully !!
if any doubt please leave a message!!
Thank you !! :)
Step 2 : select standalone Project
Step 3 : select PIC16f886 (or your IC)
Step4: select your programmer in my case its pickit2 ,click next
Step5: select XC8 compiler
Step6: project name
Step7 : See the 7th Picture ..there select source files ,Right click >new>c main file !!
Step8 : Give name !
Step 9 : paste your program here !
Step10: Build main project
Step11: Run main project (or press F6)
Pickit will upload to your IC successfully !!
if any doubt please leave a message!!
Thank you !! :)