Header Ads

Control of LEDs / Turn ON OFF LEDs using PIC16C62B Microcontroller

Pin Diagram:
In this tutorial, I'll show you how to control two LEDs by 2 seperate push buttons. When I press the the 'PB1' button, it turns on the Green LED and by pressing the 'PB2' button, it turns on the Red LED. Both LEDs are connected in sourcing mode.
Components Used:
The following cicuit components are used.
1. PIC16C62 Microcontroller
2. One green LED and one red LED
3. 3 pushbuttons
4. Two 286 ohm resistors
5. Two 270 ohms resistors
6. Two 22pF capacitors
7. One crystal oscillator (8Mhz)
8. One 10k ohm resistor
Proteus Circuit Diagram
Code
// Code by Engr. Shahid Khan
// Turn ON OFF LEDs by using pushbutton
sbit LEDGREEN at PORTB.B0; //green LED is connected to PORTB pin B0
sbit LEDRED at PORTB.B1; //red LED is connected to PORTB pin B01
sbit PB1 at PORTA.B0; //First Push button is connected to PORTA pin A0
sbit PB2 at PORTA.B1; //2nd Push button is connected to PORTA pin A1
void main() {
TRISB.RB0 = 0; //output
TRISB.RB1 = 0; //output
TRISA.RA0 = 1; //input
TRISC.RA1 = 1; //input
while(1)
{
if (PB1 == 1) //pressed
{
LEDGREEN = 1; //on
}
else
{
LEDGREEN=0; //off
}
if(PB2==1)
{
LEDRED = 1;
}
else
{
LEDRED=0;
}
}
}
Simulation Video

No comments

Powered by Blogger.