唯倚社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2426|回复: 5

[资源分享] 51单片机1602字符液晶滚动演示程序+仿真

[复制链接]

31

主题

123

帖子

812

积分

版主

Rank: 7Rank: 7Rank: 7

积分
812
发表于 2017-9-24 19:52:12 | 显示全部楼层 |阅读模式

轻松玩转社区

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
51单片机1602字符液晶滚动演示程序
1602程序
[C] 纯文本查看 复制代码
/***************   writer:shopping.w   ******************/
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int

sbit RS = P2^0;
sbit RW = P2^1;
sbit EN = P2^2;

void Delayms(uint ms)
{
 	uchar i;
	while(ms--)
	{
	 	for(i=0;i<120;i++);
	}
}

uchar Busy_Check()
{
 	uchar LCD_Status;
	RS = 0;
	RW = 1;
	EN = 1;
	Delayms(1);
   	LCD_Status = P0;
	EN = 0;
	return LCD_Status;
}

void Write_LCD_Command(uchar cmd)
{
 	while((Busy_Check()&0x80)==0x80);
	RS = 0;
	RW = 0;
	EN = 0;
	P0 = cmd;
	EN = 1;
	Delayms(1);
	EN = 0;
}

void Write_LCD_Data(uchar dat)
{
 	while((Busy_Check()&0x80)==0x80);
	RS = 1;
	RW = 0;
	EN = 0;
	P0 = dat;
	EN = 1;
	Delayms(1);
	EN = 0;
}

void Initialize_LCD()
{
 	Write_LCD_Command(0x38);
	Delayms(1);	
	Write_LCD_Command(0x01);
	Delayms(1);	
	Write_LCD_Command(0x06);
	Delayms(1);	
	Write_LCD_Command(0x0c);
	Delayms(1);	
}

void ShowString(uchar x,uchar y,uchar *str)
{
 	uchar i = 0;
	if(y == 0)
		Write_LCD_Command(0x80 | x);
	if(y == 1)
		Write_LCD_Command(0xc0 | x);
	for(i=0;i<16;i++)
	{
	 	Write_LCD_Data(str[i]);	
	}
}



主程序
[C] 纯文本查看 复制代码
/***************   writer:shopping.w   ******************/
#include <reg52.h>
#include <string.h>
#define uchar unsigned char
#define uint unsigned int
void Initialize_LCD();
void ShowString(uchar,uchar,uchar *);
sbit K1 = P3^0;
sbit K2 = P3^1;
sbit K3 = P3^2;

uchar code Prompt[]="PRESS K1--K4 TO START DEMO PROG";
uchar const Line_Count = 6;
uchar code Msg[][80]=
{
 	"Many CAD users dismiss",
	"process of creating PCB",
	"of view.with PCB layout",
	"placement and track routing,",
	"can often be the most time",
	"And if you use circuit simulation",
	"you are going to spend even more"
};
uchar Disp_Buffer[32];
void Delayxms(uint ms)
{
 	uchar i;
	while(ms--)
	{
	 	for(i=0;i<120;i++);
	}
}

void V_Scroll_Display()
{
 	uchar i,j,k = 0;
	uchar *p = Msg[0];
	uchar *q = Msg[Line_Count] + strlen(Msg[Line_Count]);
	while(p<q)
	{
	 	for(i=0;(i<16)&&(p<q);i++)
		{
		 	if(((i==0)||(i==15))&& *p == ' ')
				p++;
			if(*p != '\0')
			{
			 	Disp_Buffer[i] = *p++;
			}
			else
			{
			 	if(++k>Line_Count)
					break;
				p = Msg[k];
				Disp_Buffer[i] = *p++;
			}
		}
		for(j=i;j<16;j++)
			Disp_Buffer[j]=' ';
		while(F0)
			Delayxms(5);
		ShowString(0,0,"      ");
		Delayxms(150);
		while(F0)
			Delayxms(5);
		ShowString(0,1,Disp_Buffer);
		Delayxms(150);
		while(F0)
			Delayxms(5);
		ShowString(0,0,Disp_Buffer);
		ShowString(0,1,"      ");
		Delayxms(150);	
	}
	ShowString(0,0,"         ");
	ShowString(0,1,"         ");
}

void H_Scroll_Display()
{
	uchar m,n,t = 0,L=0;
	uchar *p = Msg[0];
	uchar *q = Msg[Line_Count] + strlen(Msg[Line_Count]);
	for(m=0;m<16;m++)
			Disp_Buffer[m]=' ';	
	while(p<q)
	{
	 	if((m=16||m==31)&& *p == ' ')
			p++;
		for(m=16;m<32&&p<q;m++)
		{
		 	if(*p != '\0')
			{
				Disp_Buffer[m] = *p++; 	
			}
			else
			{
			 	if(++t>Line_Count)
					break;
				p = Msg[t];
				Disp_Buffer[m] = *p++;
			}
		}
		for(n=m;n<32;n++)
			Disp_Buffer[n]=' ';
		for(m=0;m<=16;m++)
		{
		 	while(F0)
		 		Delayxms(5);
		   	ShowString(0,L,Disp_Buffer+1);
		   	while(F0)
		 		Delayxms(5);
			Delayxms(20);
		}
		L = (L==0)? 1:0;
		Delayxms(200);
	}
	if(L==1)
		ShowString(0,1,"      ");	
}

void EX_INT0() interrupt 0
{
 	F0 = !F0;
}

void main()
{
 	uint Count = 0;
	IE = 0x81;
	IT0 = 1;
	F0  = 0;
	Initialize_LCD();
	ShowString(0,0,Prompt);
	ShowString(0,1,Prompt+16);
	while(1)
	{
	 	if(K1 == 0)
		{
		 	V_Scroll_Display();
			Delayxms(200);
		}
		else if(K2 == 0)
		{
		 	H_Scroll_Display();
			Delayxms(200);	
		}
	}
}



仿真图


1.png





code.zip

49.61 KB, 下载次数: 0, 下载积分: E币 -1

评分

参与人数 1E币 +2 收起 理由
admin + 2 感谢对论坛的支持!

查看全部评分

[发帖际遇]: 渣哥_小白 乐于助人,奖励 7 贡献. 幸运榜 / 衰神榜

0

主题

75

帖子

249

积分

版主

Rank: 7Rank: 7Rank: 7

积分
249
发表于 2017-9-25 20:00:37 | 显示全部楼层
负分拿好,不送,滚粗
回复

使用道具 举报

3

主题

89

帖子

184

积分

版主

Rank: 7Rank: 7Rank: 7

积分
184
发表于 2017-9-25 20:57:12 | 显示全部楼层
无论是多么无聊的帖子我都会去的
回复

使用道具 举报

1

主题

76

帖子

79

积分

版主

Rank: 7Rank: 7Rank: 7

积分
79
发表于 2017-9-25 22:31:42 | 显示全部楼层
伪前排
回复

使用道具 举报

0

主题

75

帖子

249

积分

版主

Rank: 7Rank: 7Rank: 7

积分
249
发表于 2017-9-25 22:40:55 | 显示全部楼层
如果你智商能再高点,也许我会上当
回复

使用道具 举报

*滑动验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|weiecn ( 湘ICP备14002058号 )

GMT+8, 2019-6-19 03:37 , Processed in 0.059860 second(s), 11 queries , Redis On.

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表