LCD and KEYPAD interfacing using 8051 c language..

Status
Not open for further replies.

own

Newbie level 2
Joined
Nov 25, 2008
Messages
2
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,298
keypad interfacing with 8051

Hello everybody, firstly i'm new in microcontroller field. So hopefully our member can help me. Actually i want to display on LCD if 4x4 keypad is press. SO, Who have code in c language for combine lcd and keypad.Thanks for your help
 

keypad 8051

Hi Own..

here the code....for Keypad Scanning.....please use your own mind to get schematic...(discuse with your friends...)
For LCD Display visit link...below...maybe usefull
/*************************
* Scanning of Keypad
* Lecturer: ibnubudir
*
* Date: 17. July 2004
* Using Laros Elektor Board v2.3
* Editor+compiler Raisonance
* **broken link removed**
*************************/
#include <reg8252.h>
#include <stdio.h>
char code column[] = {0xbf,0xdf,0xef};
void keypad (void) interrupt 2
{
char x,key;
unsigned int k;
EX1 = 0;

P1=0xff;
for (x=0; x<3; x++)
{
P1=column[x];
for(k=0;k<0xff;k++);
if ((P1&0x0f)!=0x0f)
{
key=P1;
switch(key)
{
case 0xb7 : putchar('1');break;
case 0xd7 : putchar('2');break;
case 0xe7 : putchar('3');break;
case 0xbb : putchar('4');break;
case 0xdb : putchar('5');break;
case 0xeb : putchar('6');break;
case 0xbd : putchar('7');break;
case 0xdd : putchar('8');break;
case 0xed : putchar('9');break;
case 0xbe : putchar('*');break;
case 0xde : putchar('0');break;
case 0xee : putchar('#');break
}
}
}
for (k=0;k<0xffff;k++);
P1=0x0f;
EX1=1;
}
void main (void)
{
EA=1;
EX1=1;
IT1=1;
P1=0x0f;
while(1);
}
 

    V

    Points: 2
    Helpful Answer Positive Rating
8051 lcd c

thanks for your reply..Can you tell my how to display to lcd.thanks
 
8051 keypad

which program u use for 8051 c?where can we download it
 
keypad interfacing

keil is the most used compiler for c and its excellent
after making the hex file by compiling ur c file with keil , u need to conevert .hex file to binary ( or in some cases ur programmer screen based .exe does that) and then the binary file is burned in to the chip by the programer.

hope this helped.

- RONY
 

keypad c code

I suggest you to learn asm along with c...
Also try to find some info on lcd and keypad by googling, you should ask help when you have a problem, just copying and pasting codes will not help you in learning.

you should try working codes only when your selfmade code doesn't run.
Developing your own code gives you lots of experience and you will come to know what are the problems and difficulties while developing..

Anyways if you want tutorials on how to use an IDE, and where to start with microcontrollers, here is some help:
**broken link removed**

enjoy learning microcontrollers.
 

keypad interfacing with microcontroller

i want a code for this please give me code i hv to use in programme
 

Re: keypad interfacing with 8051

use this code
// Program to make alphabetical keypad similar to the one in mobiles
#include<reg51.h>
#define port P1
#define dataport P2 //Data port for LCD
#define key P0 // Port for Keypad
#define sec 100
sbit rs = port^1;
sbit rw = port^2;
sbit en = port^3;

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;
unsigned char position=128,i=0;
int check_again[10]={0,0,0,0,0,0,0,0,0,0};

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

void lcd_cmd(unsigned char item)
{
dataport = item;
rs= 0;
rw=0;
en=1;
delay(1);
en=0;
return;
}

void lcd_data(unsigned char item)
{
lcd_cmd(0x0f);
delay(10);
dataport = item;
rs= 1;
rw=0;
en=1;
delay(1);
en=0;
return;
}

void num_check(int a , int b) //Check function
{
int j;
for(j=0;j<10;j++)
{
if(j!=a)
{
check_again[j]=0;
}
}
if(check_again[a]==3)
check_again[a]=0;
check_again[11]=1;
check_again[12]=1;
}

void display(int a ,int b) // Display function
{
switch(b)
{
case 1:
{
switch(a)
{
case 1:{
if(check_again[a]>1)
i--;
lcd_cmd(position+i);
lcd_data('a');
delay(5);
num_check(1 ,check_again[1]);
break;
}
case 2:{
if(check_again[a]>1)
i--;
lcd_cmd(position+i);
lcd_data('d');
delay(5);
num_check(2 ,check_again[2]);
break;
}
case 3: {
if(check_again[a]>1)
i--;
lcd_cmd(position+i);
lcd_data('g');
delay(5);
num_check(3 ,check_again[3]);
break;
}
case 4:{
if(check_again[a]>1)
i--;
lcd_cmd(position+i);
lcd_data('j');
delay(5);
num_check(4 ,check_again[4]);
break;
}
case 5:{
if(check_again[a]>1)
i--;
lcd_cmd(position+i);
lcd_data('m');
delay(5);
num_check(5 ,check_again[5]);
break;
}
case 6:{
if(check_again[a]>1)
i--;
lcd_cmd(position+i);
lcd_data('p');
delay(5);
num_check(6 ,check_again[6]);
break;
}
case 7:{
if(check_again[a]>1)
i--;
lcd_cmd(position+i);
lcd_data('s');
delay(5);
num_check(7 ,check_again[7]);
break;
}
case 8:{
if(check_again[a]>1)
i--;
lcd_cmd(position+i);
lcd_data('v');
delay(5);
num_check(8 ,check_again[8]);
break;
}
case 9:{
if(check_again[a]>1)
i--;
lcd_cmd(position+i);
lcd_data('y');
delay(5);
num_check(9 ,check_again[9]);
break;
}
case 0:{
lcd_cmd(position+i);
lcd_data(' ');
delay(5);
num_check(10 ,check_again[10]);
break;
}
case 11:{
if((position+i)>129)
{
i=i-2;
delay(5);
lcd_cmd(position+i+1);
num_check(11 ,check_again[11]);;
delay(5);
}
break;
}
case 12:{
delay(5);
lcd_cmd(position+i);
num_check(12 ,check_again[12]);
delay(5);
break;
}
}
break;
}
case 2:
{
switch(a)
{
case 1:{
if(check_again[a]>1)
i--;
lcd_cmd(position+i);
lcd_data('b');
delay(5);
num_check(1 ,check_again[1]);
break;
}
case 2:{
if(check_again[a]>1)
i--;
lcd_cmd(position+i);
lcd_data('e');
delay(5);
num_check(2 ,check_again[2]);
break;
}
case 3: {
if(check_again[a]>1)
i--;
lcd_cmd(position+i);
lcd_data('h');
delay(5);
num_check(3 ,check_again[3]);
break;
}
case 4:{
if(check_again[a]>1)
i--;
lcd_cmd(position+i);
lcd_data('k');
delay(5);
num_check(4 ,check_again[4]);
break;
}
case 5:{
if(check_again[a]>1)
i--;
lcd_cmd(position+i);
lcd_data('n');
delay(5);
num_check(5 ,check_again[5]);
break;
}
case 6:{
if(check_again[a]>1)
i--;
lcd_cmd(position+i);
lcd_data('q');
delay(5);
num_check(6 ,check_again[6]);
break;
}
case 7:{
if(check_again[a]>1)
i--;
lcd_cmd(position+i);
lcd_data('t');
delay(5);
num_check(7 ,check_again[7]);
break;
}
case 8:{
if(check_again[a]>1)
i--;
lcd_cmd(position+i);
lcd_data('w');
delay(5);
num_check(8 ,check_again[8]);
break;
}
case 9:{
if(check_again[a]>1)
i--;
lcd_cmd(position+i);
lcd_data('z');
delay(5);
num_check(9 ,check_again[9]);
break;
}
case 0:{
lcd_cmd(position+i);
lcd_data('-');
num_check(10 ,check_again[10]);
break;
}
case 11:{
i--;
lcd_cmd(0x10);
delay(5);
break;
}
}
break;
}
case 3:
{
switch(a)
{
case 1:{
if(check_again[a]>1)
i--;
lcd_cmd(position+i);
lcd_data('c');
delay(5);
num_check(1 ,check_again[1]);
break;
}
case 2:{
if(check_again[a]>1)
i--;
lcd_cmd(position+i);
lcd_data('f');
delay(5);
num_check(2 ,check_again[2]);
break;
}
case 3: {
if(check_again[a]>1)
i--;
lcd_cmd(position+i);
lcd_data('i');
delay(5);
num_check(3 ,check_again[3]);
break;
}
case 4:{
if(check_again[a]>1)
i--;
lcd_cmd(position+i);
lcd_data('l');
delay(5);
num_check(4 ,check_again[4]);
break;
}
case 5:{
if(check_again[a]>1)
i--;
lcd_cmd(position+i);
lcd_data('o');
delay(5);
num_check(5 ,check_again[5]);
break;
}
case 6:{
if(check_again[a]>1)
i--;
lcd_cmd(position+i);
lcd_data('r');
delay(5);
num_check(6 ,check_again[6]);
break;
}
case 7:{
if(check_again[a]>1)
i--;
lcd_cmd(position+i);
lcd_data('u');
delay(5);
num_check(7 ,check_again[7]);
break;
}
case 8:{
if(check_again[a]>1)
i--;
lcd_cmd(position+i);
lcd_data('x');
delay(5);
num_check(8 ,check_again[8]);
break;
}
case 9:{
if(check_again[a]>1)
i--;
lcd_cmd(position+i);
lcd_data('z');
delay(5);
num_check(9 ,check_again[9]);
break;
}
case 0:{ lcd_cmd(position+i);
lcd_data('-');
num_check(10 ,check_again[10]);
break;

}
case 11:{
i=i-2;
lcd_cmd(position+i);
delay(5);
break;
}
}
break;
}
}
}

