写一个LCD1602程序,显示“Hello world!”
#include<reg51.h>
#define uchar unsigned char
uchar code Zimu[]="Hello world!";
sbit Lcd_RS=P1^0;
sbit Lcd_RW=P1^1;
sbit Lcd_EN=P1^2;
sbit Lcd_Busy=P1^3;
#define Lcd_Data=P0;
void Lcd_Set_Posi
tion(uchar position);//设置显示位置
void Lcd_Init(void);//液晶初始化
void Lcd_Write_Com(uchar command);//写命令
void Lcd_Write_Data(uchar data)//写数据
void Lcd_Display(uchar *P);
void main()
{
Lcd_Inti();
Lcd_Set_Position(0x40);
Lcd_Display( Zimu);
while(1);
}
void Lcd_Set_Position(uchar position)//设置显示位置
{
Lcd_Write_Com(0x80+position);
}
void Lcd_Init(void)//液晶初始化
{
Lcd_Write_Com(0x38); //设置显示模式
Lcd_Write_Com(0x0c); //开显示不显示光标,光标不闪烁
Lcd_Write_Com(0x06); //写一个指针加1
Lcd_Write_Com(0x01); //清屏
Lcd_Write_Com(0x80); //设置数据指针
}
void Lcd_Write_Com(uchar command)//写命令
{
Lcd_Check_Busy();
Lcd_RS=0;
Lcd_RW=0;
Lcd_Data=command;
Lcd_EN=1;
Lcd_EN=0;
}
void Lcd_Check_Busy(void)//查询忙碌
{
while(1)
{
Lcd_EN=0;
Lcd_RS=0;
Lcd_RW=1;
Lcd_EN=1;
if(Lcd_Busy==0)break;
Lcd_EN=0;
}
}
void Lcd_Write_Data(uchar data)//写数据
{
Lcd_Check_Busy();
Lcd_RS=1;
Lcd_RW=0;
Lcd_Data=data;
Lcd_EN=1;
Lcd_EN=0;
}
void Lcd_Display(uchar * P)//字符串显示子程序
{
uchar i,temp;
i=0;
while(1)
{
temp=P
;
Lcd_Write_Data(temp);
i++;
if(temp==' ')
break;
}
}
眼尖!改了,不过还是有错误
一周热门 更多>