📄 lcd_init.h
字号:
/*
LCD12864液晶驱动模块
*/
/*
PG0---RS---4
PG1---R/W--5
PG2---EN---6
PA0---DB0---7
PA1---DB1---8
PA2---DB2---9
PA3---DB3---10
PA4---DB4---11
PA5---DB5---12
PA6---DB6---13
PA7---DB7---14
*/
#include <iom128v.h>
#include <macros.h>
/*命令或是数据选择*/
/*RS = 0命令,RS = 1数据*/
#define RS_CLR PORTG&=~(1<<0)
#define RS_SET PORTG|=(1<<0)
/*读取或写入选择*/
/*RW = 1读,RW = 0写*/
#define RW_CLR PORTG&=~(1<<1)
#define RW_SET PORTG|=(1<<1)
/*读写使能信号*/
/*下降沿有效*/
#define EN_CLR PORTG&=~(1<<2)
#define EN_SET PORTG|=(1<<2)
/*芯片复位脚*/
/*高电平复位
#define RST_CLR PORTD&=~(1<<PD7)
#define RST_SET PORTD|=(1<<PD7)*/
//延时函数
void delay (unsigned int n)
{
while(n--);
}
void chk_busy(void)
{
PORTA=0XFF;
RS_CLR;
RW_SET;
DDRA=0X00;
EN_SET;
while(PINA&0X80);
EN_CLR;
DDRA=0XFF;
}
//显示屏命令写入函数
void LCD_write_code(unsigned char code)
{
chk_busy();
RS_CLR;
RW_CLR;
PORTA=code;
EN_SET;
delay(100);
EN_CLR;
}
//显示屏数据显写入函数
void LCD_write_data(unsigned char data)
{
chk_busy();
RS_SET;
RW_CLR;
PORTA=data;
EN_SET;
delay(100);
EN_CLR;
}
/*单个字符输入函数;position--显示位置,data--显示内容*/
void disp_char(unsigned char position,unsigned char asii)
{
LCD_write_code(position);
LCD_write_data(asii);
}
/*一串字符输入函数
void disp_char_str(unsigned char position,unsigned char *str)
{
LCD_write_code(position);
while(*str!=0) //含义???
{
LCD_write_data(*str);
str++;
}
}*/
/*汉字输入*/
void disp_word(unsigned char position,unsigned char *word)
{
LCD_write_code(position);//要显示的位置
while(*word!=0)
{
LCD_write_data(*word);
word++;
}
}
//------------------------------------------------------------------------------
//函数名称:disp_number10()
//功能:数据的十进制显示,7显示07,12显示12
//------------------------------------------------------------------------------
void disp_number10(unsigned char position,unsigned char num)
{
unsigned char num_h, num_l;
LCD_write_code(position);
if(num>=10)
{
num_h=(num/10);
num_l=(num%10);
LCD_write_data(num_h+0x30);
LCD_write_data(num_l+0x30);
}
else
{
LCD_write_data(0x30);
LCD_write_data(num+0x30);
}
}
//------------------------------------------------------------------------------
//函数名称:disp_number16()
//功能:数据的16进制显示,
//------------------------------------------------------------------------------
void disp_number16(unsigned char position,unsigned char num)
{
unsigned char num_h,num_l;
LCD_write_code(position);
if(num>=10)
{
num_h=(num/16);
num_l=(num%16);
LCD_write_data(num_h+0x30);
LCD_write_data(num_l+0x30);
}
else
{
LCD_write_data(0x30);
LCD_write_data(num+0x30);
}
}
//显示屏初始化
void disp_init(void)
{
DDRA=0XFF;
//DDRD=(1<<PD4)|(1<<PD5)|(1<<PD6)|(1<<PD7);
DDRG=0XFF;
LCD_write_code(0x30);//功能设定/*30---基本指令动作
LCD_write_code(0x01);//清屏,地址指针指向00H
LCD_write_code(0x06);//光标的移动方向
LCD_write_code(0x0c);//光标反白显示--0x0f/*开显示,关游标
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -