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

📄 1602b_lcd.c

📁 atmega16L输入捕获经典试验已经通过验证
💻 C
字号:
#include "1602LCD.h"

unsigned data_temp;
/**********************************************************
光标命令
LCD_write_char(0x0e,0);    //光标开
LCD_write_char(0x0d,0);    //光标所在字符闪烁  
LCD_write_char(0x0c,0);    //光标关  
**********************************************************/
/**********************************************************
TC1602B LCD DISPLAY
建立时间:2003年11月9号
修改日期:2003年11月14号
LCD_write函数功能:当command=0时,向LCD写入数据,否则向LCD写
                   入命令
LCD第一行显示寄存器地址:0X80-0X8F
LCD第二行显示寄存器地址:0XC0-0XCF
**********************************************************/
void LCD_init(void) 
{ 
  unsigned int i=0; 
  delay_nms(1000); 
  for (i=0;i<20;i++) 
    { 
      LCD_write_char(0,0x28); //4bit test 
      delay_nms(15); 
    } 
  LCD_write_char(0,0x0c); //显示开 
  delay_nms(5); 
    LCD_write_char(0,0x01);      //显示清屏
	delay_nms(2);
    LCD_write_char(0,0x06);      //显示光标移动设置	
  }
/*-----------------------------------------------------------------------
LCD_write_char    : 英文字符串显示函数

输入参数:*s      :英文字符串指针;
          X、Y    : 显示字符串的位置,X:0-15,Y:0-1
                    LCD第一行显示寄存器地址:0X80-0X8F
                    LCD第一行显示寄存器地址:0XC0-0XCF

编写日期          :2003-11-19 
最后修改日期      :2004-8-19 		
-----------------------------------------------------------------------*/
void LCD_write_char(unsigned command,unsigned data)
  {       
    if (command == 0)
   	LCD_RS_PORT &= ~LCD_RS;   //RS=0
	else
    LCD_RS_PORT |= LCD_RS;    //RS=1
	
    data_temp = data;
    LCD_Write_half_char();
	data_temp = data;
	data_temp=data_temp << 4;
    LCD_Write_half_char();
	delay_nus(100);	 
  }
/*---------写高4bit到LCD----*/
void LCD_Write_half_char(void)
  {
   	 LCD_DATA_PORT &= 0X0f; //portd4~7=0 
   	 LCD_DATA_PORT |= data_temp&0xf0; //send high 4bit
	 LCD_EN_PORT |= LCD_EN; //EN端产生一个由低电平变高电平,写LCD
	 delay_nus(1);
     LCD_EN_PORT &= ~LCD_EN; //EN端产生一个由高电平变低电平,写LCD
   	 LCD_DATA_PORT &= 0X0f; 
	 delay_nus(1); 
   }

/*-----------------------------------------------------------------------
LCD_set_xy        : 设置LCD显示的起始位置

输入参数:x、y    : 显示字符串的位置,X:0-15,Y:0-1
                    LCD第一行显示寄存器地址:0X80-0X8F
                    LCD第一行显示寄存器地址:0XC0-0XCF

编写日期          :2004-8-19 
最后修改日期      :2004-8-19 		
-----------------------------------------------------------------------*/
void LCD_set_xy( unsigned char x, unsigned char y )
  {
    unsigned char address;
    if (y == 0) address = 0x80 + x;
    else 
       address = 0xc0 + x;
    LCD_write_char(0,address);
  }
/*-----------------------------------------------------------------------
LCD_write_string  : 英文字符串显示函数

输入参数:*s      :英文字符串指针;
          X、Y    : 显示字符串的位置

编写日期          :2004-8-19 
最后修改日期      :2004-8-19 		
-----------------------------------------------------------------------*/
void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s)
  {
    LCD_set_xy( X, Y );
    
    while (*s) 
      {
        LCD_write_char(1,*s);
	s ++;
      }
  }
  

⌨️ 快捷键说明

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