GENERAL

TURNING LEDs ON AND OFF WITH PUSH BUTTONS

TURNING LEDs ON AND OFF WITH PUSH BUTTONS

Today i will be talking about push button and two of it to be precise. We will be using one of the push buttons to ON a LED(Light Emitting Diode) while the other push button is to OFF it. Very simple and interesting isn’t it? Now lets get started with the code first because it is short and simple if you have any experience in C programming language. This is the code for the project;

void main() {

TRISB=0x00;

portb=0x00;

TRISC=0x00;

PORTC=0x00;

TRISD=0xff;

PORTD=0x00;

while(1) {

if(rb0_bit==0) {

portc=0x00;

}

else if(rd7_bit==0) {

portc=0xff;

}

}

}

COMPONENTS

(I) 10k, 220Ohm Resistor

(II) 3 LEDs

(III) PIC16F877A Micro-controller

(IV) Crystal Oscillator

(V) 22pF Capacitor

(VI) 2 Push Button

The proteus schematic should look like the diagram below but you can change the position of each component to your best satisfaction but just make sure the connections are rightly connected.

  • You need to declare RB0 and RD7 as input since your push buttons are connected to these pins. You have declared these pins as output that is why you having logic contention (yellow color) at these pins. Please adjust!

Leave a Reply

Your email address will not be published. Required fields are marked *