/*注:4 X4矩阵接P3口*/
#include
#include
#include
#define uchar unsigned char
#define uint unsigned int
#define CHECK_BUSY
sbit RS = P2^4;
sbit RW = P2^5;
sbit EN = P2^6;
void DelayMs(int z)
{
int x,y;
for (x=z;x>0;x–)
for(y=110;y>0;y–);
}
/***********判忙函数***********/
bit LCD_Check_Busy()
{
#ifdef CHECK_BUSY
P0= 0xFF;
RS=0;
RW=1;
EN=0;
_nop_();
EN=1;
return (bit)(P0 & 0x80);
#else
return 0;
#endif
}
/***********写入指令函数***********/
void write_com(uchar com)
{
while(LCD_Check_Busy()); //忙则等候
RS=0;
RW=0;
EN=1;
P0= com;
_nop_();
EN=0;
}
/**********写入数据函数**********/
void write_dat(uchar dat)
{
while(LCD_Check_Busy()); //忙则等候
RS=1;
RW=0;
EN=1;
P0= dat;
_nop_();
EN=0;
}
/*******写入字符函数***********/
void LCD_Write_Char(uchar x,uchar y,uchar dat)
{
if (y == 0)
{
write_com(0x80 + x);
}
else
{
write_com(0xC0 + x);
}
write_dat( dat);
}
/******写入字符串函数***********/
void Write_String(uchar x,uchar y,uchar *s)
{
while (*s)
{
LCD_Write_Char(x,y,*s);
s++;
x++;
}
}
/*****初始化函数******/
void LCD_Init()
{
write_com(0x38); /*显现形式设置*/
DelayMs(5);
write_com(0x06);/*显现光标移动设置*/
DelayMs(5);
write_com(0x0C); /*显现开及光标设置*/
write_com(0x01); /*显现清屏*/
}