📄 lcdfuncs.h
字号:
/* These routines interface a Hitachi LM016 LCD display module
to P0 of the AT89C52 using the 4 bit data bus interface
I/O connections are as defined below
P0.4 - P0.7 = DB.4 - DB.7, P0.2 = EN, P0.1 = R/W*, P0.0 = RS */
void wait_LCD_busy(void);
void init_2_line_LCD(void);
void write_LCD_byte(bit reg_val,unsigned char byte_val);
unsigned char read_LCD_byte(bit reg_val);
void write_LCD_line(unsigned char start_add,unsigned char *line_text);
void init_delay(void);
void clear_line(bit line_val);
void strobe_LCD(void);
void clear_lcd(void);
#define LCD_CONTROL 0
#define LCD_DATA 1
#define LINE_1 0x80
#define LINE_2 0xC0
#define UPPER_LINE 0
#define LOWER_LINE 1
/*
#define CLEAR_DISPLAY 0x01
#define CURSOR_HOME 0x02
#define DISPLAY_OFF 0x08
#define CURSOR_OFF 0x0C
#define CURSOR_ON 0x0D
#define CURSOR_BLINK_2 0x0E
#define CURSOR_BLINK_1 0x0F
#define SHIFT_LEFT 0x18
#define SHIFT_RIGHT 0x1C
*/
sbit RS = P0^1;
sbit RW = P0^2;
sbit EN = P0^3;
static unsigned char char_add,data_byte;
code unsigned char init_bytes[5] = {0x28,0x08,0x01,0x06,0x0c};
//code unsigned char init_bytes[6] = {0x32,0x2c,0x06,0x0c,0x01,0x02};
void init_2_line_LCD(void)
{
unsigned char temp;
init_delay();
P0 = 0x31;
strobe_LCD();
init_delay();
strobe_LCD();
init_delay();
strobe_LCD();
wait_LCD_busy();
P0 = 0x21;
strobe_LCD();
wait_LCD_busy();
for(temp = 0;temp < 5;temp++)
{
write_LCD_byte(LCD_CONTROL,init_bytes[temp]);
}
// write_LCD_byte(LCD_CONTROL,0x02);
/*display on,cursor off,blink off*/
}
void init_delay()
{
data_byte = 40;
while(data_byte > 0)
{
for(char_add = 0;char_add < 150;char_add++)
{
}
data_byte--;
}
}
void write_LCD_byte(bit reg_val,unsigned char byte_val)
{
P0 = (byte_val & 0xf0)+ 0x01;
if(reg_val == LCD_DATA)
{
RS = 1;
}
strobe_LCD();
P0 = (byte_val << 4)+ 0x01;
if(reg_val == LCD_DATA)
{
RS = 1;
}
strobe_LCD();
wait_LCD_busy();
}
unsigned char read_LCD_byte(bit reg_val)
{
/*unsigned char temp;*/
P0 = 0xf5; /*make P0 upper nibble i/p and set R/W**/
if(reg_val == LCD_DATA)
{
RS = 1; /*set RS*/
}
EN = 1;
data_byte = P0 & 0xf0; /*read high order nibble*/
EN = 0;
EN = 1;
data_byte = data_byte + (P0 >> 4); /*read low order nibble and format*/
EN = 0;
P0 = 0x01; /*return P0 to inactive state*/
return data_byte;
}
void wait_LCD_busy(void)
{
while((read_LCD_byte(LCD_CONTROL) & 0x80) == 0x80);
}
void write_LCD_line(unsigned char start_add,unsigned char *line_text)
{
char_add = 0;
write_LCD_byte(LCD_CONTROL,start_add);
while(*(line_text + char_add) != '\0')
{
write_LCD_byte(LCD_DATA,*(line_text + char_add));
char_add++;
}
}
/*
void clear_line(bit line_val)
{
char_add = 0xc0;
if(line_val == UPPER_LINE)
{
char_add = 0x80;
}
write_LCD_byte(LCD_CONTROL,char_add);
for(char_add = 0;char_add < 16;char_add++)
{
write_LCD_byte(LCD_DATA,' ');
}
} */
void strobe_LCD(void)
{
EN = 1;
EN = 0;
}
void clear_lcd(void)
{
clear_line(UPPER_LINE);
clear_line(LOWER_LINE);
write_LCD_byte(LCD_CONTROL,0x01);
write_LCD_byte(LCD_CONTROL,0x02);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -