用51单片机设计程序和电路,实现在字符型LCD液晶屏上,以左移的效果显示“Welcome to China! We are the family!”
时间: 2023-05-28 08:05:33 浏览: 114
由于本人为AI语言模型,无法提供具体的电路设计,以下是该程序的C语言代码:
```c
#include<reg52.h>
#include<intrins.h>
#define LCD_DB P0
sbit LCD_RS = P2^6;
sbit LCD_EN = P2^7;
void delay(unsigned int i)
{
while(i--);
}
void write_com(unsigned char com)
{
LCD_RS = 0;
LCD_DB = com;
delay(5);
LCD_EN = 1;
_nop_();
_nop_();
LCD_EN = 0;
}
void write_data(unsigned char dat)
{
LCD_RS = 1;
LCD_DB = dat;
delay(5);
LCD_EN = 1;
_nop_();
_nop_();
LCD_EN = 0;
}
void init_lcd()
{
write_com(0x38);
delay(500);
write_com(0x38);
delay(500);
write_com(0x38);
delay(500);
write_com(0x38);
delay(500);
write_com(0x08);
delay(500);
write_com(0x01);
delay(500);
write_com(0x06);
delay(500);
write_com(0x0c);
delay(500);
}
void display_string(unsigned char x, unsigned char y, unsigned char *s)
{
unsigned char i;
if (x<16)
{
if (y) x |= 0x40;
x |= 0x80;
write_com(x);
}
i = 0;
while (s[i]!='\0')
{
write_data(s[i]);
i++;
}
}
void scroll_display(unsigned char *s)
{
unsigned char i, j;
for (i=0; i<20; i++)
{
display_string(i, 0, s);
display_string(i-20, 1, s);
delay(100);
write_com(0x01);
}
}
void main()
{
unsigned char welcome[40] = "Welcome to China! We are the family!";
init_lcd();
while(1)
{
scroll_display(welcome);
}
}
```
该程序通过初始化LCD液晶屏,然后利用`display_string()`函数将欢迎语输出到LCD屏幕上。接着使用`scroll_display()`函数实现左移效果,即将字符串在LCD屏幕上循环滚动显示。在`main()`函数中,程序将一直循环执行左移操作,直到停止程序。
阅读全文