标题:在八位LED显现屏,显现“HELLO”:1、使“HELLO”字样闪耀 2、使字样“HELLO”从左至右翻滚显现。而且循环下去。
解决方案:(C言语编程)
#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);
}
声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/fangan/biancheng/260996.html