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

📄 1602.h

📁 1602液晶显示头文件 硬件测试通过 相当好用
💻 H
字号:
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//void lcd_delay(int i)                          延时
//void wcmd(uchar c)                             写控制字
//void lcd_showchar(uchar pos,uchar c)           显示单个字符(在pos位置上)
//void lcd_display(uchar pos,uchar *dispbuf)     显示字符串(在pos位置上,以`结束)
//void lcd_init()                               显示初始化(每次显示前必用,否则结果失真)
//void loadchar(uchar *str)                  加载字符
//void clr()


/************************************LCD1602与单片机接口方式****************************************************************************/
#define RS    P3OUT|=BIT2;
#define RS0   P3OUT&=~BIT2;
#define RW    P3OUT|=BIT3;
#define RW0   P3OUT&=~BIT3;
#define EN    P3OUT|=BIT5;
#define EN0    P3OUT&=~BIT5;
/**************************************************************************************************************************************/



unsigned char keywords[]={0x30,0x31,0x32,0x33,	//0,1,2,3,	对应的在LCD1602上的代码地址
                          0x34,0x35,0x36,0x37,	//4,5,6,7,  
                          0x38,0x39,0x41,0x42,	//8,9,A,B
                          0x43,0x44,0x45,0x46}; //C,D,E,F



void lcd_delay(int i)
{
  while(i--);
}


uint lcd_bz()	//测试LCD忙碌状态函数
{   
     uint result;
     P5DIR&=~BIT7;
	 RS0;
       //  __no_operation();
	 RW;
    //     __no_operation();
	 EN;
	/// __no_operation();
	// __no_operation();
	 __no_operation();
         __no_operation();
         result=P5IN&BIT7;
     P5DIR|=BIT7; 
     EN0;
	 return result;
}


void wcmd(uchar c) //写控制指令到LCD
{
     while(lcd_bz());
     //lcd_delay(100);
         RS0;
     //    __no_operation();
	 RW0;
      //   __no_operation();
	 EN0;
    // __no_operation();
   //  __no_operation();
	 P5OUT=c;
     __no_operation();
     __no_operation();
     __no_operation();
     __no_operation();

      EN;
     __no_operation();
     __no_operation();
     //__no_operation();
    // __no_operation();
      EN0;
}


void writedata(uchar c)//写入字符显示数据到LCD
{
    while(lcd_bz());
  //lcd_delay(100);

    RS;
  //  __no_operation();
    EN0;
  //  __no_operation();
    RW0;
   // __no_operation();
	P5OUT=c;
      __no_operation();
   //   __no_operation();
      __no_operation();
    //  __no_operation();
//    lcd_delay(255); 
    EN;
     __no_operation();
 //    __no_operation();
  //   __no_operation();
     __no_operation();
    EN0;
}


/*********************************在pos位置上显示单个字符子程序***************************************************************************/
void lcd_showchar(uchar pos,uchar c)//显示单个字符(在pos位置上),pos必须为十六进制
/*****************************************************************************************************************************************/  
{   uchar p;
    if(pos>=0x11)
      p=pos+0xb0;	//调整使字符从第一为开始显示
    else
      p=pos+0x80;
    wcmd(p);					//置字符发生存储器地址,即设置显示位置。地址也是控制指令,所以要调用写控制指令子程序。 
    writedata(c);				//告诉LCD要显示的字符
}


void loadchar(uchar *str)		//加载字符
  {
    uchar p,i;
    p=0x40;
    wcmd(p);
   for(i=0;i<32;i++) 
    writedata(str[i]);
  }


/**********************************在pos位置上显示字符串*dispbuf子程序*********************************************************************/
void lcd_display(uchar pos, char *dispbuf)//显示字符串(在pos位置上,以`结束),pos必须为十六进制 
/******************************************************************************************************************************************/ 
  {
      uchar i=0;     
	  while(dispbuf[i]!=0)
     {
      lcd_showchar(pos+i,dispbuf[i]);
      i++;
      } 
   }


void clr()       //清屏
{
  wcmd(1);
}


void lcd_init()	 //显示初始化(每次显示前必用,否则结果失真)
{
 //lcd_delay(255);
    wcmd(0x38);	 //设置为4位总线,双行显示,显示5*7的点阵字符。
  //  __no_operation();
    wcmd(0x38);
   // __no_operation();
    wcmd(0x0c);	 //显示开及光标设置:设置为显示开,无光标,光标不闪烁。
   /// __no_operation();
    wcmd(0x01);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

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