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

shshistiem
Thu Sep 13 2018, 04:28 AM
hii!! some1 please let me know how i ll get rfid code to 8051 by WEIGAND mode
DrNossberg
Wed Sep 12 2018, 01:39 AM
is there anyone here?
Mon Aug 27 2018, 01:00 PM
bun
Hello everyone´╝ü
Sat Jul 21 2018, 11:51 AM
Dibakar Bhanja Chowdhury
By using a 555 timer how can I expand the range of the mobile phone jammer? Please reply me asap
Sun May 20 2018, 03:31 PM
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, 12:06 PM
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, 06:24 PM
ashutosh jain
IR Remote Switch using TV remote (RC5 Protocol) is not working properly. opp1 & opp2 is in problem.plz help
ExperimenterUK
Sat Apr 28 2018, 01:39 AM
@kaiserslautern Post in forum
Wed Apr 25 2018, 12:39 PM
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
Sun Apr 22 2018, 01:20 AM
This is a community site. Feel free to help anyone needing advice

Downloads

Comments

PCBindex
Fri Sep 14 2018, 02:45 AM
sirkit
Thu Sep 13 2018, 04:46 AM
shshistiem
Wed Sep 12 2018, 10:36 PM
DrNossberg
Tue Sep 11 2018, 03:25 PM
ranjanvh
Thu Sep 06 2018, 02:28 PM
rbbhamre
Tue Sep 04 2018, 06:15 PM
Tressie
Sun Sep 02 2018, 02:20 PM
Sudhansudeep
Fri Aug 31 2018, 08:26 AM

Online

Guests: 52, Members: 0 ...

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

Members: 38006
Newest member: PCBindex
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Thu Sep 13 2018, 08:39 PM
First of all, by reading your reply, I abandoned m...
DrNossberg Avatar
Posted By DrNossberg
Thu Sep 13 2018, 03:49 PM
Hi, thanks you for your reply ^^ First of all, by ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Wed Sep 12 2018, 12:12 AM
HiThere are several issues here.The original 8051 ...
DrNossberg Avatar
Posted By DrNossberg
Tue Sep 11 2018, 08:08 PM
Hello everybody!First of all let me explain some s...
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Sep 07 2018, 05:08 AM
The compiler thinks the micro doesn't have enough...
Sudhansudeep Avatar
Posted By Sudhansudeep
Fri Sep 07 2018, 02:59 AM
this is the build output message
Sudhansudeep Avatar
Posted By Sudhansudeep
Fri Sep 07 2018, 01:38 AM
Change the mobile number as [number removed] in t...
ExperimenterUK Avatar
Posted By ExperimenterUK
Thu Sep 06 2018, 08:56 PM
I don't know what the problem is, I get no errors....
Sudhansudeep Avatar
Posted By Sudhansudeep
Thu Sep 06 2018, 01:12 PM
the code is Attachment ...
Sudhansudeep Avatar
Posted By Sudhansudeep
Thu Sep 06 2018, 12:48 PM
the code is same as u sent me for 16 chars