Toll-Free Customer Support 24/7

PIC LED and Keypad code


/*
* Project name:
PIC Development Board LED and Keypad code
* Copyright
(c) Researchdesignlab.com
* Test configuration:
MCU: PIC16F877A
Dev.Board: PIC
Oscillator: 20.0 MHz
Software: mikroC PRO for PIC v 4.6
Developer: DD
*/ 

sbit sw1 at RD4_bit; //defining Pin D4 as sw1
sbit sw2 at RD5_bit; //defining Pin D5 as sw2
sbit sw3 at RD6_bit; //defining Pin D6 as sw3
sbit sw4 at RD7_bit; //defining Pin D7 as sw4

void main()
{
TRISB=0x00; //defining PORTB as output port
TRISD=0xFF; //defining PORTD as input port
while(1)
{
if(sw1 ==1 && sw2==0 && sw3==0 && sw4==0)
{
PORTB=85; //binary equivalent value:01010101
Delay_ms(200);
PORTB=170; //binary equivalent value:10101010
Delay_ms(200);
}
else if(sw1 ==0 && sw2==1 && sw3==0 && sw4==0)
{
PORTB=240; //binary equivalent value:11110000
Delay_ms(200);
PORTB=15; //binary equivalent value:00001111
Delay_ms(200);
}
else if(sw1 ==0 && sw2==0 && sw3==1 && sw4==0)
{
PORTB=51; //binary equivalent value:00110011
Delay_ms(200);
PORTB=204; //binary equivalent value:11001100
Delay_ms(200);
}
else if(sw1 ==0 && sw2==0 && sw3==0 && sw4==1)
{
PORTB=1; //binary equivalent value:00000001
Delay_ms(50);
PORTB=3; //binary equivalent value:00000011
Delay_ms(50);
PORTB=7; //binary equivalent value:00000111
Delay_ms(50);
PORTB=15; //binary equivalent value:00001111
Delay_ms(50);
PORTB=31; //binary equivalent value:00011111
Delay_ms(50);
PORTB=63; //binary equivalent value:00111111
Delay_ms(50);
PORTB=127; //binary equivalent value:01111111
Delay_ms(50);
PORTB=255; //binary equivalent value:11111111
Delay_ms(50);
PORTB=0; //binary equivalent value:00000000
Delay_ms(50);
}
else
{
PORTB=0x00; //binary equivalent value:00000000
Delay_ms(200);
PORTB=0xFF; //binary equivalent value:11111111
Delay_ms(200);
}
}
}

Back to top