Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Keypad and LCD interfacing for 8051

Status
Not open for further replies.
check this link out for
**broken link removed**
hope this might be useful

Hey mike,
please make it a habit to read the thread starting date. dont reply for very old threads. since you are new comer, its my advice not to reply without reading the date of post. Lessen the burden of moderators, who cannot check all the posts.
 


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <REGX51.H>
sbit rs=P3^5;
sbit rw=P3^6;
sbit en=P3^7;
delay(unsigned int i)
{
 while(i--);
}
lcd_cmd(unsigned char c)
{
    P1=c;
    rs=0;
    rw=0;
    en=1;
    delay(150);
    en=0;
}
lcd_data(unsigned char c)
{
    P1=c;
    rs=1;
    rw=0;
    en=1;
    delay(150);
    en=0;
}
lcd_init()
{
    lcd_cmd(0x38);
    lcd_cmd(0x0c);
    lcd_cmd(0x01);
    lcd_cmd(0x80);
    
}
 
void main()
{
int i;
lcd_init();
for(i=0;i<=16;i++)
 
{
lcd_cmd(0x01);
lcd_cmd(0x80+i);
lcd_data( "VINOTH");
 
}
lcd_cmd(0xc0);
lcd_data( "  HELLO World");
}

 
Last edited by a moderator:

Hello there, i have problem with my keypad and LCD..
I use 89s52 and already build my own code using keil. the LCD should display 3 digit that pressed on keypad, unfortunately the lCD only show the first number that I pushed until three times..
can anybody help me?

thanks..
 

Hello there, i have problem with my keypad and LCD..
I use 89s52 and already build my own code using keil. the LCD should display 3 digit that pressed on keypad, unfortunately the lCD only show the first number that I pushed until three times..
can anybody help me?

thanks..
can I see the code ?
thanks
 

Code:
#pragma SMALL DB OE
#include<stdio.h>
#include<reg52.h>
//#include"stdlib2.h"

#define port P3
#define dataport P2
#define key P1

sbit rs=port^7;
sbit rw=port^5;
sbit en=port^6;

sbit col1=key^4;
sbit col2=key^5;
sbit col3=key^6;
sbit row1=key^0;
sbit row2=key^1;
sbit row3=key^2;
sbit row4=key^3;
sbit out=P0^7;
sbit pir1=P0^0;
sbit pir2=P0^1;

static unsigned int time;
static unsigned int count;
static unsigned timer,timer1;
static unsigned int bcounter=1;
int digit[3]={0,0,0};

int i,k;

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

void lcd_cmd(unsigned char item) // Function to send command to LCD
{
dataport = item;
rs= 0;
rw=0;
en=1;
delay(1);
en=0;
return;
}

void lcd_data(unsigned char item) // Function to send data to LCD
{
dataport = item;
rs= 1;
rw=0;
en=1;
delay(1);
en=0;
return;
}

void lcd_data_string(unsigned char *str) // Function to send data to string
{
while(*str)
{
  lcd_data(*str++);
  delay(1);
}
return;
}

void lcd(unsigned char str[10])
{
lcd_cmd(0x38);
lcd_cmd(0x0e);
lcd_data_string(str);
}

void lcd_data_int(int time_val)			// Function to send three digit number
{
	int int_amt;
	int_amt = time_val/100;
	lcd_data(int_amt+48);
	time_val = time_val%100;
	int_amt = time_val/10;
	lcd_data(int_amt+48);
	int_amt = time_val%10;	 
	lcd_data(int_amt+48);
}

void digit_set(int num)			
{
	if(count==4)
	{
		lcd_cmd(0x01);
		lcd_data_string("done");
	}
	else
	{
		if(count==1)
			digit[0]=num;
		else
		{
			if(count==2)
			{
				digit[1]=digit[0];
				digit[0]=num; 
			}
			else
				if(count==3)
				{
					digit[2]=digit[1];
					digit[1]=digit[0];
					digit[0]=num;
				}
		}
		lcd_data((num+48));
	}
}

void check_col1()		 // Col1 check
{
	row1=row2=row3=row4=1;
	row1=0;
	if(col1==0)				 	// Key 1
	{  
		delay(10);
		count=count+1;
		digit[i]=0;
	}
	row1=1;
	row2=0;
	if(col1==0)					// Key 4
	{
		delay(10);
		count=count+1;
		digit[i]=0;
	}
	row2=1;
	row3=0;
	if(col1==0)			  		// Key 7
	{ 
		delay(10);
		count=count+1;
		digit[i]=0;
	}
	row3=1;
	row4=0;
	if(col1==0)					// Key *
	{ 
		delay(10);
		count=count+1;
		if(count==4)
		{
			digit_set(10);
		}
		else
		{
			count=4;
			digit_set(10);
		}
	}
	row4=1;
}

