#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit RS=P2^2;
sbit RW=P2^3;
sbit E=P2^4;
//Delay Function
void Delay_Ms(uint ms)
{
uchar t;
while(ms--)
for(t=0;t<120;t++);
}
//Busy Checking Function
uchar Busy_Check()
{
uchar lcd_status;
RS=0;
RW=1;
E=1;
Delay_Ms(1);
lcd_status=P0;
E=0;
return lcd_status;
}
//Write LCD Command Function
void Write_LCD_Command(uchar cmd)
{
while((Busy_Check()&0x80)==0x80); //busy! wait!!!
RS=0;
RW=0;
E=0;
P0=cmd;
E=1;
Delay_Ms(1);
E=0;
}
//Write LCD Data Function
void Write_LCD_Data(uchar dat)
{
while((Busy_Check()&0x80)==0x80); //busy! wait!!!
RS=1;
RW=0;
E=0;
P0=dat;
E=1;
Delay_Ms(1);
E=0;
}
//LCD Initialize Funtion
void Initialize_LCD()
{
Write_LCD_Command(0x38);
Delay_Ms(1);
Write_LCD_Command(0x01);
Delay_Ms(1);
Write_LCD_Command(0x06);
Delay_Ms(1);
Write_LCD_Command(0x0c);
Delay_Ms(1);
}
//Display String Function
void Display_String(uchar x,uchar y,uchar *str)
{
uchar i=0;
if(y==0) //setting display char start
Write_LCD_Command(0x80|x);
if(y==1)
Write_LCD_Command(0xc0|x);
for(i=0;(i<16)&&(str!='\0');i++)
{
Write_LCD_Data(str);
}
}