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

📄 lcd1602.c

📁 利用51单片机控制1602读写
💻 C
字号:
#include <reg51.h>
#include <intrins.h>
#include <absacc.h>
//#define	lcd_comw   XBYTE[0xF200]      
//#define	lcd_dataw  XBYTE[0xF201]      
//#define	lcd_com    XBYTE[0xF202]      
//#define	lcd_data   XBYTE[0xF203]      
#define  uint  unsigned  int
#define  uchar unsigned  char
bit flag;
sbit  PinRS=P2^0;
sbit  PinRW=P2^1;
sbit  PinE=P2^2;
sfr   PinData=0x80;
#define   ClearScreen()     Write_Data_Com(0,0x01)	  //清屏
#define	  CursorReturn()    Write_Data_Com(0,0x02)	  //归位
#define   InputMode(temp)	Write_Data_Com(0,temp)	  //输入方式设置
#define   DispControl(temp)	Write_Data_Com(0,temp)	  //显示开关设置
#define   DispShift(temp)	Write_Data_Com(0,temp)	  //光标画面移位
#define   FunctionSet(temp)	Write_Data_Com(0,temp)	  //功能设置
void  delay()
{
 uchar i;
 for(i=200;i>0;i--)	;
}

unsigned char LCD_Wait(void)
{
	PinRS=0;
	PinRW=1;	_nop_();
	PinE=1;	_nop_();
	//while(DBPort&0x80);//在用Proteus仿真时,注意用屏蔽此语句,在调用GotoXY()时,会进入死循环,
						 //可能在写该控制字时,该模块没有返回写入完备命令,即DBPort&0x80==0x80
						 //实际硬件时打开此语句
	PinE=0;
	return PinData;		
}
void  Write_Data_Com(bit style,uchar data1)
{
 PinE=0;
 PinRS=style;
 PinRW=0;	        _nop_();
 PinData=data1;		_nop_();
 PinE=1;			_nop_();
 PinE=0;			_nop_();
 //while(flag);
 //if(style==0)    lcd_comw=data1;
 //else            lcd_dataw=data1;
 //delay();
  LCD_Wait();
}
/*uchar  Read_Data_Com(bit style)
{
 uchar temp;
 PinE=0;
 PinRS=style;
 PinRW=1;		    _nop_();
 temp=PinData;		_nop_();
 PinE=1;			_nop_();
 PinE=0;			_nop_();
 //while(flag);
 //if(style==0)    temp=lcd_com;
 //else            temp=lcd_data;
 //delay();
 
 return temp; 
  LCD_Wait();
} 
bit StatusCheck()
{
 flag=(Read_Data_Com(0) & 0x80);
 return flag;
} */

void  LCDReset()
{
 ClearScreen();
 //CursorReturn();
}

void GotoXY(unsigned char x, unsigned char y)
{
	if(y==0)
		 Write_Data_Com(0,0x80|x);
	if(y==1)
		 Write_Data_Com(0,0x80|(x-0x40));
}
void Print(unsigned char *str)
{
	while(*str!='\0')
	{
		 Write_Data_Com(1,*str);
		str++;
	}
}
void  InitLCD()
{
 PinE=0;
 LCDReset();
 InputMode(0x06);
 DispControl(0x0c);
 FunctionSet(0x38);
}

void  main()
{
   
    InitLCD();
   	GotoXY(0,0);
	Print("The 1602LCD Test");
	GotoXY(0,1);
	Print("GO:       by JJJ");

}

⌨️ 快捷键说明

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