📄 lcd.h
字号:
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
sfr db=0x80;
sbit rs=P2^0;
sbit rw=P2^1;
sbit en=P2^2;
// check whether the BF is busy or not //
uchar lcd_wait(void)
{
rs=0;
rw=1; _nop_();
en=1; _nop_();
while(db&0x80);
en=0;
return(db);
}
// write the data to lcd or read the directive from lcd //
#define lcd_command 0
#define lcd_data 1
#define lcd_clear_screen 0x01
#define lcd_homing 0x02
void lcd_write(bit byte,uchar inpute)
{
rw=0;
rs=byte;
en=0; _nop_();
db=inpute; _nop_();
en=1; _nop_();
en=0; _nop_();
lcd_wait();
}
// set display //
#define lcd_on 0x0c
#define lcd_off 0x08
#define lcd_cursor 0x0A
#define lcd_no_cursor 0x08
#define lcd_flash 0x09
#define lcd_no_flash 0x08
void lcd_setdisplay(uchar display)
{
lcd_write(lcd_command,display);
}
// set input //
#define lcd_ac_up 0x06
#define lcd_ac_down 0x04
#define lcd_move 0x05
#define lcd_no_move 0x04
void lcd_setinput(uchar inputmode)
{
lcd_write(lcd_command,inputmode);
}
// if the cursor move //
#define lcd_curson 0x02
#define lcd_screen 0x08
#define lcd_left 0x00
#define lcd_right 0x04
void lcd_movn(direction, object)
uchar direction,object;
{
if(object==lcd_curson)
lcd_write(lcd_command,0x10|direction);
if(object==lcd_screen)
lcd_write(lcd_command,0x18|direction);
}
// 初始化lcd //
void lcd_initial(void)
{
en=0;
lcd_write(lcd_command,0x38);
lcd_write(lcd_command,0x38);
lcd_setdisplay(lcd_on|lcd_no_cursor);
lcd_write(lcd_command,lcd_clear_screen);
lcd_setinput(lcd_ac_up|lcd_no_move);
}
// 显示的位置 //
void gotoxy(uchar x,uchar y)
{
if(y==0)
lcd_write(lcd_command,0x80|x);
if(y==1)
lcd_write(lcd_command,0x80|(x-0x40));
}
// 输出 //
void print(uchar *str)
{
while(*str!='\0')
{
lcd_write(lcd_data,*str);
str++;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -