Discussion in "8051 Discussion Forum" started by    Ansh12    Nov 17, 2017.
Fri Nov 17 2017, 04:07 AM
#1
I am looking keypad interfacing program. I was reading tutorial Keypad programming for 8051 http://www.8051projects.net/keypad-interfacing/8051-programming.php
I have seen program in link. its not complete program. Also I didn't understand keypad reading functions. I am trying to understand keypad reading in c programming. Please help me..

Sun Nov 19 2017, 08:35 PM
#2
As a starting point, can you tell us how much of the tutorial example you understand ?
Do you have access to the Proteus program to simulate a circuit ?

Mon Nov 20 2017, 02:15 AM
#3


As a starting point, can you tell us how much of the tutorial example you understand ?
Do you have access to the Proteus program to simulate a circuit ?

ExperimenterUK


I understand logic of keypad but I am having difficulties to implement program. That's the reason first I tried to implement function for keypad reading.

I have simulator software. I can simply add keypad and lcd to 8051 controller.

In tutorial, there is only program for keypad interfacing, no program for both lcd and keypad. I wanted to see sample example for lcd and keypad interfacing program. once I see its working on proteus. I can try to understand the whole program. I have keil compiler and at89c51 controller.
Mon Nov 20 2017, 10:18 PM
#4
Here is a version of the tutorial that reads a key and prints it to a serial terminal.
There is also a Proteus project to run the program and display the code as a hex value.
In Proteus ->Virtual Terminal, make sure "Hex display mode" is ticked
 Ansh12 like this.
Mon Feb 19 2018, 12:17 PM
#5


Here is a version of the tutorial that reads a key and prints it to a serial terminal.

ExperimenterUK


Please see the below code. I have taken idea from your code to read keypad. there is no error in code but it doesn't print anything on screen.
AT89c51 & Keil
#include<reg51.h>

#define keyport P1	//keypad connected to P1
#define lcdport P2	//lcd connected to P2

sbit C1 = P1^0;     //Column1
sbit C2 = P1^1;     //Column2
sbit C3 = P1^2;     //Column3
sbit C4 = P1^3;     //Column4

sbit E    = P3^6;     //E pin for LCD
sbit RS   = P3^7;     //RS pin for LCD

//Function declarations
void init_port(void);
void Delay(int);
void LCD_Init(void);
void LCD_Command(int);
void LCD_Data(char);
char Get_key(void);

int main(void)
{
   char key;         // key char for keeping record of pressed key
	
	 init_port();      // Make input and output pins as required
           
        LCD_Init();       // Initilize LCD

   while(1)
   { 
           key = Get_key();       // Get pressed key
	   LCD_Data(key+1);        // Echo the key pressed to LCD
   }
}


void init_port(void)
{
	P0 = 0x00;   //not used
	P1 = 0x0f;   //used for generating outputs and taking inputs from Keypad
	P2 = 0x00;   //used as data port for LCD
	P3 = 0x00;   //used for RS and E   
}

void Delay(int a)
{
   int i;
   for(i=0;i<a;i++);   //Delay
}

void LCD_Data(char t)
{
   RS = 1;             // This is data
   P2 = t;             //Data transfer
   E  = 1;             //  E = 1
   Delay(150);
   E  = 0;             // E = 0
   Delay(150);
}


void LCD_Command(int z)
{
   RS = 0;             // This is command
   P2 = z;             //Data transfer
   E  = 1;             // E = 1
   Delay(150);
   E  = 0;             // E = 0
   Delay(150);
}

void LCD_Init(void)
{
 
     Delay(15000);
     LCD_Command(0x30);
     Delay(4500);
     LCD_Command(0x30);
     Delay(300);
     LCD_Command(0x30);
     Delay(650);
 
    LCD_Command(0x38);    //function set
    LCD_Command(0x0c);    //display on,cursor off,blink off
    LCD_Command(0x01);    //clear display
    LCD_Command(0x06);    //entry mode, set increment
}

 char get_key()
{
	unsigned char i, k, key = 0;
	k = 1;
	for(i = 0; i < 4; i++){		//loop for 4 rows
		
		keyport &=~ (0x80>
>
i);	//to make rows low 1 by 1
		 
  		               if(!C1){	            //check if key1 is pressed
				 Delay(10000);
				key = k+0;	        //set key number
				while(!C1);	        //wait for release
				return key;	        //return key number
			        }

			      if(!C2){	             //check if key2 is pressed
				 Delay(10000);
				key = k+1;	         //set key number
				while(!C2);	         //wait for release
				return key;	         //return key number
			         }

			         if(!C3){	             //check if key3 is pressed
				 Delay(10000);
				key = k+2;         	//set key number
				while(!C3);	        //wait for release
				return key;	        //return key number
			         }

    			      if(!C4){	            //check if key4 is pressed
				 Delay(10000);
				key = k+3;	        //set key number
				while(!C4);	        //wait for release
				return key;	        //return key number
			}
		k+=4;			              //next row key number
		keyport |= 0x80>
>
i;	    //make the row high again
	}
	return 0;			            //return 0 if no key pressed
}



[ Edited Mon Feb 19 2018, 12:52 PM ]
Tue Feb 20 2018, 04:16 PM
#6
Change .....
while(1)
{
key = Get_key(); // Get pressed key
LCD_Data(key+1); // Echo the key pressed to LCD
}

to...

while(1)
{
key = Get_key(); // Get pressed key if any
if(key) //only print if a key is pressed
LCD_Data(key+0x60); // Send a printable value to LCD

}

Adding 0x60 ,moves the code it into the printable range a-p


[ Edited Tue Feb 20 2018, 04:32 PM ]
Wed Feb 21 2018, 12:53 AM
#7



while(1)
{
key = Get_key(); // Get pressed key if any
if(key) //only print if a key is pressed
LCD_Data(key+0x60); // Send a printable value to LCD

}

ExperimenterUK


Thanks for your fast feedback. I did replace that portion of code But this code is not working there nothing on the screen

Please take look at the connection . It may be one of the reason

Wed Feb 21 2018, 05:41 PM
#8
Can you post your Proteus files.
You will need pull-up resistors on port 0.

Thu Feb 22 2018, 01:36 AM
#9


Can you post your Proteus files.

ExperimenterUK


Thanks I have attached file. Please look at this
Fri Feb 23 2018, 01:12 AM
#10
Add pull- ups for EN and RS.
change your defines to

sbit E = P0^7; //E pin for LCD
sbit RS = P0^5; //RS pin for LCD

R1,3,4 and 5 are not needed.

Get Social

Information

Powered by e107 Forum System

Conversation

Sun May 20 2018, 10:01 AM
justinb
how to write and execute a program that read the keypad button and display the number on 7 segment on intel8051 at89s52 in assembly language?
Thu May 17 2018, 06:36 AM
HAMZA TAJ
sir iwant to ask about controller of three phase supply by using back to back thyristor instead of triac....will u give me some guideline?
Sat Apr 28 2018, 12:54 PM
ashutosh jain
IR Remote Switch using TV remote (RC5 Protocol) is not working properly. opp1 & opp2 is in problem.plz help
ExperimenterUK
Fri Apr 27 2018, 08:09 PM
@kaiserslautern Post in forum
Wed Apr 25 2018, 07:09 AM
kaiserslautern
Hello everyone, using software uart is a very good idea for a second serial port. Thank you so much. I would kindly like to know how to connect this port to the PC?
ExperimenterUK
Sat Apr 21 2018, 07:50 PM
This is a community site. Feel free to help anyone needing advice
hareeshchamiyar
Thu Mar 29 2018, 10:47 AM
please help me for the configuration bits for dspic30f2010
hareeshchamiyar
Thu Mar 29 2018, 10:45 AM
can any one using dspic30f2010.
Thu Mar 29 2018, 06:03 AM
Neena
can anybody give solar tracking in 8051 using proteus and keil to mail [email protected]
ExperimenterUK
Mon Mar 19 2018, 07:33 PM
sorry bedo.. maybe next time

Downloads

Comments

bdmehta
Tue May 22 2018, 02:30 AM
kmag1953
Sun Apr 29 2018, 07:09 PM
udiwonder
Sat Apr 28 2018, 12:41 PM
pirpiri
Sat Apr 21 2018, 03:35 PM
Pater
Fri Apr 20 2018, 02:38 PM
jamiel
Sat Apr 14 2018, 12:47 AM
akrepkral76
Wed Apr 04 2018, 07:51 PM
samanthaeaves
Mon Apr 02 2018, 06:27 AM

Online

Guests: 56, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 37998
Newest member: bdmehta
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Thu Jun 21 2018, 10:49 PM
The frequency of the pulses has to be the same as ...
LAMBO Avatar
Posted By LAMBO
Thu Jun 21 2018, 02:13 PM
hi sircan we change the frequency on pin no 39 of ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sat Jun 16 2018, 11:33 PM
hi sir sorry for the late reply sir can we control...
LAMBO Avatar
Posted By LAMBO
Sat Jun 16 2018, 07:15 AM
hi sir sorry for the late reply sir can we control...
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon May 14 2018, 10:17 PM
So the main problem is that I am not getting Analo...
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon May 14 2018, 09:40 PM
Hi sir after checking all the connection i...
Pater Avatar
Posted By Pater
Mon May 14 2018, 05:36 PM
Basically my project is based on Data Acquisition ...
LAMBO Avatar
Posted By LAMBO
Sun May 13 2018, 02:13 PM
Hi sir after checking all the connection i...
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon May 07 2018, 07:27 PM
This design should be fine.Choose a frequency betw...
Pater Avatar
Posted By Pater
Mon May 07 2018, 01:28 PM
Sorry for late reply as exams were on,Based on my ...