PIC16F684 Blink LED with PICkit 3

This post is for beginners who would like to run a simple LED blinking example using PIC16F684 with PICkit 3. Most of the beginners may start learning by using Demo board that is usually shipped with the PICkit 3 but this post aims to connect PICkit 3 directly to the PIC16F684. This post assumes that MPLAB IDE and XC8 compiler have been successfully installed.

PICkit 3 is a programmer and debugger for PIC microcontollers. PICkit 3 has 6 pins but pin 6 is not used in our case. Here is the connection between PICkit 3 and PIC16F684

PICkit 3 pins on the left and PIC16F684 pins on the right
pin 1 <-----> pin 4 
pin 2 <-----> pin 1 (Vdd)
pin 3 <-----> pin 14 (Vss)
pin 4 <-----> pin 13
pin 5 <-----> pin 12

In this example, an LED is connected to PIC16F684 on pin number 9 (RC1) and the other side is to ground. Note that pin 14 (Vss) acts as ground. Also, internal clock of the PIC16F684 is used so configuration bit of FOSC must be set to INTOSCIO. Here is the code for blinking an LED on port RC1.

#include <stdio.h>
#include <stdlib.h>
#include <xc.h>

#pragma config FOSC = INTOSCIO
#pragma config WDTE = OFF 
#pragma config PWRTE = OFF 
#pragma config MCLRE = OFF 
#pragma config CP = OFF 
#pragma config CPD = OFF 
#pragma config BOREN = OFF 
#pragma config IESO = OFF 
#pragma config FCMEN = OFF 

#define _XTAL_FREQ 8000000
int main(int argc, char** argv) {

 TRISCbits.TRISC1 = 0;
 ANSEL = 0;


 RC1 = 0;
 RC1 = 1;
 return (EXIT_SUCCESS);