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

📄 jhd162.c

📁 国产LCD显示屏JHD162驱动源码
💻 C
字号:
#include <at89x51.h>
#include <intrins.h>
#define uchar unsigned char
#define uint  unsigned int

sbit dc=0xa5;        /*P2.5     LCD的RS*/
sbit rw=0xa6;       /*P2.6     LCD的R/W*/
sbit cs=0xa7;      /*P2.7     LCD的E*/
#define lcdbus P0  /*P0LCD  数据D0=P0.0*/ 

void soft_nop(){}


uchar data lcdcounter;

bit lcdusing1,lcdusing2;
bit lcd_checkbusy()    /*检查LCD忙*/

{  register lcdstate;
   dc=0;
   rw=1;
   cs=1;
   soft_nop();
   lcdstate=lcdbus;
   cs=0;
   return((bit)(lcdstate&0x80));
}

void lcd_wrcmd(uchar lcdcmd) /*写LCD命令*/
{  lcdusing1=1;
   while(lcd_checkbusy());
   lcdbus=lcdcmd;
   dc=0;
   rw=0;
   cs=1;
   soft_nop();
   cs=0;
   lcdbus=0xff;
   lcdusing1=0;
}

void lcd_moveto(char position)  /*移动光标到:0-79*/
{  register cmd=0x80;
   lcdcounter=position;
     if(position>59)
	    position+=0x18;
	 else
	 {if(position>39)position-=0x14;
	  else
	  {if(position>19)position+=0x2c;
	  }
	 }
   cmd=cmd|position;
   lcd_wrcmd(cmd);
}

void lcd_wrdata(char lcddata)  /*在当前显示位置显示数据*/
{
   lcdusing2=1;
   while(lcd_checkbusy());
   if(lcdcounter==20)
     {lcd_moveto(20);
      while(lcd_checkbusy());
     }
   if(lcdcounter==40)
     {lcd_moveto(40);
      while(lcd_checkbusy());
     }
   if(lcdcounter==60)
     {lcd_moveto(60);
      while(lcd_checkbusy());
     }
   if(lcdcounter==80)
     {lcd_moveto(0);
      while(lcd_checkbusy());
	  lcdcounter=0;
     }
   lcdcounter++;
   lcdbus=lcddata;
   dc=1;
   rw=0;
   cs=1;
   soft_nop();
   cs=0;
   lcdbus=0xff;
   lcdusing2=0;
}


void lcd_string(char *strpoint)  /*在指定位置显示LCD字符串*/
{  register i=0;
   while(strpoint[i]!=0){
   lcd_wrdata(strpoint[i]);
   i++;
   }    
}


void lcd_init() /*初始化*/
{  lcd_wrcmd(0x38); /*设置8位格式,2行,5*7 */
   lcd_wrcmd(0x0c); /*整体显示,关光标,不闪烁*/
   lcd_wrcmd(0x06); /*设定输入方式,增量不移位*/
   lcd_wrcmd(0x01); /*清除显示*/
   lcdcounter=0;
}

void lcd_cls() /*清除显示*/
{  lcd_wrcmd(0x01);
   lcdcounter=0;
}



/**********************************************************************/

⌨️ 快捷键说明

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