當前位置:首頁 > 單片機 > 單片機
[導(dǎo)讀]//////////////////上下滾動顯示/////////////////////8051#include #include typedef unsigned char uchar;typedef unsigned int uint;sbit rs=P2^0;sbit rw=P2^1;sbit e=P2^2;uchar key_val;uchar i,n;uchar code

//////////////////上下滾動顯示/////////////////////8051
#include
#include
typedef unsigned char uchar;
typedef unsigned int uint;
sbit rs=P2^0;
sbit rw=P2^1;
sbit e=P2^2;
uchar key_val;
uchar i,n;
uchar code dis0[]={"00000000000000001111111111111111222222222222222233333333333333334444444444444444"};
void delayms(uint ms)
{// 延時子程序
uchar i,j;
for(;ms>0;ms--)
for(i=6;i>0;i--)
for(j=82;j>0;j--);
}
bit lcd_bz()
{// 測試LCD忙碌狀態(tài)
bit result;
rs=0;
rw=1;
e=1;
_nop_();
_nop_();
_nop_();
_nop_();
result=(bit)(P0&0x80);
e=0;
return result;
}

void lcd_w_cmd(uchar cmd)
{// 寫入指令數(shù)據(jù)到LCD
while(lcd_bz());
rs=0;
rw=0;
e=0;
_nop_();
_nop_();
P0=cmd;
_nop_();
_nop_();
_nop_();
_nop_();
e=1;
_nop_();
_nop_();
_nop_();
_nop_();
e=0;
}

void lcd_pos(uchar pos)
{//設(shè)定顯示位置
lcd_w_cmd(pos|0x80);
}

void lcd_w_dat(uchar dat)
{//寫入字符顯示數(shù)據(jù)到LCD
while(lcd_bz());
rs=1;
rw=0;
e=0;
P0=dat;
_nop_();
_nop_();
_nop_();
_nop_();
e=1;
_nop_();
_nop_();
_nop_();
_nop_();
e=0;
}
void lcd_init()
{//LCD初始化設(shè)定
lcd_w_cmd(0x38);//
delayms(1);
lcd_w_cmd(0x0c);//
delayms(1);
lcd_w_cmd(0x06);//
delayms(1);
lcd_w_cmd(0x01);//清除LCD的顯示內(nèi)容
delayms(1);
}
void disp_2line() //雙行顯示代碼
{
lcd_pos(0x00);
i=n*16;
n++;
while(dis0[i]!='