51单片机LCD1602两行移动显示

实现51单片机LCD1602两行移动显示

第一行:My name is Eagal

第二行:Music film Games

#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit lcden=P3^4;
sbit rs=P3^5;
sbit rw=P3^6;	
sbit dula=P2^6;
sbit wela=P2^7;
uchar table1[]="My name is Eagal";
uchar table2[]=" Music Flim Games ";
void delay(uint x)
{
	uint a,b;
	for(a=x;a>0;a--)
		for(b=10;b>0;b--); 
}

void write_com(uchar com)
{
	P0=com;
	rs=0;
	lcden=0;
	delay(10);
	lcden=1;
	delay(10);
	lcden=0;
	
}

void write_date(uchar date)
{
	P0=date;
	rs=1;
	lcden=0;
	delay(10);
	lcden=1;
	delay(10);
	lcden=0;
	
}

void init()
{
    rw=0;
	dula=0;
	wela=0;
	write_com(0x38);   //显示模式设置:16×2显示,5×7点阵,8位数据接口
	delay(20);
	write_com(0x0c);   //显示模式设置
	delay(20);
	write_com(0x06);   //显示模式设置:无光标
	delay(20);
	write_com(0x01);   //清屏幕指令,将以前的显示内容清除
	delay(20);	
}

void main()
{	uint k=1000;
	uchar *pa,*pb;
	init();

	write_com(0x80 | 0x0f);	 //将第一个字符写在向右偏移17个字符处,为后面的由右向左划入做准备。
	delay(20);
		pa = table1;
		while(*pa != '\0')
		{
			write_date(*pa++);
			while(k--);
		}

	write_com(0x07); 
	write_com(0x80 | 0x4f);
//	delay(50);
	pb = table2;
		while(*pb != '\0')
		{
			write_date(*pb++);
			while(k--);
		}	
	//while(1);
}

上一篇:基于单片机智能视力保护台灯控制系统设计-毕设课设


下一篇:426【毕设课设】基于51单片机红外遥控定时开关智能家电家居插座