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.

LCD display with numeric keypad 4x4

Status
Not open for further replies.

polong_5

Newbie level 4
Joined
Jul 30, 2008
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,322
Hello...
I just to ask regarding to the subject. is there anyone please give me some simple code to display numeric when pressing 4x4 numeric keypad. the lcd displays is 2x20 module and using pic 16f877.
 

Hi,
Please ref. the LCD example c file.
It used for 8051 serial CPU, you may modifiy it for your CPU.

/
/
/ LCD Display
/ Ver. 1.0
/ Date Aug. 2, 2008
/
/ For ref. only
/
/
/*---------------------------------------------------------------------------*/

void LcdDelay(void)
{
int data i;
for(i = 0; i < 2000; i++)
{
}
}

/*---------------------------------------------------------------------------*/

void LcdBusy(void)
{
Lcd_RS = 0;
Lcd_RW = 1;
LcdCmdPort = 0xff;
Lcd_EN = 1;
Lcd_EN = 0;
while((LcdCmdPort & 0x80) != 0)
{
Lcd_EN = 0;
Lcd_EN = 1;
}
Lcd_EN = 1;
}

/*---------------------------------------------------------------------------*/

void LcdCmd(uchar c)
{
LcdBusy();
LcdCmdPort = c;
Lcd_RS = 0;
Lcd_RW = 0;
Lcd_EN = 0;
Lcd_EN = 1;
}

/*---------------------------------------------------------------------------*/

void LcdData(uchar c)
{
LcdBusy();
LcdDataPort = c;
Lcd_RS = 1;
Lcd_RW = 0;
Lcd_EN = 0;
Lcd_EN = 1;
LcdDelay();
}

/*---------------------------------------------------------------------------*/

void LcdInit(void)
{
Lcd_RS = 1;
Lcd_RW = 1;
Lcd_EN = 1;
LcdCmd(0x38);
LcdCmd(0x38);
LcdCmd(0x06);
LcdCmd(0x0c);
LcdCmd(0x02);
}

/*---------------------------------------------------------------------------*/

void LcdXY(uchar x, uchar y)
{
if((y & 0x01) != 0)
LcdCmd(0x80 | (x - 1));
else
LcdCmd(0xc0 | (x - 1));
}

/*---------------------------------------------------------------------------*/

void LcdClr(void)
{
LcdCmd(0x01);
}

/*---------------------------------------------------------------------------*/

void LcdHex(uchar c)
{
LcdData(table[(((c & 0xf0) >> 4) & 0x0f)]);
LcdData(table[(c & 0x0f)]);
}

/*---------------------------------------------------------------------------*/\][/code]

Added after 2 minutes:


/
/ This program used for 8051 serial CPU, Just for your ref.
/
/ Date: Aug. 1, 2008
/
/
/



#include "reg52.h"
#define RS P1_0
#define RW P1_1
#define Enable P1_2
sbit P1_0=0x90;
sbit P1_1=0x91;
sbit P1_2=0x92;
void delay(void);
void InitialLCD(void);
void WriteIns(char);
void WriteData(char);
void WriteString(char,char *);
void CheckBusy(void);
/*void KeyScan(void);*/
char one=0;
char zero=0;
int KeyData=0xff;
int KeyTemp=0xff;

main()
{
char MSG0[]="0123456789";
char MSG1[]="I Love LCD";
char MSG2[]="02 AUG.,2008";
char MSG3[]="R=10K. C=10uF";
char MSG4[]="MCS-51";
char MSG5[]="01234";
char MSG6[]="56789";
char MSG7[]="ABCDE";
char MSG8[]="I Love YOU";

InitialLCD();
WriteString(13,MSG3);

/* while(1)
{
KeyScan();
if(KeyData!=0xff)
{
WriteIns(0x01);
if(KeyData==0)
WriteString(10,MSG1);
else if(KeyData==1)
WriteString(12,MSG2);
else if(KeyData==2)
WriteString(13,MSG3);
else if(KeyData==3)
WriteString(6,MSG4);
KeyData=0xff;
}
}*/
} /* main */

void InitialLCD(void)
{
WriteIns(0x38);
WriteIns(0x38);
WriteIns(0x38);
WriteIns(0x38);
WriteIns(0x08); /* off display */
WriteIns(0x01); /* clear buffer */
WriteIns(0x0e); /* on display */
WriteIns(0x06); /* set input mode */
} /* InitialLCD */

void WriteIns(char instruction)
{
RS=0;
RW=0;
Enable=1;
P2=instruction;
Enable=0;
CheckBusy();
} /* WriteIns */

void WriteData(char i)
{
RS=1;
RW=0;
Enable=1;
P2=i;
Enable=0;
CheckBusy();
} /* WriteData */

void WriteString(count,MSG)
char count;
char MSG[];
{
char i;
for(i=0;i<count;i++)
WriteData(MSG);
} /* WriteString */

void CheckBusy(void)
{
char i=0x80;
while(i&0x80)
{
RS=0;
RW=1;
Enable=1;
i=P2;
Enable=0;
delay();
}
} /* CheckBusy */

void delay(void)
{
int i;
for(i=0;i<10000;i++)
;
} /* delay */

/*void KeyScan(void)
{
char key=0;
char KeyStatus;
char KeyScanLine=0x01;
char col;
char row;
for(col=0;col<2;col++)
{
P3=~KeyScanLine;
KeyStatus=~P3;
KeyStatus>>=2;
for(row=0;row<2;row++)
{
if(KeyStatus==0x01)
{
one=0;
if(KeyTemp!=key)
{
KeyTemp=key;
zero=1;
}
else
{
zero++;
if(zero==5)
KeyData=KeyTemp;
}
}
key++;
KeyStatus>>=1;
} *//* row */
/* KeyScanLine<<=1;
} *//* col */
/*one++;
if(one==5)
{
zero=0;
KeyTemp=0xff;
KeyData=0xff;
}
}*/ /* KeyScan */
 

Hi,
thank for the information and c code.

TQ
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top