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

📄 lcd.h

📁 带遥控的液晶显示程序
💻 H
字号:
#ifndef LCD_2003_7_21
#define LCD_2003_7_21

#include<reg51.h>
#include<intrins.h>

sbit  LcdRS=P3^6;
sbit  LcdRW=P3^4;
sbit  LcdEN=P3^5;
sbit ACC_7=ACC^7;

#define LcdPort P0

code char table[]="0123456789ABCDEF";

unsigned char code dis1[] = {"pp51.com"};
unsigned char code dis2[] = {"www.pp51.com"};
unsigned char code dis3[] = {"http://pp51.com"};

unsigned char code RightCode1[]={0x18,0x1C,0x1E,0x1F,0x1F,0x1E,0x1C,0x18};
unsigned char code RightCode2[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

#define COMMAND			0         // style
#define DATA			1         // style
#define SHOW			0x04      
#define HIDE			0x00      // default	  

#define CURSOR			0x02 
#define NO_CURSOR		0x00      // default		     

#define FLASH			0x01      // 光标闪动
#define NO_FLASH		0x00      // default
#define CURSOR		0x02      
#define SCREEN		0x08
#define LEFT		0x00
#define RIGHT		0x04

void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData);
void DisplayListChar(unsigned char X, unsigned char Y, unsigned char code *DData);
void LcdWriteCommand( unsigned char style, unsigned char dictate); //向LCD写入命令或数据
void Lcdclear(unsigned char command);  // LCD清屏函数 

unsigned char b=0;



void Delay50us(unsigned int count)
{
	unsigned int i,j;
	for(i=0;i<count;i++)
	for(j=0;j<6;j++);
}
/*void scan_key()
{	Delay1ms(1);
	if(P3_3==0)b++;
	if(b>=3)b=0;
	F0:if(P3_3==0)goto F0;				//按键未释放,在此等候//
}
*/
char Wait()	//等待
{
	LcdRS=0;
	LcdRW=1;	_nop_();
	LcdEN=1;	_nop_();
	do{ ACC=LcdPort;
		}while(ACC_7==1);	
	LcdEN=0;
	Delay1ms(1);
	return ACC;		
}

void LcdWriteCommand( unsigned char style, unsigned char dictate) //向LCD写入命令或数据
{
 	LcdRS=style;
	LcdRW=0;	_nop_();
	LcdEN=1;	_nop_();
	LcdPort=dictate;_nop_();
	LcdEN = 0;
	Wait();
}


void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData)//按指定位置显示一个字符
{
Y &= 0x1;
X &= 0xF; //限制X不能大于15,Y不能大于1
if (Y) X |= 0x40; //当要显示第二行时地址码+0x40;
X |= 0x80; //算出指令码
LcdWriteCommand(COMMAND, X); //这里不检测忙信号,发送地址码
LcdWriteCommand(DATA, DData);
}


void DisplayListChar(unsigned char X, unsigned char Y, unsigned char code *DData)//按指定位置显示一串字符
{
unsigned char ListLength;

ListLength = 0;
Y &= 0x1;
X &= 0xF; //限制X不能大于15,Y不能大于1
while (DData[ListLength]>0x20) //若到达字串尾则退出
{
if (X <= 0xF) //X坐标应小于0xF
{
DisplayOneChar(X, Y, DData[ListLength]); //显示单个字符
ListLength++;
X++;
}
}
}

void initial(void)
{

	LcdEN=0;
	LcdWriteCommand(COMMAND, 0x38); // 显示模式设置(不检测忙信号)
	Delay1ms(15);
	LcdWriteCommand(COMMAND, 0x38); 
	Delay1ms(5);
	LcdWriteCommand(COMMAND, 0x38);	// 共三次
	Delay1ms(5);
	LcdWriteCommand( DATA, 0X38); // 显示模式设置(以后均检测忙信号)
    LcdWriteCommand( COMMAND, 0X01); // 显示清屏
	LcdWriteCommand( COMMAND, 0X0F); // 显示开及光标闪烁

}


void SetDisplay(unsigned char DisplayMode)
{
	LcdWriteCommand(COMMAND, 0x08|DisplayMode);	
}

void SetInput(unsigned char InputMode)
{
	LcdWriteCommand(COMMAND, 0x04|InputMode);
}

void Move(unsigned char object, unsigned char direction)
{
	if(object==CURSOR)
		LcdWriteCommand(COMMAND,0x10|direction);
	if(object==SCREEN)
		LcdWriteCommand(COMMAND,0x18|direction);
}

void GotoXY(unsigned char x, unsigned char y)
{
	if(y==0)
		LcdWriteCommand(COMMAND,0x80|x);
	if(y==1)
		LcdWriteCommand(COMMAND,0x80|(x-0x40));
}

void Write(unsigned char style, unsigned char input)
{
	LcdRS=style;
	LcdRW=0;	_nop_();
	LcdEN=1;	_nop_();
	P0=input;	_nop_();
	LcdEN=0;	_nop_();
	Wait();	
}

void Print(unsigned char *str)
{
	while(*str!='\0')
	{
		LcdWriteCommand(DATA,*str);
		str++;
	}
}

void LcdData(char); /* LCD数据输入函数 */
void LcdData(char c)
{ 

LcdPort = c;
LcdRS = 1;
LcdRW = 0;
LcdEN = 0;
LcdEN = 1;
}

void LcdHex2(char); /* 字符的十六进制显示函数 */
void LcdHex2(char c)
{ 
LcdData(table[(((c&0xf0)>>4)&0x0f)]);
LcdData(table[(c&0x0f)]);
}

void LoadChar(unsigned char user[8],unsigned char place)
{
	unsigned char i;
	LcdWriteCommand(COMMAND,0x40|(place*8));
	for(i=0; i<8; i++)
		LcdWriteCommand(DATA,user[i]);
}

#endif

⌨️ 快捷键说明

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