void check_col1() //Check column one
{
row1=row2=row3=row4=1;
row1=0;
if(col1==0)
{
delay(10);
check_again[1]++;
display(1,check_again[1]);
}
row1=1;
row2=0;
if(col1==0)
{
delay(10);
check_again[4]++;
display(4,check_again[4]);
}
row2=1;
row3=0;
if(col1==0)
{
delay(10);
check_again[7]++;
display(7,check_again[7]);
}
row3=1;
row4=0;
if(col1==0)
{
delay(10);
display(11,1); //FOR *
}
row4=1;
}

void check_col2() //Check column two
{
row1=row2=row3=row4=1;
row1=0;
if(col2==0)
{
delay(10);
check_again[2]++;
display(2,check_again[2]);
}
row1=1;
row2=0;
if(col2==0)
{
check_again[5]++;
display(5,check_again[5]);
}
row2=1;
row3=0;
if(col2==0)
{
delay(10);
check_again[8]++;
display(8,check_again[8]);
}
row3=1;
row4=0;
if(col2==0)
{
delay(10);
check_again[0]++;
display(0,1);
}
row4=1;
}

void check_col3() //check column three
{
row1=row2=row3=row4=1;
row1=0;
if(col3==0)
{
delay(10);
check_again[3]++;
display(3,check_again[3]);
}
row1=1;
row2=0;
if(col3==0)
{
delay(10);
check_again[6]++;
display(6,check_again[6]);
}
row2=1;
row3=0;
if(col3==0)
{
delay(10);
check_again[9]++;
display(9,check_again[9]);
}
row3=1;
row4=0;
if(col3==0)
{
delay(10);
display(12,1); //FOR #
}
row4=1;
}

void keypad1()
{
if((position+i)>144 && i>16)
{
position=192;
i=0;
}
if((position+i)>203 && i>12 )
{
lcd_cmd(0X01);
i=0;
position=128;
}
i++;
lcd_cmd(position+i);
if(col1==0)
check_col1();
else
if(col2==0)
check_col2();
else
if(col3==0)
check_col3();
delay(10);
}

void main()
{
col1=col2=col3=1;
lcd_cmd(0x38);
lcd_cmd(0x0e);
lcd_cmd(0x01);
delay(sec);
while(1)
{
row1=row2=row3=row4=0;
while(col1==1 && col2==1 && col3==1);
{
keypad1();
}
}
}
check this link out for other details
**broken link removed**
 

since you are a beginner, check out **broken link removed** and then go for **broken link removed**. I'm sure you'll get all the details about circuit connections and coding.
 
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…