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

📄 driver_1602.c

📁 高精度数控毫伏电压源的程序,使用8051控制器,dac76
💻 C
字号:
/************************************************************

详细内容:LCD1602 4线并口通信源程序

作者:何昱
2006-10-5
QQ:262970434

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




#include"DRIVER_1602.h"



unsigned char LCDIO; 



/******************** LCD PART *************************************/
void LCD_delay(void)   
{
  unsigned char i;
  for(i=40;i>0;i--)
    ;
}

void LCD_cls(void)
{
  LCD_en_command(0x01);	
}

void LCD_en_command(unsigned char command)
{
  
  LCD1602_RS=0;   
//  LCD1602_RW=0;
  LCD1602_EN=0;
  
  LCDIO=(command & 0xf0);
  SET_LCD(LCDIO);
 
  LCD1602_EN=1;
  LCD_delay();
  LCD1602_EN=0;

  LCDIO=(command & 0x0f)<<4;
  SET_LCD(LCDIO);
  
  LCD1602_EN=1;
  LCD_delay();
  LCD1602_EN=0;
}
/********************************************************************/
void SET_LCD(unsigned char IO_temp)
{   
	LCD_DB7=IO_temp&0x80;
	
	LCD_DB6=IO_temp&0x40;
					  
	LCD_DB5=IO_temp&0x20;

	LCD_DB4=IO_temp&0x10;
	
}



void LCD_en_dat(unsigned char dat)
{
  
  LCD1602_RS=1;
//  LCD1602_RW=0;
  LCD1602_EN=0;
  LCDIO=(dat & 0xf0);
  SET_LCD(LCDIO);

  LCD1602_EN=1;
  LCD_delay();
  LCD1602_EN=0;

  LCDIO=(dat & 0x0f)<<4;
  SET_LCD(LCDIO);
  LCD1602_EN=1;
  
  LCD_delay();
  LCD1602_EN=0;
}
/********************************************************************/
void LCD_set_xy( unsigned char x, unsigned char y )
{
  unsigned char address;
  if (y ==0) 
   address = 0x80 + x;
  else 
      address = 0xC0 + x;
  LCD_en_command(address); 
}
/********************************************************************/
void LCD_write_char( unsigned x,unsigned char y,unsigned char dat)
{
  LCD_set_xy( x, y ); 
  LCD_en_dat(dat);
}
/********************************************************************/
void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s)
{
    LCD_set_xy( X, Y );    //set address 
    while (*s)       // write character
    {
      LCDIO=*s;
	  SET_LCD(LCDIO);
      LCD_en_dat(*s);   
   s ++;
    }
}
/********************************************************************/
void LCD_init(void)
{ 
  LCD_en_command(0x33);	  //后加的4bit初始化部分!..宇轩
  delay_nms(20);
  LCD_en_command(0x32);
  delay_nms(20);
  


  LCD_en_command(0x08);
  delay_nms(5);
  LCD_en_command(0x01);
  delay_nms(5);
  LCD_en_command(0x06);
  delay_nms(5);
  LCD_en_command(0x0c);
  delay_nms(5);
}
/********************************* *********************************/
void delay_nms(unsigned int n)      
{
    unsigned int i=0,j=0;
    for (i=n;i>0;i--)
     for (j=0;j<1140;j++);  
}
/********************************************************************/

⌨️ 快捷键说明

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