⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 diceng1602.h

📁 17869333sensor.rar
💻 H
字号:
#define uchar unsigned char
#define uint  unsigned int


#include "reg52.h"
#include "intrins.h"

sbit	RS	=	P2^7;
sbit	RW	=	P2^6;
sbit	E	=	P2^5;

#define DPORT	P0

const uchar NoDisp=0;		//无显示
const uchar NoCur=1;		//有显示无光标
const uchar CurNoFlash=2;	//有光标但不闪烁
const uchar CurFlash=3;		//有光标且闪烁

void LcdPos(uchar,uchar);	//确定光标位置
void LcdWd(uchar);			//写字符
void LcdWc(uchar);			//送控制字(检测忙信号)
void LcdWcn(uchar );		//送控制字子程序(不检测忙信号)
void mDelay(uchar );		//延时,毫秒数由j决定
void WaitIdle();			//正常读写操作之前检测LCD控制器状态

//在指定的行与列显示指定的字符,xpos:行,ypos:列,c:待显示字符
void WriteChar(uchar c,uchar xPos,uchar yPos)
{	LcdPos(xPos,yPos);
    LcdWd(c);
}

void WriteString(uchar *s,uchar xPos,uchar yPos)
{	uchar i;
	if(*s==0)		//遇到字符串结束
		return;	
	for(i=0;;i++)
	{	
		if(*(s+i)==0)
			break;
		WriteChar(*(s+i),xPos,yPos);
		xPos++;
		if(xPos>=15)	//如果XPOS中的值未到15(可显示的最多位)
			break;

	}
}
void SetCur(uchar Para)	//设置光标
{	mDelay(2);
	switch(Para)
	{	case 0:
		{	LcdWc(0x08);	//关显示
			break;
		}
		case 1:
		{	LcdWc(0x0c);	//开显示但无光标
			break;
		}
		case 2:
		{	LcdWc(0x0e);	//开显示有光标但不闪烁
			break;
		}
		case 3:
		{	LcdWc(0x0f);	//开显示有光标且闪烁
			break;
		}
		default:
			break;
	}
}

void ClrLcd()	//清屏命令
{	LcdWc(0x01);
}			

//	正常读写操作之前检测LCD控制器状态
void WaitIdle()
{	uchar tmp;
	RS=0;
	RW=1;
	E=1;
	_nop_();
	for(;;)
	{	tmp=DPORT;	
		tmp&=0x80;
		if(	tmp==0)
			break;
	}
	E=0;
}

void LcdWd(uchar c)		//写字符子程序
{	WaitIdle();
	RS=1;	
	RW=0;
	DPORT=c;			//将待写数据送到数据端口
	E=1;
	_nop_();
	_nop_();
	E=0;
}
void LcdWc(uchar c)		//送控制字子程序(检测忙信号)
{	WaitIdle();	
	LcdWcn(c);
}

void LcdWcn(uchar c)	//送控制字子程序(不检测忙信号)
{	RS=0;
	RW=0;
	DPORT=c;
	E=1;
	_nop_();
	E=0;
}
void LcdPos(uchar xPos,uchar yPos)	//设置第(xPos,yPos)个字符的DDRAM地址
{	unsigned char tmp;
	xPos&=0x0f;		//x位置范围是0~15
	yPos&=0x01;		//y位置范围是0~1
	if(yPos==0)		//显示第一行
		tmp=xPos;
	else
		tmp=xPos+0x40;
	tmp|=0x80;
	LcdWc(tmp);
}
void RstLcd()		//复位LCD控制器
{	mDelay(15);		//如果使用12M或以下晶振,此数值不必改,如用24M晶振,须用30
	LcdWc(0x38);	//显示模式设置
	LcdWc(0x08);	//显示关闭
	LcdWc(0x01);	//显示清屏
	LcdWc(0x06);	//显示光标移动位置
	LcdWc(0x0c);	//显示开及光标设置
}	

void mDelay(uchar j)	//延时,毫秒数由j决定
{   uint i=0;
    for(;j>0;j--)
    {  for(i=0;i<124;i++)
        {;}
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -