微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 单片机学习——LED显示实验之二

单片机学习——LED显示实验之二

时间:11-23 来源:互联网 点击:
题目:在八位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);
}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top