📄 lcd1602.c
字号:
//-----------------------------LCD1602 Function---------------------------------
#include <iom8v.h>
#include <macros.h>
#include "lcd1602.h"
void LCD_init(void) //液晶初始化
{
delay_nms(2);
LCD_write_char(0x28,0); //4位显示
LCD_write_char(0x0c,0); //显示开
LCD_write_char(0x01,0); //清屏
}
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 ++;
}
}
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_en_write(void) //液晶使能
{
LCD_EN_PORT|=LCD_EN;
delay_nus(1);
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(16);
if(command==0)
{
LCD_RS_PORT|=LCD_RS; //RS=1
LCD_DATA_PORT&=0Xf0;
LCD_DATA_PORT|=((data_temp&0xf0)>>4); //写高四位
LCD_en_write();
LCD_DATA_PORT&=0Xf0;
LCD_DATA_PORT|=data_temp&0x0f; //写低四位
LCD_en_write();
}
else
{
LCD_RS_PORT&=~LCD_RS; //RS=0
LCD_DATA_PORT&=0Xf0;
LCD_DATA_PORT|=((command_temp&0xf0)>>4); //写高四位
LCD_en_write();
LCD_DATA_PORT&=0xf0;
LCD_DATA_PORT|=command_temp&0x0f; //写低四位
LCD_en_write();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -