程序:
#include<reg52.h>
#define LCD_DB P0
unsigned char x,y;
sbit LCD_RS=P2^0;
sbit LCD_RW=P2^1;
sbit LCD_E=P2^2;
void delay(unsigned char n) //延时函数i=1约为1毫妙
{
unsigned char i,j;
for(i=n;i>0;i--)
for(j=0;j<110;j++);
{;}
}
void LCD_xiezhiling(unsigned char dat) //写指令函数
{
LCD_DB=dat;
LCD_RS=0;//指令
LCD_RW=0;//写入
LCD_E=1;//允许
LCD_E=0;
delay(5);
}
void LCD_chushihua() //LCD初始化函数
{
LCD_xiezhiling(0x38);//设置8位格式,2行,5x7
LCD_xiezhiling(0x0c);//整体显示,关光标,不闪烁
LCD_xiezhiling(0x06);//设定输入方式,增量不移位
LCD_xiezhiling(0x01);//清除屏幕显示
delay(10);
}
void LCD_xieshuju(unsigned char dat) //写数据函数
{
LCD_DB=dat;
LCD_RS=1;//数据
LCD_RW=0;//写入
LCD_E=1;//允许
LCD_E=0;
delay(5);
}
void LCD_zifu(unsigned char dat) //显示字符函数,data数据
{
unsigned char address;
if(y==1)
address=0x80+x;
else
address=0xc0+x;
LCD_xiezhiling(address);
LCD_xieshuju(dat);
}
void main(void)
{
unsigned char chuhao=0xFD; //chuhao是除号
LCD_chushihua();
x=0;
y=1; //x横坐标,y纵坐标
LCD_zifu(0x41);
x=3;
y=0; //x横坐标,y纵坐标
LCD_zifu(chuhao);
while(1);
}
#include<reg52.h>
#define LCD_DB P0
unsigned char x,y;
sbit LCD_RS=P2^0;
sbit LCD_RW=P2^1;
sbit LCD_E=P2^2;
void delay(unsigned char n) //延时函数i=1约为1毫妙
{
unsigned char i,j;
for(i=n;i>0;i--)
for(j=0;j<110;j++);
{;}
}
void LCD_xiezhiling(unsigned char dat) //写指令函数
{
LCD_DB=dat;
LCD_RS=0;//指令
LCD_RW=0;//写入
LCD_E=1;//允许
LCD_E=0;
delay(5);
}
void LCD_chushihua() //LCD初始化函数
{
LCD_xiezhiling(0x38);//设置8位格式,2行,5x7
LCD_xiezhiling(0x0c);//整体显示,关光标,不闪烁
LCD_xiezhiling(0x06);//设定输入方式,增量不移位
LCD_xiezhiling(0x01);//清除屏幕显示
delay(10);
}
void LCD_xieshuju(unsigned char dat) //写数据函数
{
LCD_DB=dat;
LCD_RS=1;//数据
LCD_RW=0;//写入
LCD_E=1;//允许
LCD_E=0;
delay(5);
}
void LCD_zifu(unsigned char dat) //显示字符函数,data数据
{
unsigned char address;
if(y==1)
address=0x80+x;
else
address=0xc0+x;
LCD_xiezhiling(address);
LCD_xieshuju(dat);
}
void main(void)
{
unsigned char chuhao=0xFD; //chuhao是除号
LCD_chushihua();
x=0;
y=1; //x横坐标,y纵坐标
LCD_zifu(0x41);
x=3;
y=0; //x横坐标,y纵坐标
LCD_zifu(chuhao);
while(1);
}