0% found this document useful (0 votes)
43 views

Program For LCD and Keyboard Interface

This program interfaces an LCD display and keyboard with a microcontroller. It initializes the LCD, defines functions to send commands and display data to the LCD. It also defines a keypad function to detect key presses and display the pressed key on the LCD. When a key is pressed, it determines the row and column and looks up the corresponding key value in a table to display on the LCD.

Uploaded by

bhushan-da-code
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

Program For LCD and Keyboard Interface

This program interfaces an LCD display and keyboard with a microcontroller. It initializes the LCD, defines functions to send commands and display data to the LCD. It also defines a keypad function to detect key presses and display the pressed key on the LCD. When a key is pressed, it determines the row and column and looks up the corresponding key value in a table to display on the LCD.

Uploaded by

bhushan-da-code
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

PROGRAM FOR LCD AND KEYBOARD INTERFACE

#include<reg52.h>

sbit rs=P0^4;

sbit w=P0^5;

sbit e=P0^6;

sbit busy=P0^3;

unsigned char g=0xC4;

void lcdinit();

void command (unsigned char );

void display (unsigned char * );

void data_display (unsigned char );

void ready();

void keypad();

void main()

unsigned char msg1[16]=" Key pressed ";

unsigned char msg3[16]= "is ";

lcdinit();

command(0x80);

display(&msg1[0]);

command(0xC0);

display(&msg3[0]);

keypad();

}
void lcdinit()

//command(0x20);

command(0x28);

command(0x08);

command(0x01);

command(0x06);

return;

void command(unsigned char com)

unsigned char i, temp;

ready();

temp=com;

com=com>>4;

P0=com;

rs=0;

w=0;

e=1;

for(i=0;i<5;i++)

{}

e=0;

temp=(temp) & (0x0F);

P0=temp;

rs=0;

w=0;
e=1;

for(i=0;i<5;i++)

{}

e=0;

return;

void display(unsigned char * ch)

while(*ch!='\0')

ready();

data_display(*ch);

ch++;

void data_display (unsigned char message)

unsigned char i, temp;

temp=message;

message=message>>4;

P0=message;

rs=1;

w=0;

e=1;

for(i=0;i<5;i++)
{}

e=0;

temp=temp & 0x0F;

P0=temp;

rs=1;

w=0;

e=1;

for(i=0;i<5;i++)

{}

e=0;

return;

void ready()

unsigned char i;

busy=1;

rs=0;

w=1;

while(busy==1)

e=0;

for(i=0;i<100;i++)

{}

e=1;

return;
}

void keypad()

unsigned char i=0, row,temprow,col,tempcol,key,key2,temp;

unsigned int k;

unsigned char msg2[16]={'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};

P1=0xFF;

P3=0x00;

temp=0xFE;

while(1)

P3=temp;

row=P3 & 0x0F;

col=P1 & 0x0F;

if(col!= 0x0F)

tempcol=col;

temprow=row;

for(k=0;k<8000;k++)

col=P1 &0x0F;

if(col==tempcol)

switch(col)

case 0x0E: key=0;

break;
case 0x0D: key=1;

break;

case 0x0B: key=2;

break;

case 0x07: key=3;

break;

key=(key*4);

switch(row)

case 0x0E: key2=0;

break;

case 0x0D: key2=1;

break;

case 0x0B: key2=2;

break;

case 0x07: key2=3;

break;

key=key+key2;

command(0x0C);

if(g==0xcf)

g=0xc3;

else

command(g);

g=g+1;

data_display(msg2[key]);
}

i++;

if(i==4)

temp=0xFE;

i=0;

else

temp=(temp<<1)+1;

You might also like