Monday, March 7, 2016

PIC16F877A blinking an LED with CCS C compiler


PIC16F877A is a 40-pin (PDIP type) microcontroller that has 5 ports: A, B, C, D and E. From the 40 pins we can use 33 pins as an I/O pins. This microcontroller has 3 timers which are:
Timer0: 8-bit timer,
Timer1: 16-bit timer,
Timer2: 8-bit timer.
This microcontroller has also 10-bit, up to 8-channel Analog-to-Digital Converter (A/D) and many other peripheral features.
Blink an LED using PIC16F877A and CCS C compiler:
This is a small example shows how to make an LED blinking. Circuit schematic is shown below:
pic16f877a led blink ccs pic c
The LED is connected to RB0 pin and the microcontroller clock is 8MHz.
Blink an LED using PIC16F877A CCS PIC C code:
// PIC16F877A LED blink example
// http://ccspicc.blogspot.com/
// electronnote@gmail.com

#include <16F877A.h>
#use delay(crystal=8000000)

void main()
{
   while(TRUE)
   {
    output_toggle(PIN_B0);    // Toggle output pin RB0
    delay_ms(500);
   }
}

PIC16F877A make all outputs blink:
This is a second example which makes all the33 output pins on PIC16F877A blink. Circuit schematic is below:
pic16f877a all outputs blink ccs pic s
PIC16F877A make all outputs blink CCS PIC C code:

// PIC16F877A all outputs blink
// http://ccspicc.blogspot.com/
// electronnote@gmail.com

#include <16F877A.h>
#use delay(crystal=8000000)

void main()
{
   while(TRUE)
   {
    output_a(0);       // All port A pins low
    output_b(0);       // All port b pins low
    output_c(0);       // All port c pins low
    output_d(0);       // All port d pins low
    output_e(0);       // All port e pins low
    delay_ms(500);
    output_a(0x3F);    // All port A pins high
    output_b(0xFF);    // All port b pins high
    output_c(0xFF);    // All port c pins high
    output_d(0xFF);    // All port d pins high
    output_e(0x07);    // All port e pins high
    delay_ms(500);
   }
}