Tuesday, 22 September 2015

4x4 Keypad programming in PIC16F877A( text on LCD(LM016L) according to buttons pressed )


#include<pic.h>
void delay(int);
void cmd(int);
void data(char);
void main()
{
int e;
TRISB=0X00;
TRISC=0X00;
TRISD=0X0F;
cmd(0X38);
cmd(0X01);
cmd(0X0E);
cmd(0X06);
cmd(0X80);
while(1)
{
PORTD=0X7F;
e=PORTD&0X0F;
switch(e)
{
case 0X07:
data('1');
break;
case 0X0B:
data('2');
break;
case 0X0D:
data('3');
break;
case 0X0E:
data('4');
break;
}
PORTD=0XBF;
e=PORTD&0X0F;
switch(e)
{
case 0X07:
data('5');
break;
case 0X0B:
data('6');
break;
case 0X0D:
data('7');
break;
case 0X0E:
data('8');
break;
}
PORTD=0XDF;
e=PORTD&0X0F;
switch(e)
{
case 0X07:
data('9');
break;
case 0X0B:
data('0');
break;
case 0X0D:
data('A');
break;
case 0X0E:
data('B');
break;
}
PORTD=0XEF;
e=PORTD&0X0F;
switch(e)
{
case 0X07:
data('C');
break;
case 0X0B:
data('D');
break;
case 0X0D:
data('E');
break;
case 0X0E:
data('F');
break;
}
}
}
void cmd(int s)
{
PORTB=s;
RC0=0;
RC1=0;
RC2=1;
delay(10);
RC2=0;
}

void data(char a)
{
PORTB=a;
RC0=1;
RC1=0;
RC2=1
delay(10);
RC2=0;
}
void delay(int k)
{
int i,j;
for(i=0;i<k;i++)
for(j=0;j<1000;j++);
}

No comments:

Post a Comment