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

ExperimenterUK
Mon Dec 03 2018, 06:17 PM
Please post questions in the forum. The chat box is for chat
Mon Dec 03 2018, 07:43 AM
help!me!
help! I don't understand busy flag!
Sun Dec 02 2018, 09:01 PM
ile
hello
Mon Nov 12 2018, 06:58 AM
Pavan_user
i have seen your replica of I2C programming using AT89C51 but i am unable to understand the "ack_bit" variable usage ...looks like it is always 1...can you elaborate how acknowledgment is working....
bgk3678
Tue Nov 06 2018, 03:36 PM
kindly any one give solution for my problem
ExperimenterUK
Mon Nov 05 2018, 10:48 PM
Pins high is the normal state. You need a program to set them low
mayengbam
Sun Nov 04 2018, 06:41 PM
hello, i am niranjoy, alll the port of my 8051 is always high, even i erase all the program. why is it so happen and what is the problem. any one please help me!
Sun Nov 04 2018, 03:16 PM
BASAVARAJ g kudamble
hi I am interfacing GSM 300 to 8051 microcontroller to receive message from mobile
ExperimenterUK
Sat Sep 29 2018, 07:28 PM
Please post questions in the forum.
Sat Sep 29 2018, 12:26 PM
Ashfaq Ch
hi i have some AT89C51RC microcontrollers already programed. some one help us to how to download from AT89C51RC and after study and edit all corractions reload to AT89C51RC controller

Downloads

Comments

mauste
Thu Dec 13 2018, 01:52 PM
sifirsekiz
Wed Dec 12 2018, 01:37 PM
cadetjeff
Fri Dec 07 2018, 10:11 AM
crak0axel
Sun Dec 02 2018, 01:12 AM
AbuHishaam
Thu Nov 29 2018, 03:43 PM
Evgen87
Thu Nov 29 2018, 10:44 AM
akshaykulkarni
Mon Nov 26 2018, 05:18 AM
atalnet
Fri Nov 16 2018, 07:44 AM

Online

Guests: 45, Members: 0 ...

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

Members: 38028
Newest member: mauste
Forum Activity
sifirsekiz Avatar
Posted By sifirsekiz
Thu Dec 13 2018, 04:31 PM
sifirsekiz Avatar
Posted By sifirsekiz
Wed Dec 12 2018, 01:50 PM
Hi guys I have max30100 pulse sensor need to measu...
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon Nov 19 2018, 01:11 AM
ExperimenterUK Avatar
Posted By ExperimenterUK
Thu Nov 15 2018, 06:48 PM
Unfortunately I have no experience of LabView,but ...
katherineamt Avatar
Posted By katherineamt
Mon Nov 12 2018, 03:22 PM
I have never used LabView and I have to implement ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon Nov 12 2018, 01:21 AM
wimac Avatar
Posted By wimac
Sun Nov 11 2018, 04:03 PM
bgk3678 Avatar
Posted By bgk3678
Sun Nov 11 2018, 07:25 AM
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Nov 06 2018, 06:10 PM
bgk3678 Avatar
Posted By bgk3678
Sun Nov 04 2018, 02:52 PM