lcd keypad 8051
I will send the LCD KEybaord Routine use this for ur project . Remaing KEybaoard routine i ll send later.
U finish this lCD interface first and let me know
Added after 48 minutes:
#include <AT89c51.H> // Sfr defination header provided by keil in your case it may be #include <REG8252.H>
#include<intrins.h> // For defination of NOP function.
/*------------------------------------------------
LCD signals and data definations
------------------------------------------------*/
sfr LCDDATA = 0xA0; // P2 defined as LCD Data
sbit RS = 0XB4; // P3.4 as RS line of LCD
sbit RW = 0XB5; // P3.5 as R/W line of LCD
sbit EN = 0XB6; // P3.5 as EN line of LCD
void waitLCD(void)
{
unsigned char a, ACC;
for(a=0;a<255;a++)
{
EN = 0;
RS = 0;
RW = 1;
LCDDATA = 0Xff;
_nop_();
_nop_();
EN = 1;
ACC = LCDDATA;
ACC = ACC & 0X80;
if(ACC==0)
break;
}
EN = 0;
RW = 0;
}
void ClearDisplay()
{
EN = 1;
RS = 0;
LCDDATA = 0X01;
EN = 0;
waitLCD();
}
void WriteLCDCmd(char c)//reentrant
{
EN = 1;
RS = 0;
LCDDATA = c;
EN = 0;
waitLCD();
}
void WriteLCDData(char c, char Pos)
{
if(Pos < 16)
WriteLCDCmd(Pos | 0x80);
else
WriteLCDCmd((Pos-16) | 0xC0);
EN = 1;
RS = 1;
LCDDATA = c;
EN = 0;
waitLCD();
}
/*------------------------------------------------
LCD Commands Table
--------------------------------------------------
1 Clear display screen
2 Return Home
4 Decrement cursor (Shift cursor to left)
6 Increment cursor (Shift cursor to right)
5 Shift display right
7 Shift display left
8 Display off, cursor off
A Display off, cursor on
C Display on, cursor off
E Display on, cursor blinking
F Display on, cursor blinking
10 Shift cursor position to left
14 Shift cursor position to right
18 Shift the entire display to the left
1C Shift the entire display to the right
80 Force cursor position to beginning of 1st line
C0 Force cursor position to beginning of 2nd line
38 2 lines and 5X7 matrix.*/
void Initialize_LCD()
{
unsigned char i;
i = 0X38; // For 8 bit communication and 16X2 type.
WriteLCDCmd(i);
i = 0X0E; // For turning LCD ON and set cursor position.
WriteLCDCmd(i);
i = 0X06; // For incrementing cursor position automatically.
WriteLCDCmd(i);
i = 0X0C; // For Cursor off.
WriteLCDCmd(i);
void main()
{
unsigned char i = 0, My_name[] = "RAVI", prog[] = "LCD Interface" ;
unsigned int x = 0;
Initialize_LCD(); // Initialise the LCD display.
ClearDisplay(); // Clear LCD display.
for(i = 0; i < 28; i++)
WriteLCDData(prog,i); // Write Name on LCD
for(x=0 ; x<30000; x++); // simple delay of 1 sec for 12 Mhz crystal.
ClearDisplay(); // Clear LCD display.
for(i = 0; i < 6; i++)
WriteLCDData(My_name,i); // Write Name on LCD
while(1); // Infinite loop
}