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

📄 lcd.h

📁 基于STC单片机,电子钟设计,五个按键,LCD显示,
💻 H
字号:

#define uchar unsigned char
#define uint unsigned int
#define check 1
#define uncheck 0
//#define DB P0
sfr DB = 0x80;
sbit RS = P2^0;
sbit RW = P2^1;
sbit E  = P2^2;

void setddr(unsigned char y,unsigned char x);

void delayms(unsigned int t)  //延时t毫秒 at 12.0 MHz
{
	uint i;
	while(t--)
	{
		i=1000;
		while(i--);	
	}
}



//检查BF信号
void checkbusy(void)
{
	unsigned char temp;
	DB = 0xFF;
	RW = 1;
	RS = 0;
	E = 0;
	E = 1;
	do
	{
		temp = DB;
	}while ((temp&0x80)==0x80);
	RW = 0;
}

//1602写命令子程序
void write(bit busy,uchar tempdata)		
{
	if(busy) checkbusy();
	E = 1;
	DB = tempdata;
	RS = 0;
	RW = 0;
	E = 0;
	E = 0;
}

/*****1602写数据子程序*****/
void writeddr(bit busy,uchar tempdata)
{
	if(busy) checkbusy();	
	E = 1;
	DB = tempdata;
	RS = 1;
	RW = 0;
	E = 0;
	E = 0;
}

//初始化:光标闪烁
/*void init_flash(void)
{
	write(check,0x38);
	write(check,0x0d);
	write(check,0x01);		//清屏
	write(check,0x06);
}*/

//初始化:光标不闪烁
void init_unflash(void)
{
	write(check,0x38);		//选择八口数据传送,两行显示,5*10点阵,加光标
	write(check,0x0c);		//开显示,不显示光标,关光标闪烁
	write(check,0x01);		//清屏
	delayms(30);
	write(check,0x06);		//指针自动加1,禁止滚动
	delayms(30);
}

//写数字
/*void wn(unsigned int c)
{
	writeddr(check,0x30+c);
}*/

//光标移到第y行第x个字符
void setddr(unsigned char y,unsigned char x)
{
	checkbusy();
	if(y==1)
		write(check,0x80+x-1);
	else write(check,0xc0+x-1);
}

//在Y行,X列显示字符串
void writestr(uchar y,uchar x,uchar *DData)
{
	unsigned char i=0;
	setddr(y,x);
	checkbusy();
	while(DData[i]!='\0')
	{
		writeddr(uncheck,DData[i]);
		i++;
	}
}

⌨️ 快捷键说明

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