📄 lcd._h
字号:
#ifndef __LCD_h
#define __LCD_h
#include <iom16v.h>
#include <macros.h>
#define LCD_EN_PORT PORTC
#define LCD_RW_PORT PORTC
#define LCD_RS_PORT PORTC
#define LCD_DATA_PORT PORTA
#define LCD_DATA_DDR DDRA
#define LCD_DATA_PIN PINA
#define LCD_EN 0x02
#define LCD_RS 0x01
#define LCD_DATA 0xf0
extern void delay_nus(unsigned char n);
extern void delay_nms(unsigned char n);
void LCD_en_write(void) //液晶使能
{
LCD_EN_PORT|=LCD_EN;
delay_nus(5);
LCD_EN_PORT&=~LCD_EN;
}
void LCD_write_char(unsigned command,unsigned data) // 写数据
{
unsigned command_temp,data_temp;
command_temp=command;
data_temp=data;
delay_nus(20);
if(command==0)
{
LCD_RS_PORT|=LCD_RS; //RS=1
LCD_DATA_PORT&=0x0f;
LCD_DATA_PORT|=data_temp&0xf0; //写高四位
LCD_en_write();
data_temp=data_temp<<4;
LCD_DATA_PORT&=0x0f;
LCD_DATA_PORT|=data_temp&0xf0; //写低四位
LCD_en_write();
}
else
{
LCD_RS_PORT&=~LCD_RS; //RS=0
LCD_DATA_PORT&=0x0f;
LCD_DATA_PORT|=command_temp&0xf0; //写高四位
LCD_en_write();
command_temp=command_temp<<4;
LCD_DATA_PORT&=0x0f;
LCD_DATA_PORT|=command_temp&0xf0; //写低四位
LCD_en_write();
}
}
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( address, 0 );
}
void LCD_init(void) //液晶初始化
{
delay_nms(30);
LCD_write_char(0x28,0); //4位显示
LCD_write_char(0x0c,0); //显示开
LCD_write_char(0x01,0); //清屏
delay_nms(30);
}
void LCD_write_string(unsigned char x,unsigned char y,unsigned char *s)
{
LCD_set_xy( x, y); //写地址
while (*s) // 写显示字符
{
LCD_write_char(0, *s);
s++;
}
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -