新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 單片機(jī)學(xué)習(xí)——LED顯示實(shí)驗(yàn)之二

單片機(jī)學(xué)習(xí)——LED顯示實(shí)驗(yàn)之二

作者: 時(shí)間:2016-11-23 來源:網(wǎng)絡(luò) 收藏
題目:在八位LED顯示屏,顯示“HELLO”:1、使“HELLO”字樣閃爍 2、使字樣“HELLO”從左至右滾動(dòng)顯示。并且循環(huán)下去。

解決方案:(C語言編程)

本文引用地址:http://m.butianyuan.cn/article/201611/320188.htm

#include
#include
#define uint unsigned int
#define uchar unsigned char
uchar hello_table[]={0x89,0x86,0xc7,0xc7,0xc0,0xff};
uchar sled_bit_table[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
uchar sled_disp_buff[]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x89,0x86,0xc7,0xc7,0xc0,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
#define sled_dm_port P0
#define sled_wm_port P2
sbit speaker_en_port = P3^7;
sbit le=P3^6;
sbit led_en_port=P2^5;
void display(uchar aa,uchar bb,uchar cc,uchar dd,uchar ee,uchar ba,uchar sh,uchar g);
void delay(uint a) {
uint i,j;
for(j=a;j>0;j--)
for(i=220;i>0;i--);
}
void main()
{
uchar i,j,k,a,b,c,d;
uint count=4;
led_en_port=0;
speaker_en_port = 0;
while(1){
c=5;
while(c){
for(a=0;a<50;a++)
display(5,0,1,2,3,4,5,5);
for(b=0;b<50;b++)
display(5,5,5,5,5,5,5,5);
c--;
}
le=1;
k=16;
while(k) {
for(j=0;j<50;j++){
for(i=0;i<8;i++){
sled_wm_port = 0xff;
sled_dm_port = sled_disp_buff[i+count];
sled_wm_port = sled_bit_table[i];
delay(1);
}
}
count++;
if(count>=8)
count=4;
k--;
}
d=5;
while(d){
for(a=0;a<50;a++)
display(5,0,1,2,3,4,5,5);
for(b=0;b<50;b++)
display(5,5,5,5,5,5,5,5);
d--;
}
}
}
void display(uchar aa,uchar bb,uchar cc,uchar dd,uchar ee,uchar ff,uchar hh,uchar ii)
{
le=1;
P2=sled_bit_table[0];
le=0;
le=1;
P0=hello_table[aa];
le=0;
delay(1);
le=1;
P2=sled_bit_table[1];
le=0;
le=1;
P0=hello_table[bb];
le=0;
delay(1);
le=1;
P2=sled_bit_table[2];
le=0;
le=1;
P0=hello_table[cc];
le=0;
delay(1);
le=1;
P2=sled_bit_table[3];
le=0;
le=1;
P0=hello_table[dd];
le=0;
delay(1);
le=1;
P2=sled_bit_table[4];
le=0;
le=1;
P0=hello_table[ee];
le=0;
delay(1);
le=1;
P2=sled_bit_table[5];
le=0;
le=1;
P0=hello_table[ff];
le=0;
delay(1);
le=1;
P2=sled_bit_table[6];
le=0;
le=1;
P0=hello_table[hh];
le=0;
delay(1);
le=1;
P2=sled_bit_table[7];
le=0;
le=1;
P0=hello_table[ii];
le=0;
delay(1);
}



評(píng)論


技術(shù)專區(qū)

關(guān)閉