液晶显示器(LCD)是一种常用的显示屏,在许多电子产品中经常使用它来以文本或图像格式显示信息。LCD用于在其屏幕上显示字母、数字等字符。LCD显示器由8条数据线和3条控制线组成,用于将LCD显示器与8051单片机连接。
考虑使用基于Proteus的模拟LCD与8051单片机的接口是:
如何在LCD显示屏上显示“8051单片机”,案例程序如下:
#include< reg51.h >
#define kam P0
void lcd_initi();
void lcd_dat(unsigned char );
void lcd_cmd(unsigned char );
void delay();
void display(unsigned char *s, unsigned char r)
sbit rs=P2^0;
sbit rw=P2^1;
sbit en=P2^2;
void main()
{
lcd_initi();
lcd_cmd(0x80);
delay(100);
lcd_cmd(0xc0);
display("8051单片机",10);
while(1);
}
void display(unsigned char *s, unsigned char r)
{
unsignedint w;
for(w=0;w< r;w++)
{
lcd_data(s[w]);
}
}
voidlcd_initi()
{
lcd_cmd(0x01);
delay(100);
lcd_cmd(0x38);
delay(100);
lcd_cmd(0x06);
delay(100);
lcd_cmd(0x0c);
delay(100);
}
voidlcd_dat(unsigned char dat)
{
kam = dat;
rs=1;
rw=0;
en=1;
delay(100);
en=0;
}
}
voidlcd_cmd(unsigned char cmd)
{
kam=cmd;
rs=0;
rw=0;
en=1;
delay(100);
en=0;
}
void delay( unsigned int n)
{
unsignedint a;
for(a=0;a< n;a++);
}