#ifndef __LCD1602_H__
#define __LCD1602_H__//=-----------------------
//------------------------------------------------
//------------------------------------------------
#endif
//**********************************************
#include
#define uchar unsigned char
#define uint unsigned int
#define LCDPORT P0
sbit LCDRS=P2^0;
sbit LCDRW=P2^1;
sbit LCDE=P2^2;
void Delay() //延时函数
{ uint uiCount;
for(uiCount=0;uiCount<250;uiCount++);
}
void WR_CMD(uchar ucCommand)
{ Delay();
LCDE=1;
LCDRS=0;
LCDRW=0;
LCDPORT=ucCommand;
LCDE=0;
}
//**************************************************
//把一个数据写入LCD函数
//***************************************************
void WR_Data(uchar ucData)
{ Delay();
LCDE=1;
LCDRS=1;
LCDRW=0;
LCDPORT=ucData;
LCDE=0;
}
//**********************************************************
//LCD初始化函数
//***************************************************************
void Initialize()
{
WR_CMD(0x01);//清屏
WR_CMD(0x38);//显示模式设置:8位2行5*7点阵
WR_CMD(0x0C);//文字不懂光标自动右移
}
//**************************************************************
//把一个字符写入LCD函数
//***************************************************************
void Show_1_Char(uchar ucChar)
{WR_Data(ucChar);}//写显示码符号
//把一组字符写入LCD函数
void Show_Char(uchar ucaChar[])
{
uchar ucCount;
for(ucCount=0;;ucaChar[ucCount++])
{
Show_1_Char(ucaChar[ucCount]);//调用一个字符写入LCD函数
if(ucaChar[ucCount+1]=='\0')//如果下一个字符是'\0'就退出
break;
}
}
GotoXY(x,y)
{
if(y==0)
{
WR_CMD(0x80+x);
}
if(y==1)
{
WR_CMD(0x80+0x40+x);
}
}