Pages

Thursday, June 29, 2017

LED Blink with PIC16F887 microcontroller


This simple post shows how to blink an LED using PIC16F887 microcontroller and CCS C compiler.
The LED here is connected to pin RA0 as shown in the circuit schematic below and easily that LED can be connected to other output pin or other LEDs can be added to the circuit which require code modification.
I this example there is no need for oscillator and MCLR circuits because the internal oscillator of the microcontroller is used at 8MHz and MCLR pin function is disabled (MCLR pin is configured as I/O pin).
Circuit diagram:
LED Blink with PIC16F887 microcontroller and CCS C compiler
C Code:
/* LED blink with PIC16F887 microcontroller
   Internal oscillator used @ 8MHz
   http://ccspicc.blogspot.com/
   electronnote@gmail.com
*/

#include <16F887.h>
#fuses NOMCLR NOBROWNOUT NOLVP INTRC_IO
#use delay(clock = 8MHz)

void main(){
  setup_oscillator(OSC_8MHZ);                         // Set the internal oscillator to 8MHz
    while(TRUE){                                      // Endless loop
      output_high(PIN_A0);                            // LED ON
      delay_ms(500);                                  // Wait 1/2 second
      output_low(PIN_A0);                             // LED OFF
      delay_ms(500);                                  // Wait 1/2 second
    }
}

CCS C and Proteus simulation files can be downloaded from the following link:
Download