?? lcd1602.h
字號:
#define DISPLAYON 0x0c
#define DISPLAYOFF 0x08
#define INPUTMODE 0x06
#define DISPLAYCLR 0x01
#define RETURNHOME 0x02
#define LCD_PORT P0
sbit LCD_RS = P2^5;
sbit LCD_RW = P2^6;
sbit LCD_EN = P2^7;
void write_lcd_command(unsigned char);
void write_lcd_data(unsigned char);
void write_lcd_char(unsigned char x,bit y,unsigned char DATA);
void lcd_init();
void delay20MS();
bit read_busy();
void gotoxy(unsigned char x,bit y);
/***************************************************************/
void lcd_init()
{
delay20MS();
delay20MS();
write_lcd_command (DISPLAYCLR);//清屏
while(read_busy());//讀忙標志
write_lcd_command (0x38);//8位數據發送模式
while(read_busy());//讀忙標志
write_lcd_command (DISPLAYON);//0x0C
while(read_busy());//讀忙標志
write_lcd_command (INPUTMODE);//input mode
while(read_busy());//讀忙標志
write_lcd_command (0x80);//設置LCD開始顯示地址
while(read_busy());//讀忙標志
write_lcd_command (DISPLAYCLR);//清屏
}
void delay20MS()//延時時間有待調整
{
unsigned char i,j;
for(i = 0; i < 255; i++)
{
for(j = 0; j < 100; j++);
}
}
void write_lcd_command(unsigned char command)
{
LCD_PORT = command;
LCD_RS = 0;
LCD_RW = 0;
LCD_EN = 1;
LCD_EN = 0;
}
void write_lcd_data(unsigned char dat)
{
LCD_PORT = dat;
LCD_RS = 1;
LCD_RW = 0;
LCD_EN = 1;
LCD_EN = 0;
}
void write_lcd_char(unsigned char x,bit y,unsigned char DAT)
{
gotoxy( x, y);
while(read_busy());//讀忙標志
write_lcd_data(DAT);
}
bit read_busy()
{
unsigned char readdata;
LCD_PORT = 0xff;
LCD_RS = 0;
LCD_RW = 1;
LCD_EN = 1;
readdata = LCD_PORT;
LCD_EN = 0;
if (readdata >> 7)
return (1);
else
return (0);
}
void gotoxy(unsigned char x,bit y)
{
while(read_busy());//讀忙標志
if(y)
write_lcd_command(0xc0 + x);//2 line
else
write_lcd_command(0x80 + x);//1 line
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -