#include <reg52.h>
sbit RS=P2^6;
sbit RW=P2^5;
sbit E=P2^7;
void LCD1602_init();
void LCD1602_disp(unsigned char x,unsigned y,unsigned char buf);
void LCD1602_write_adress(unsigned char x,unsigned y);
/*void LCD1602_write_dat(unsigned char datbuf);*/
void LCD1602_write_dat_busy(unsigned char datbuf);
void LCD1602_write_com(unsigned char combuf);
void LCD1602_write_com_busy(unsigned char combuf);
void LCD1602_busy();
void delay(unsigned int t);
//主函数
void main()
{
LCD1602_init(); //初始化
LCD1602_disp(0,0,'H');
LCD1602_disp(1,1,'E');
LCD1602_disp(2,0,'L');
LCD1602_disp(3,0,'L');
LCD1602_disp(4,0,'O');
LCD1602_disp(5,0,'!');
while(1)
{
}
}
//lcd显示函数
void LCD1602_disp(unsigned char x,unsigned y,unsigned char buf)
{
LCD1602_write_adress(x,y);
LCD1602_write_dat_busy(buf);
}
//lcd写地址函数
void LCD1602_write_adress(unsigned char x,unsigned y)
{
if(y==0)
LCD1602_write_com_busy(0x80+x);
else
LCD1602_write_com_busy(0xc0+x);
}
//写数据函数
/*void LCD1602_write_dat(unsigned char datbuf)
{
RS=1;
RW=0;
P0=datbuf;
E=1;
E=0;
}*/
//写数据函数带忙检测
void LCD1602_write_dat_busy(unsigned char datbuf)
{
LCD1602_busy();
RS=1;
RW=0;
P0=datbuf;
E=1;
E=0;
}
//写指令函数
void LCD1602_write_com(unsigned char combuf)
{
RS=0;
RW=0;
P0=combuf;
E=1;
E=0;
}
//写指令函数带忙检测
void LCD1602_write_com_busy(unsigned char combuf)
{
LCD1602_busy();
RS=0;
RW=0;
P0=combuf;
E=1;
E=0;
}
//读状态函数(忙检测函数)
void LCD1602_busy()
{
RS=0;
RW=1;
P0=0xff; //读前准备
E=1;
while(P0^7==0);
E=0;
}
//延时函数
void delay(unsigned int t)
{
unsigned int k;
for(k=0;k<t;k++);
}
//初始化函数
void LCD1602_init(void)
{
delay(1500); //延时15ms
LCD1602_write_com(0x38); //写指令38H 不检测忙信号
delay(500); //延时5ms
LCD1602_write_com(0x38); //写指令38H 不检测忙信号
delay(500); //延时5ms
LCD1602_write_com(0x38); //写指令38H 不检测忙信号 从该处开始,以后都需要忙检测 写地址不需要
LCD1602_write_com_busy(0x38);//写指令38H 显示模式设置
LCD1602_write_com_busy(0x08);//显示关闭
LCD1602_write_com_busy(0x01);//显示清屏
LCD1602_write_com_busy(0x06);//显示光标移动设置
LCD1602_write_com_busy(0x0c);//显示开及光标设置
}
为什么只显示打一个字符H 其他的都不显示 |