📄 lcd_1602.c
字号:
#include "LCD_1602.h"
/********************************************************************/
void LCD_delay(unsigned char i)
{
for(;i>0;i--);
}
/********************************************************************/
void LCD_en_command(unsigned char command)
{
P3DIR=0x15;
P2DIR=0xFF;
CLR_LCD_1602_RS;
CLR_LCD_1602_RW;
LCD_I0=command;
SET_LCD_1602_EN;
LCD_delay(50);
CLR_LCD_1602_EN;
}
/********************************************************************/
void LCD_en_dat(unsigned char dat)
{
P3DIR=0x15;
P2DIR=0xFF;
SET_LCD_1602_RS;
CLR_LCD_1602_RW;
LCD_I0=dat;
SET_LCD_1602_EN;
LCD_delay(50);
CLR_LCD_1602_EN;
}
/********************************************************************/
void LCD_set_xy( unsigned char x, unsigned char y )
{
unsigned char address;
if (y == 0)
address = 0x80 + x;
else
address = 0xc0 + x;
LCD_en_command(address);
}
/********************************************************************/
void LCD_write_char( unsigned x,unsigned char y,unsigned char dat)
{
LCD_set_xy( x, y );
LCD_en_dat(dat);
}
/********************************************************************/
void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s)
{
LCD_set_xy( X, Y );
while (*s)
{
LCD_I0=*s;
LCD_en_dat(*s);
s ++;
}
}
/********************************************************************/
void LCD_init(void)
{
P3DIR = BIT0 + BIT1 + BIT2; // LCD control bus
LCD_en_command(0x0C);
LCD_en_command(0x06);
LCD_en_command(0x80);
LCD_en_command(0x38);
LCD_en_command(0x01);
}
/********************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -