液晶顯示器(LCD)是一種常用的顯示屏,在許多電子產(chǎn)品中經(jīng)常使用它來(lái)以文本或圖像格式顯示信息。LCD用于在其屏幕上顯示字母、數(shù)字等字符。LCD顯示器由8條數(shù)據(jù)線和3條控制線組成,用于將LCD顯示器與8051單片機(jī)連接。
考慮使用基于Proteus的模擬LCD與8051單片機(jī)的接口是:
如何在LCD顯示屏上顯示“8051單片機(jī)”,案例程序如下:
#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單片機(jī)",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++);
}