Keypad interface and display program.

Status
Not open for further replies.

joseph raj

Junior Member level 2
Joined
Mar 16, 2009
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,501
proteus keypad

Hi ,i have interfaced keypad,encoder mm74c922,lcd jhd162a and PIC16F877A to display the key pressed.
I am connecting keypad encoder to PIC.
I am using mplab ide.and hitechc c compiler.
My program is as below.I am using Proteus software for simulation.there is no error while building but it doesn't display the key pressed .
I have checked Lcd program and it displays hello world display when checked independently.Please help me out and make corrections necessarily.
#include<htc.h>
extern void lcd_cmd(unsigned char);
extern void lcd_data(unsigned char);
extern void lcd_ready(void);
extern void lcd_clear(void);
extern void ms_delay(unsigned int);
#define LCD_data PORTD
#define busy_bit RD7
#define LCD_rs RE0
#define LCD_rw RE1
#define LCD_en RE2
#define enc_out PORTB


void lcd_init(void)
{

ADCON1=0x06;
TRISE=0;
TRISD=0;
lcd_cmd(0x38);
lcd_cmd(0x0C);
//lcd_cmd(0x01);
lcd_cmd(0x0E);
lcd_cmd(0x06);
return;
}

void lcd_cmd(unsigned char value)
{
// lcd_ready();
LCD_data=value;
LCD_rs=0;
LCD_rw=0;
LCD_en=1;
ms_delay(1);
LCD_en=0;
return;
}

void lcd_clear(void)
{
LCD_rs=0;
lcd_data(0x01);
LCD_en=1;
ms_delay(1);
LCD_en=0;
return;
}
void lcd_ready(void)
{
//busy_bit=1;
LCD_rs=0;
LCD_rw=1;
while(busy_bit==1)
{
LCD_en=0;
ms_delay(1);
LCD_en=1;
}
return;
}




void lcd_data(unsigned char value)
{
//lcd_ready();
LCD_data=value;
LCD_rs=1;
LCD_rw=0;
LCD_en=1;
ms_delay(20);
LCD_en=0;
return;
}

void ms_delay(unsigned int itime)
{
int i,j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++);
}

void main(void)
{

unsigned int temp;
lcd_init();
lcd_clear();
TRISB=0xF0;
OPTION = 0b00000111;
TRISB = 0b00000011;
//RBPU = 0;
INTEDG=1;
INTE=1;
GIE=1;

if (INTF)
{
lcd_cmd(0x80);
temp= enc_out & 0xF0;
if(temp==0b00010000)
{

lcd_data('1');
}
else if(temp==0b00100000)
{
lcd_data('2');
}
else if(temp==0b00110000)
{

lcd_data('3');
}
else if(temp==0b01000000)
{

lcd_data('4');
}
else if(temp==0b01010000)
{
lcd_data('5');
}
else if(temp==0b01100000)
{
lcd_data('6');
}
else if(temp==0b01110000)
{
lcd_data('7');
}
else if(temp==0b10000000)
{
lcd_data('8');
}
else if(temp==0b10010000)
{
lcd_data('9');
}
else if(temp==0b10100000)
{
lcd_data('*');
}
else if(temp==0b10110000)
{
lcd_data('0');
}

else if(temp==0b11000000)
{
lcd_data('#');
}
INTF=0;
}
}
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…