Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] keypad interfacing with 8051. data doesn't show on lcd

Status
Not open for further replies.

uday mehta

Advanced Member level 4
Full Member level 1
Joined
Dec 30, 2011
Messages
104
Helped
6
Reputation
12
Reaction score
6
Trophy points
1,298
Activity points
1,979
I have written a keypad and LCD interfacing with 8051 program.
I works properly when I don't you scrolling command.
but when my display data exceed 16 characters then it get data from keypad but instead of show that pressed key it shift display one position. even I use command 0xC0. it never come to second line.

I tried it on proteus simulator. plz suggest me Is there any problem in proteus or in my program?
Code:
#include<reg51.h>

void cct_init(void);
void delay(int);
void lcdinit(void);
void wcmd(int);
void wdata(char);
void enter_roll(void);
char READ_SWITCHES(void);
char keypad(int);



//********************
// Define Pins
//********************
sbit RowA = P1^0;     //RowA
sbit RowB = P1^1;     //RowB
sbit RowC = P1^2;     //RowC
sbit RowD = P1^3;     //RowD

sbit C1   = P1^4;     //Column1
sbit C2   = P1^5;     //Column2
sbit C3   = P1^6;     //Column3
sbit C4   = P1^7;     //Column4

sbit en   = P3^6;     //E pin for LCD
sbit rs   = P3^7;     //RS pin for LCD
sbit te   = P3^3;	   //transmission inable for H12E



char key;                
int a,b,k=0;
int c;                 // check taht enter function called in which condition i.e for enter or change or status
char u[10];

void delay(int c)
{
 int i,j;
 for(i=0;i<c;i++)
 for(j=0;j<50;j++);
} 

void cct_init(void)
{
 P1 = 0xf0;   //used for generating outputs and taking inputs from Keypad
 P2 = 0x00;   //used as data port for LCD
 
 en = 0;   //used for E 
 rs = 0;   //used for RS  
}

void lcdinit()
{
 wcmd(0x38);
 delay(200);
 wcmd(0x0c);
 delay(200);
 wcmd(0x01);
 delay(200);
 wcmd(0x06);
 delay(200);
}

void wcmd(int b)
{
 rs = 0;
 P2 = b;
 en = 1;
 delay(50);
 en = 0;
 delay(50);
}

void wdata(char a)
{
 rs = 1;
 P2 = a;
 en = 1;
 delay(50);
 en = 0;
 delay(50);
}

void lcd(char *disp)
{
 int k,i;
 i=0;
 k=0;
 for(k=0;disp[k]!='\0';k++)
 {
  wdata(disp[k]);
  if(i>=15)
 {
  wcmd(0x07);
 }
  i++;
 }
 
}


void keypad(int k)
{
 key = get_key();       // Get pressed key
 wdata(key);        // Echo the key pressed to LCD
 u[k]=key;
}

void enter_roll()
{
 b=0;
 wcmd(0x01);
 lcd("enter your rollnumber");
 delay(100);
 wcmd(0XC0);
 do
 { 
  keypad(b);
  b++;
 }while( key !='#' );

 }

  //////////////////////////////////
 //******************************//
//////////////////////////////////
// Main program
int main(void)
{
 cct_init();
 lcdinit();               // Initilize LCD


 lcd("   welcome");
 while(1)
 {
  for(k=0;k<1;k++)
  {  
   key = get_key();       // Get pressed key
   wcmd(0X01);	              	       
  }
  enter_roll();
 }
}

char READ_SWITCHES(void)	
{	
	RowA = 0; RowB = 1; RowC = 1; RowD = 1; 	//Test Row A

	if (C1 == 0) { delay(500); while (C1==0); return '1'; }
	if (C2 == 0) { delay(500); while (C2==0); return '2'; }
	if (C3 == 0) { delay(500); while (C3==0); return '3'; }
	if (C4 == 0) { delay(500); while (C4==0); return '+'; }

	RowA = 1; RowB = 0; RowC = 1; RowD = 1; 	//Test Row B

	if (C1 == 0) { delay(500); while (C1==0); return '4'; }
	if (C2 == 0) { delay(500); while (C2==0); return '5'; }
	if (C3 == 0) { delay(500); while (C3==0); return '6'; }
	if (C4 == 0) { delay(500); while (C4==0); return '-'; }
	
	RowA = 1; RowB = 1; RowC = 0; RowD = 1; 	//Test Row C

	if (C1 == 0) { delay(500); while (C1==0); return '7'; }
	if (C2 == 0) { delay(500); while (C2==0); return '8'; }
	if (C3 == 0) { delay(500); while (C3==0); return '9'; }
	if (C4 == 0) { delay(500); while (C4==0); return '%'; }
	
	RowA = 1; RowB = 1; RowC = 1; RowD = 0; 	//Test Row D

	if (C1 == 0) { delay(500); while (C1==0); return '*'; }
	if (C2 == 0) { delay(500); while (C2==0); return '0'; }
	if (C3 == 0) { delay(500); while (C3==0); return '#'; }
	if (C4 == 0) { delay(500); while (C4==0); return '/'; }

	return 'n';           	// Means no key has been pressed
}

char get_key(void)           //get key from user
{
	char key = 'n';              //assume no key pressed

	while(key=='n')              //wait untill a key is pressed
		key = READ_SWITCHES();   //scan the keys again and again

	return key;                  //when key pressed then return its value
}
 

i checked your code.everything is fine except this function
Code:
void lcd(char *disp)
{
 
 unsigned short m=0;
	while(disp[m]!='\0')
	{
 	  	wdata(disp[m]);				  
 	  	m++;
   	}
 
}

- - - Updated - - -

Change this you will get the values of key pressed in 2nd line

- - - Updated - - -

Change this you will get the values of key pressed in 2nd line
 

look at the video. you will automatically understand the problem.
 

Attachments

  • New folder.rar
    2.4 MB · Views: 149

thank you very much.
now it is working properly.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top