Interfacing PIC16F84A with push button
This topic shows how to turn on and off 2 LEDs connected to PIC16F84A microcontroller, from Microchip, using 2 push buttons. The goal of this example is to see how to read the PIC16F84A inputs with CCS C compiler.
LED blink using push button circuit:
Example circuit schematic diagram is shown below.
The circuit is simple there 2 LEDs and 2 buttons where each button controls one LED, for example if the first button which is connected to RB0 is pressed then the first LED which is connected to RA0 will be turned ON, and if the same button pressed again the same LED will be turned OFF, and the same thing for the second button and the second LED.
LED blink using push button CCS PIC C code:
Example C code is the one below. It was tested with CCS C compiler version 5.051.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | // PIC16F84A LED blink example // http://simple-circuit.com/ #include <16F84A.h>; #fuses HS,NOWDT,PUT,NOPROTECT #use delay(crystal=8000000) void main(){ while(TRUE){ // Endless loop if(input(PIN_B0) == 0){ // If RB0 button is pressed output_toggle(PIN_A0); // Toggle RA0 LED status delay_ms(500); // Wait 500 ms } if(input(PIN_B1) == 0){ // If RB1 button is pressed output_toggle(PIN_A1); // Toggle RA1 LED status delay_ms(500); // Wait 500 ms } } } |
Discover more from Simple Circuit
Subscribe to get the latest posts sent to your email.