標題:
lcd1602滾動顯示
[打印本頁]
作者:
JINWANDALAOHU
時間:
2017-11-20 17:09
標題:
lcd1602滾動顯示
#include<reg52.h>
typedef unsigned char uint8;
typedef unsigned int uint16;
sbit rs=P2^6;
sbit rw=P2^5;
sbit e=P2^7;
uint8 a[16]="zheeeg ti wwi ";
uint8 b[27]="ze asfeng xe xi 1w284g50hb6 ";
void delay(uint16 i) //1us
{
while(i--);
}
void wrc(uint8 c) /*寫命令*/
{
delay(1000);
rs=0; //選擇發(fā)送命令
rw=0; //選擇寫入
e=0; //使能清零
P0=c; //放入命令
e=1; //寫入時序
delay(10); //保持時間
e=0;
/*
P0=c<<4;
e=1;
e=0;*/ //四位的LCD要加上
}
void wrd(uint8 dat) /*讀命令將數(shù)據(jù)寫在LCD上*/
{
delay(1000);
rs=1; //選擇輸入數(shù)據(jù)
rw=0; //選擇寫入
e=0; //使能清零
P0=dat; //寫入數(shù)據(jù)
e=1; //寫入時序
delay(10);//保持時間
e=0;
/*
P0=dat<<4;
e=1;
e=0; //四位的LCD要加上
rs=0;*/
}
void init() /*初始化設(shè)置*/
{
delay(1000);
/*wrc(0x32);
wrc(0x28);
wrc(0x28); */ //四位的LCD要加上
wrc(0x38); //8位數(shù)據(jù)總線,顯示兩行,5*10點陣
wrc(0x0c);
wrc(0x01);
}
void display()
{
uint8 i;
wrc(0x00+0x80);
for(i=0;i<16;i++)
{
wrd(a[i]);
delay(30000);
}
wrc(0x40+0x80);
for(i=0;i<27;i++)
{
wrd(b[i]);
delay(30000);
}
wrc(0x07); //每寫一個數(shù)據(jù)屏幕就要右移一位,就相對于數(shù)據(jù)來說就是左移了;
/* while(1)
{
wrc(0x00+0x80);
for(i=0;i<16;i++)
{
wrd(a[i]);
delay(30000); //如果不加這條延時語句的話滾動會非常快。
}
} */
}
void main()
{
init();
while(1)
{
display();
}
}
復(fù)制代碼
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1