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

📄 lcd1602.h

📁 电感表的程序和电路原理图。 ATmega8单片机。
💻 H
字号:




#define LCD_EN_PORT    PORTD
#define LCD_EN_DDR     DDRD
#define LCD_EN         (1<<7)     //

#define LCD_RS_PORT    PORTB 
#define LCD_RS_DDR     DDRB
#define LCD_RS         (1<<5)     //

#define LCD_DATA_PORT  PORTB   
#define LCD_DATA_DDR   DDRB    
#define LCD_DATA_BIT   0b00011110 //
flash unsigned char data[8]={0x0C,0x0C,0x03,0x04,0x04,0x04,0x03,0x00};//℃
flash unsigned char data1[8]={0x04,0x0E,0x15,0x04,0x04,0x04,0x04,0x00};//↑

void LCD_en_write(void)  //液晶使能
{
  LCD_EN_PORT|=LCD_EN;
  delay_us(12);
  LCD_EN_PORT&=~LCD_EN;
  delay_us(12);
}
void LCD_write_low(unsigned char temp)
{
  LCD_DATA_PORT&=~LCD_DATA_BIT;              //清高四位
  LCD_DATA_PORT|=(temp<<1)&LCD_DATA_BIT; //写低四位
  LCD_en_write();
}
void LCD_write_high(unsigned char temp)
{
  LCD_DATA_PORT&=~LCD_DATA_BIT;              //清高四位
  LCD_DATA_PORT|=(temp>>3)&LCD_DATA_BIT; //写低四位
  LCD_en_write();
}

void LCD_write_command(unsigned char command) //写指令
{
  delay_us(20);
  LCD_RS_PORT&=~LCD_RS;        //RS=0
  LCD_write_high(command);
  LCD_write_low(command);
  
}

void LCD_write_data(unsigned char data) //写数据
{
  delay_us(16);
  LCD_RS_PORT|=LCD_RS;                     //RS=1
  LCD_write_high(data);
  LCD_write_low(data);
}
void LCD_clear(void)         //清屏
{
  
  LCD_write_command(0x01);  
  delay_ms(2);
}
void LCD_inital(void)
{
 LCD_DATA_DDR|=LCD_DATA_BIT;   //数据口方向为输出
 LCD_EN_DDR|=LCD_EN;       //设置EN方向为输出
 LCD_RS_DDR|=LCD_RS;       //设置RS方向为输出
 LCD_write_low(0x03);
 delay_ms(20);
 LCD_write_low(0x03);
 delay_us(200);
 LCD_write_low(0x03);
 delay_us(20);
 LCD_write_low(0x02);      //4位显示
 LCD_write_command(0x28);  //4位,设定两行
 LCD_write_command(0x0C);  //显示开
 LCD_write_command(0x01);  //清屏
 delay_ms(2);
}


void write_user_capter(unsigned char ascii,flash unsigned char *z)
//ascii为与要定义的图案对应的ascii码值(0到7间任选)
//z为字码定义数组
{ 
  unsigned char address=0,i,temp=0;     
  temp=(ascii&0x07)<<3;                
   for(i=0;i<8;i++) 
   {   
      address = 0x40 +temp+ i; 
      LCD_write_command( address ); 
      delay_us(5); 
      LCD_write_data ( *(z++)); 
      delay_us(5); 
   } 
} 


void LCD_goto_xy( unsigned char x, unsigned char y )  //写地址函数
{
    unsigned char address;
    if (y == 0) address = 0x80 + x;
    else   address = 0xc0 + x;
    LCD_write_command( address);
}

void LCD_put_c( unsigned char data) //列x=0~15,行y=0,1
{
   LCD_write_data( data);
}

void LCD_put_str(unsigned char X,unsigned char Y, flash unsigned char *s) //列x=0~15,行y=0,1
{
    LCD_goto_xy( X, Y ); //写地址    
    while (*s)  // 写显示字符
    {
      LCD_write_data( *s );
      s ++;
    }
 }
 void LCD_put_str2(unsigned char X,unsigned char Y, unsigned char *s) //列x=0~15,行y=0,1
{
    LCD_goto_xy( X, Y ); //写地址    
    while (*s)  // 写显示字符
    {
      LCD_write_data( *s );
      s ++;
    }
 }          
 

⌨️ 快捷键说明

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