求LCD1602显示生日快乐四个汉字的程序,单片机用AT89S52的,谢啦~
4个回答
展开全部
/*LCD 1602生成两行字,分别是:"Believe yourself!"和"Happybirthy to you!"并作向左循环移动!*/
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table1[]="Believe yourself!";
uchar code table2[]="Happybirthy to you!";
sbit RS=P1^0;
sbit RW=P1^1;
sbit E=P1^2;
void delay(uint ms)
{
uint n;
for(;ms>0;ms--)
for(n=124;n>0;n--);
}
/*写指令*/
void write_Instruction(uchar Instruction)
{
RS=0;
RW=0;
E=0;
P0=Instruction;
delay(5);
E=1;
delay(5);
E=0;
}
/*写数据*/
void write_Data(uchar Data)
{
RS=1;
RW=0;
E=0;
P0=Data;
delay(5);
E=1;
delay(5);
E=0;
}
/*初始化*/
void Init()
{
delay(15);
write_Instruction(0x38);
delay(5);
write_Instruction(0x38);
delay(5);
write_Instruction(0x38);
delay(5);
write_Instruction(0x38);
write_Instruction(0x38);
write_Instruction(0x08);
write_Instruction(0x01);
write_Instruction(0x06);
write_Instruction(0x0c);
}
void left_move()
{
uchar i;
for(i=0;i<16;i++)
{
write_Instruction(0x18);
delay(3000);
}
}
void main()
{
uchar i;
Init();
while(1)
{
write_Instruction(0x80);
for(i=0;i<16;i++)
{
write_Data(table1[i]);
delay(1);
}
write_Instruction(0x80+0x40);
for(i=0;i<19;i++)
{
write_Data(table2[i]);
delay(1);
}
left_move();
}
}
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table1[]="Believe yourself!";
uchar code table2[]="Happybirthy to you!";
sbit RS=P1^0;
sbit RW=P1^1;
sbit E=P1^2;
void delay(uint ms)
{
uint n;
for(;ms>0;ms--)
for(n=124;n>0;n--);
}
/*写指令*/
void write_Instruction(uchar Instruction)
{
RS=0;
RW=0;
E=0;
P0=Instruction;
delay(5);
E=1;
delay(5);
E=0;
}
/*写数据*/
void write_Data(uchar Data)
{
RS=1;
RW=0;
E=0;
P0=Data;
delay(5);
E=1;
delay(5);
E=0;
}
/*初始化*/
void Init()
{
delay(15);
write_Instruction(0x38);
delay(5);
write_Instruction(0x38);
delay(5);
write_Instruction(0x38);
delay(5);
write_Instruction(0x38);
write_Instruction(0x38);
write_Instruction(0x08);
write_Instruction(0x01);
write_Instruction(0x06);
write_Instruction(0x0c);
}
void left_move()
{
uchar i;
for(i=0;i<16;i++)
{
write_Instruction(0x18);
delay(3000);
}
}
void main()
{
uchar i;
Init();
while(1)
{
write_Instruction(0x80);
for(i=0;i<16;i++)
{
write_Data(table1[i]);
delay(1);
}
write_Instruction(0x80+0x40);
for(i=0;i<19;i++)
{
write_Data(table2[i]);
delay(1);
}
left_move();
}
}
展开全部
(因为你没有说想怎样显示‘生日快乐!’,所以我给你编写的是这些字向右循环移动,你也可以编写,闪烁的,循环左移的)
在LCD中,一次只能写入一个字符,所以,你先建立一个字符串数组:
unsigned char code string[]={"生日快乐!"}
然后再设置一个循环,从第一个数组元素开始写入LCD,直到写到字符串的结束标志‘\0’为止,程序如下:
unsigned char i;
i=0;
while(string[i]!='\0')
{
WriteData (string[i]);
i++;
delay (150);
}
在LCD中,一次只能写入一个字符,所以,你先建立一个字符串数组:
unsigned char code string[]={"生日快乐!"}
然后再设置一个循环,从第一个数组元素开始写入LCD,直到写到字符串的结束标志‘\0’为止,程序如下:
unsigned char i;
i=0;
while(string[i]!='\0')
{
WriteData (string[i]);
i++;
delay (150);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
太强悍了,1602可以显示汉字么?另外,1602是显示双排的,哪怕用符号来显示,也不可能完成生日快乐的正确显示,建议采用12832或者12864屏幕显示,要么就是采用1602显示英文“HAPPY BIRTHDAY TO YOU”倒是可以的。
追问
那能帮我编一段显示HAPPY BIRTHDAY TO YOU的程序么,多谢~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
2楼说的对。1楼不要忽悠楼主了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询