Monday, 19 October 2015

PIC16F877A [4X4] KEYPAD WITH LCD

#include<pic.h>
#include<htc.h>
#define __PIC16F877A_H
__CONFIG(WDTE_OFF & FOSC_HS & PWRTE_OFF & LVP_OFF & BOREN_OFF);

void delay(unsigned int i)
{
while(i--);
}
void cmd(unsigned char c)
{
PORTD=c;
PORTC=0x04;
delay(100);
PORTC=0x00;
}
void dat(unsigned char c)
{
PORTD=c;
PORTC=0x05;
delay(100);
PORTC=0x01;
}
void lcd_init()
{
cmd(0x01);
delay(100);
cmd(0x0e);
delay(100);
cmd(0x80);
delay(100);
cmd(0x38);
delay(100);
}
void string(unsigned char *p)
{
while(*p!='\0')
{
dat(*p);
p++;
}
}

 void digit(unsigned int i)
 {
  unsigned char a,k=0x82;
   cmd(0x01);
  do
  {
  cmd(k--);  //agar num lagatar print karane hai to
  a=i%10;     //num vala function dal do
  dat(48+a);
  cmd(0x80);
  delay(10);
  i=i/10;
 }
 while(i>0);
 }

void main()
{
TRISB=0X00;
TRISC=0x00;
TRISD=0X00;
int a,b,c;
lcd_init();
PORTC=0x00;


while(1)
{
cmd(0xc0);
string("EMBEDDED LAB");
PORTB=0xf0;
while(PORTB==0xf0);
a=PORTB;
PORTB=0x0f;
b=PORTB;
while(PORTB!=0x0f);
c=a|b;
PORTC=c;
if(c==0xe7)
{
digit(1);
}
else if(c==0xeb)
{
digit(2);
}
else if(c==0xed)
{
digit(3);

}
else if(c==0xee)
{
digit(4);

}
else if(c==0xd7)
{
digit(5);
}
else if(c==0xdb)
{
digit(6);
}
else if(c==0xdd)
{
digit(7);
}
else if(c==0xde)

{
digit(8);
}
else if(c==0xb7)
{
digit(9);
}
else if(c==0xbb)
{
digit(10);
}
else if(c==0xbd)
{
digit(11);
}
else if(c==0xbe)
{
digit(12);
}
else if(c==0x77)
{
digit(13);
}
else if(c==0x7b)
{
digit(14);
}
else if(c==0x7d)
{
digit(15);
}
else if(c==0x7e)
{
digit(16);
}
}
}





No comments:

Post a Comment