51单片机lcd1602液晶显示中文烟花易冷程序
时间: 2023-10-16 21:06:36 浏览: 109
51单片机LCD1602滚动显示
5星 · 资源好评率100%
以下是51单片机LCD1602液晶显示中文烟花易冷程序,供参考:
```
#include <reg51.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit RS = P2^6;
sbit RW = P2^5;
sbit EN = P2^7;
uchar code tab[] = {" 烟花易冷 "};
uchar code tab1[] = {" By: Luba96 "};
uchar code tab2[] = {" 2021.3.25 "};
uchar code tab3[] = {" * "};
uchar code tab4[] = {" *** "};
uchar code tab5[] = {" ***** "};
uchar code tab6[] = {" ******* "};
uchar code tab7[] = {" ***** "};
uchar code tab8[] = {" * "};
void delay(uint xms)
{
uint i, j;
for (i = xms; i > 0; i--)
for (j = 112; j > 0; j--);
}
void write_com(uchar com)
{
RW = 0;
RS = 0;
P0 = com;
EN = 1;
_nop_();
EN = 0;
}
void write_data(uchar date)
{
RW = 0;
RS = 1;
P0 = date;
EN = 1;
_nop_();
EN = 0;
}
void init()
{
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
}
void main()
{
uchar i;
init();
write_com(0x80+0x40);
for (i = 0; i < 16; i++)
write_data(tab3[i]);
write_com(0x80+0x00);
for (i = 0; i < 16; i++)
write_data(tab4[i]);
write_com(0x80+0x40+0x01);
for (i = 0; i < 16; i++)
write_data(tab5[i]);
write_com(0x80+0x00+0x01);
for (i = 0; i < 16; i++)
write_data(tab6[i]);
write_com(0x80+0x40+0x02);
for (i = 0; i < 16; i++)
write_data(tab7[i]);
write_com(0x80+0x00+0x02);
for (i = 0; i < 16; i++)
write_data(tab8[i]);
write_com(0x80+0x00+0x0f);
while (1)
{
write_com(0x80+0x00+0x0f);
for (i = 0; i < 16; i++)
write_data(tab[i]);
write_com(0x80+0x40+0x0f);
for (i = 0; i < 16; i++)
write_data(tab1[i]);
delay(500);
write_com(0x80+0x00);
for (i = 0; i < 16; i++)
write_data(' ');
write_com(0x80+0x40);
for (i = 0; i < 16; i++)
write_data(' ');
delay(500);
}
}
```
程序的主要功能是在LCD1602液晶屏上显示一个中文“烟花易冷”和作者信息“By: Luba96 2021.3.25”,同时还有一个烟花图案在液晶屏上闪烁。程序中使用了51单片机的GPIO控制LCD1602液晶屏的显示,并且通过延时函数控制烟花图案的闪烁。
阅读全文