Thursday, February 25, 2016

PIC16F84A blink LED using push button


This topic shows how to turn on and off 2 LEDs connected to PIC16F84A using 2 push buttons.
LED blink using push button circuit:
pic16f84 led bink button ccs pic c
The circuit is simple there 2 LEDs and 2 buttons each button toggles one LED for example when the first push button which is connected to RB0 is pressed, the first LED which is connected to RA0 turns ON, and when the same button pressed again the same LED turns OFF, and the same thing for the second button and the second LED.
LED blink using push button CCS PIC C code:
// PIC16F84A LED blink example
// http://ccspicc.blogspot.com/
// electronnote@gmail.com

#include <16F84A.h>
#fuses HS,NOWDT,PUT,NOPROTECT
#use delay(crystal=8000000)

void main()
{
   while(TRUE)    // Endless loop
   {
     if(input(PIN_B0) == 0)
     {
       output_toggle(PIN_A0);
       delay_ms(500);
     }
     if(input(PIN_B1) == 0)
     {
       output_toggle(PIN_A1);
       delay_ms(500);
     }
   }
}