Pages

Wednesday, March 9, 2016

PIC16F877A read inputs using CCS C

PIC16F877A button read
This is an example shows how to read data from input pins on PIC16F877A microcontroller. LEDs are going to be controlled using pushbuttons as shown in the circuit schematic below.
PIC16F877A read inputs using CCS C circuit:
pic16f877a button input read ccs pic c
As shown in the circuit schematic there are two pushbuttons and two LEDs. Each button controls one LED, the first button which is connected to RD0 toggles ON and OFF the LED connected to RB0 and the second button toggles ON and OFF the other LED.
PIC16F877A read inputs CCS C code:

// PIC16F877A buttons read
// http://ccspicc.blogspot.com/
// electronnote@gmail.com

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

void main()
{
   output_b(0);
   while(TRUE)
   {
    if(input(PIN_D0) == 0)
    {
      output_toggle(PIN_B0);
      delay_ms(500);
    }
    if(input(PIN_D1) == 0)
    {
      output_toggle(PIN_B1);
      delay_ms(500);
    }
   }
}