void check_col2()     //Col2 check
{
	row1=row2=row3=row4=1;
	row1=0;
	if(col2==0)					// Key 2
	{
		delay(10);
		count=count+1;
		digit_set(2);
	}
	row1=1;
	row2=0;
	if(col2==0)			 		// Key 5
	{
		delay(10);
		count=count+1;
		digit_set(5);
	}
	row2=1;
	row3=0;
	if(col2==0)	       				// Key 8
	{
		delay(10);
		count=count+1;
		digit_set(8);
	}
	row3=1;
	row4=0;
	if(col2==0)		 			// Key 0
	{
		delay(10);
		count=count+1;
		digit_set(0);
	}
	row4=1;
}

void check_col3()	 // Col3 check
{
	row1=row2=row3=row4=1;
	row1=0;
	if(col3==0)					// Key 3
	{
		delay(10);
		count=count+1;
		digit_set(3);
	}
	row1=1;
	row2=0;
	if(col3==0)			   		// Key 6
	{
		delay(10);
		count=count+1;
		digit_set(6);
	}
	row2=1;
	row3=0;
	if(col3==0)				  	// Key 9
	{
		delay(10);
		count=count+1;
		digit_set(9);
	}
	row3=1;
	row4=0;
	if(col3==0)					// Key #
	{
		delay(10);
		EA=1;
		lcd_cmd(0x01);
		lcd_data_string("counting down . . .");
	}
	row4=1;
}

void keypad()
{ 
row1=row2=row3=row4=0;
while(col1==1&&col2==1&&col3==1);
row1=row2=row3=row4=0;
	if(col1==0)
		check_col1();
	else
		if(col2==0)
			check_col2();
		else
			if(col3==0)
				check_col3();
	delay(10);
}

void main()
{
unsigned int k;

TMOD=0x01;
EA=0;
TH0=50621/256;TL0=50621%256;
ET0=1;
EX0=1;
IT0=1;
PX0=1;
TF0=0;
//TR0=1;

count=0;			//initial count value
k=time;

pir1=pir2=0;
	

out=0;
 lcd_cmd(0x38);
 delay(2); 
 lcd_cmd(0x01);  // Clear Screen
 lcd("WELCOME");
				delay(50000);
		count=0;
		delay(1);
		lcd_cmd(0x01);
		lcd_cmd(0x80);
		lcd("Enter time interval(second):");
				
	
for(i=0;i<3;i++)
		{ 
		delay(50);
		lcd_cmd(0xc4+i);
		row1=row2=row3=row4=0;
		while(col1==1&&col2==1&&col3==1);
		keypad();
		time=(digit[0]+(digit[1]*10)+(digit[2]*100));		
		delay(1);
		}

	while(1);
	{
		int out;
 		if(pir1==0 && pir2==0)
  		out=0;
  		if(pir1==1 && pir2==0)
  		out=1;
 		if(pir1==0 && pir2==1)
  		out=1;
 		if(pir1==1 && pir2==1)
  		out=1;
		if(out==1) {
		EA=1;
		}
		if(time==0)
			out=0;
		
	}
	}


void isr_t0()interrupt 1 using 2
{
 TR0=0;
 TF0=0;
 TH0=50621/256;TL0=50621%256;
 if(++timer==20)
 {--time;//bcounter^=1;
  timer=0;
   }
  if(++timer1==5){(bcounter^=1);timer1=0;}
 TR0=1;
 }
 
void key_isr() interrupt 0 using 1
{
EX0=0;
if(col3==0&&row4==0)
{
TR0=~TR0;
if(TR0)
time=0;
}
EX0=1;
}

thank you.. :)
 

can u explain this codeafter while(1) loop plzzzz.......
 

can u explain this codeafter while(1) loop plzzzz.......

I just compare two input (pir1 & pir2) to get output=1. and if the output=1, then activate EA(enable interrupt)
 

thankss...i have tried this program by lcd.h header file to simplify it..but it was giving error...now can u please give the program of keypad and lcd interfacing using lcd.h header file for 8051 in kiel uv2...
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top