Toll-Free Customer Support 24/7

#include<reg51.h>

sbit D7=P2^7;
sbit D6=P2^6;
sbit D5=P2^5;
sbit D4=P2^4;

sbit rs=P2^0; /* Register select pin */
sbit en=P2^1; /* Enable pin */

#define KeyPort P0
unsigned char check();
unsigned int LCD_Port;
void delay12(unsigned int time);
/* Function to provide delay Approx 1ms with 11.0592 Mhz crystal*/
void delay(unsigned int count)
{
int i,j;
for(i=0;i<count;i++)
for(j=0;j<112;j++);
}

void LCD_Command (char cmnd) /* LCD16x2 command funtion */
{
LCD_Port = (cmnd & 0xF0)>>4;/* Send upper nibble */
D7=LCD_Port&0X08;
D6=LCD_Port&0X04;
D5=LCD_Port&0X02;
D4=LCD_Port&0X01;
rs=0; /* Command reg. */
// rw=0; /* Write operation */
en=1;
delay(1);
en=0;
delay(2);

LCD_Port = (cmnd & 0x0F);/* Send lower nibble */
D7=LCD_Port&0X08;
D6=LCD_Port&0X04;
D5=LCD_Port&0X02;
D4=LCD_Port&0X01;
rs=0;
en=1; /* Enable pulse */
delay(1);
en=0;
delay(5);
}

void LCD_Char (char char_data) /* LCD data write function */
{
LCD_Port =(char_data & 0xF0)>>4;/* Send upper nibble */
D7=LCD_Port&0X08;
D6=LCD_Port&0X04;
D5=LCD_Port&0X02;
D4=LCD_Port&0X01;
rs=1; /*Data reg.*/
// rw=0; /*Write operation*/
en=1;
delay(1);
en=0;
delay(2);

LCD_Port = (char_data & 0x0F);/* Send lower nibble */
D7=LCD_Port&0X08;
D6=LCD_Port&0X04;
D5=LCD_Port&0X02;
D4=LCD_Port&0X01;
en=1; /* Enable pulse */
delay(1);
en=0;
delay(5);

}

void LCD_String (char *str) /* Send string to LCD function */
{
int i;
for(i=0;str[i]!=0;i++) /* Send each char of string till the NULL */
{
LCD_Char (str[i]); /* Call LCD data write */
}
}

void LCD_String_xy (char row, char pos, char *str) /* Send string to LCD function */
{
if (row == 0)
LCD_Command((pos & 0x0F)|0x80);
else if (row == 1)
LCD_Command((pos & 0x0F)|0xC0);
LCD_String(str); /* Call LCD string function */
}

void LCD_Init (void) /* LCD Initialize function */
{
delay(20); /* LCD Power ON Initialization time >15ms */
LCD_Command (0x02); /* 4bit mode */
LCD_Command (0x28); /* Initialization of 16X2 LCD in 4bit mode */
LCD_Command (0x0C); /* Display ON Cursor OFF */
LCD_Command (0x06); /* Auto Increment cursor */
LCD_Command (0x01); /* clear display */
LCD_Command (0x80); /* cursor at home position */
}

void main()
{
unsigned char VALUE=0;
LCD_Init(); /* Initialization of LCD*/
LCD_String("RDL TECHOLOGIES"); /* write string on 1st line of LCD*/
LCD_Command(0xC0); /* Go to 2nd line*/

while(1) /* Infinite loop. */
{
VALUE=check();
LCD_Char(VALUE);
}
}

unsigned char check()
{
unsigned char colloc=0,rowloc=0, colloc1,rowloc1;
unsigned char keypad[4][4]={'1','5','9','C',
'2','6','0','D',
'3','7','A','E',
'4','8','B','F'};

{

do
{
KeyPort = 0X0f;
do
{
colloc1 = KeyPort;
colloc1 &= 0x0F;
}while(colloc1 != 0x0F);

delay12(20);

do
{
colloc1=KeyPort;
colloc1 &= 0x0F;
}while(colloc1==0x0F);


delay12(20);

KeyPort = 0x0f;
colloc1=KeyPort;
colloc1 &= 0x0F;
if(colloc1==0x0E)
{
colloc=0;
}
else if(colloc1==0x0D)
{
colloc=1;
}
else if(colloc1==0x0B)
{
colloc=2;
}
else if(colloc1==0x07)
{
colloc=3;
}
KeyPort = 0xf0;
rowloc1 = KeyPort;
rowloc1 &= 0xf0;
if(rowloc1 == 0xE0)
{
rowloc=0;
}

else if(rowloc1==0xD0)
{
rowloc=1;
}
else if(rowloc1==0xB0)
{
rowloc=2;
}
else if(rowloc1==0x70)
{
rowloc=3;
}
// CMD_WRT(0XC0);
// DATA_WRT(keypad[rowloc][colloc]);

return(keypad[rowloc][colloc]);

}while(1);
}
}

void delay12(unsigned int time)
{
unsigned int i;
for(i=0;i<time;i++);
for(i=0;i<10000;i++);
}

Back to top