當前位置:首頁 > 單片機 > 單片機
[導讀]//////////////////左右滾動顯示/////////////////////C51 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 code dis0[]

//////////////////左右滾動顯示/////////////////////

C51 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 code dis0[]={"Take time to yell English,it will build your confidence and enhance your personal power. "};
void delayms(uchar 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)
{//設定顯示位置
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初始化設定
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 lcd_disp(uchar x,uchar y,uchar *str)
{
if(y==0) //Y=0為第一行, *STR為所顯示字符串
{
if(x<16) //16為字符長度, x表示起啟位置
{
lcd_pos(x);
for(;x<16&&*str!='