?? jhd162.c
字號:
#include <at89x51.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit dc=0xa5; /*P2.5 LCD的RS*/
sbit rw=0xa6; /*P2.6 LCD的R/W*/
sbit cs=0xa7; /*P2.7 LCD的E*/
#define lcdbus P0 /*P0LCD 數據D0=P0.0*/
void soft_nop(){}
uchar data lcdcounter;
bit lcdusing1,lcdusing2;
bit lcd_checkbusy() /*檢查LCD忙*/
{ register lcdstate;
dc=0;
rw=1;
cs=1;
soft_nop();
lcdstate=lcdbus;
cs=0;
return((bit)(lcdstate&0x80));
}
void lcd_wrcmd(uchar lcdcmd) /*寫LCD命令*/
{ lcdusing1=1;
while(lcd_checkbusy());
lcdbus=lcdcmd;
dc=0;
rw=0;
cs=1;
soft_nop();
cs=0;
lcdbus=0xff;
lcdusing1=0;
}
void lcd_moveto(char position) /*移動光標到:0-79*/
{ register cmd=0x80;
lcdcounter=position;
if(position>59)
position+=0x18;
else
{if(position>39)position-=0x14;
else
{if(position>19)position+=0x2c;
}
}
cmd=cmd|position;
lcd_wrcmd(cmd);
}
void lcd_wrdata(char lcddata) /*在當前顯示位置顯示數據*/
{
lcdusing2=1;
while(lcd_checkbusy());
if(lcdcounter==20)
{lcd_moveto(20);
while(lcd_checkbusy());
}
if(lcdcounter==40)
{lcd_moveto(40);
while(lcd_checkbusy());
}
if(lcdcounter==60)
{lcd_moveto(60);
while(lcd_checkbusy());
}
if(lcdcounter==80)
{lcd_moveto(0);
while(lcd_checkbusy());
lcdcounter=0;
}
lcdcounter++;
lcdbus=lcddata;
dc=1;
rw=0;
cs=1;
soft_nop();
cs=0;
lcdbus=0xff;
lcdusing2=0;
}
void lcd_string(char *strpoint) /*在指定位置顯示LCD字符串*/
{ register i=0;
while(strpoint[i]!=0){
lcd_wrdata(strpoint[i]);
i++;
}
}
void lcd_init() /*初始化*/
{ lcd_wrcmd(0x38); /*設置8位格式,2行,5*7 */
lcd_wrcmd(0x0c); /*整體顯示,關光標,不閃爍*/
lcd_wrcmd(0x06); /*設定輸入方式,增量不移位*/
lcd_wrcmd(0x01); /*清除顯示*/
lcdcounter=0;
}
void lcd_cls() /*清除顯示*/
{ lcd_wrcmd(0x01);
lcdcounter=0;
}
/**********************************************************************/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -