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

Sat Feb 24 2018, 09:05 AM
Aaquib
I want help for digital ic tester
ExperimenterUK
Tue Feb 20 2018, 09:31 PM
Join up.. and post your problem
Mon Feb 19 2018, 04:47 PM
ashishkumar
i needs help for my project
Mon Feb 19 2018, 04:46 PM
ashishkumar
can i join you guys
ExperimenterUK
Mon Feb 05 2018, 03:08 AM
Hi Dave. Good to see you.
DavesGarage
Wed Jan 10 2018, 01:25 AM
It's been a few years since I poked around here - Hi all...
ExperimenterUK
Tue Jan 09 2018, 12:49 AM
Hi TPS. it's been a while..
۞ TPS ۞
Mon Jan 08 2018, 12:12 AM
hello
Thu Jan 04 2018, 07:20 PM
sayyad affrid
its AT89S52
Thu Jan 04 2018, 07:20 PM
sayyad affrid
sir, i want embedded c code for ultrasonic sensor having buzzer interfaced with AT9S52

Downloads

Comments

Manojsanghavi
Sat Feb 24 2018, 12:47 PM
Daro12_76
Wed Feb 21 2018, 05:01 PM
radhikanathani
Wed Feb 21 2018, 06:55 AM
Narayani
Wed Feb 21 2018, 04:10 AM
Parth09
Tue Feb 20 2018, 07:53 AM
goutham
Mon Feb 19 2018, 02:49 AM
kks
Sun Feb 18 2018, 05:59 PM
justotemon
Sat Feb 17 2018, 07:14 AM

Online

Guests: 36, Members: 0 ...

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

Members: 37971
Newest member: Manojsanghavi
Forum Activity
Manojsanghavi Avatar
Posted By Manojsanghavi
Sat Feb 24 2018, 01:03 PM
Dear allCan someone please help me on how to progr...
Ansh12 Avatar
Posted By Ansh12
Fri Feb 23 2018, 07:10 PM
sbit E = P0^7; //E pin for LCD //use port 0sb...
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Feb 23 2018, 02:43 PM
sbit NOT #definesbit E = P0^7; //E pin for LCD ...
Ansh12 Avatar
Posted By Ansh12
Fri Feb 23 2018, 01:55 PM
change your defines tosbit E = P0^7; //E pi...
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Feb 23 2018, 01:12 AM
Add pull- ups for EN and RS.change your defines t...
Ansh12 Avatar
Posted By Ansh12
Thu Feb 22 2018, 01:36 AM
Can you post your Proteus files.ExperimenterUKThan...
ExperimenterUK Avatar
Posted By ExperimenterUK
Wed Feb 21 2018, 09:07 PM
The code you refer to is to drive the circuitshown...
ExperimenterUK Avatar
Posted By ExperimenterUK
Wed Feb 21 2018, 05:41 PM
Can you post your Proteus files.You will need pull...
radhikanathani Avatar
Posted By radhikanathani
Wed Feb 21 2018, 02:39 PM
I want to design a system for vehicle tracking and...
Narayani Avatar
Posted By Narayani
Wed Feb 21 2018, 04:17 AM
Hello,Your tutorial really helped me understand st...