LED和数码管同时点亮问题

syd syd 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
at89s52单片机,有74hc138译码器,这是我编写的小程序,但希望LED流水灯和数码管同时变换,想了好久也没想出来如何实现,流程图也画了,实验了好多次,哪位高手给指点指点,LED流水灯和数码管同时变换。

/************************************************************************
工程名称:LEDflash AND Digitron
工程功能:花样流水灯和动态数码管变换
时 间: 2012-04-28
作 者:syd989
*************************************************************************/
#include<at89x52.h>
#define num 6 //流水灯样式
unsigned char code tab[]={ //数码管选值
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71
};
unsigned char code tab1[]={0xe4,0xe3,0xe2,0xe1}; //74hc138译码器选址
code unsigned char tab3[num][8]=
{
{0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}, //逐个亮
{0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff}, //逐一亮
{0xff,0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01}, //逐个灭
{0x81,0xc3,0xe7,0xff,0xe7,0xc3,0x81,0x00}, //两端亮中间灭
{0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff}, //左端逐一亮
{0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff}, //右端逐一亮
};
void delay(unsigned int z); //不精确延时函数声明
void LED(); //花样LED流水灯函数声明
void shuma(); //动态扫描数码管变换

void main() //主函数 调用LED()和shuma()函数
{
while(1)
{
LED();
shuma();
}
}
void delay(unsigned int z) //不精确延时
{
unsigned int x,y;
for(x=z;x>0;x--)
for(y=120;y>0;y--);
}

void LED()
{
unsigned int i,j;
P2=0xe0; //74hc138使能
P1=0x00;
for(j=0;j<num;j++) //花样LED流水灯
{
for(i=0;i<8;i++)
{
P1=tab3[j][i];
delay(40);
}
}
}

void shuma()
{
unsigned int m,n;
for(m=0;m<16;m++) //动态扫描数码管变换
{
for(n=0;n<4;n++)
{
P2=tab1[n];
P1=tab[m];
delay(30);
}
}
}
/************************************************************************
End of file
*************************************************************************/
...全文

相关推荐

评论 8
收藏 已收藏
分享
返回顶部
syd
单片机/工控 27,522 成员 28,796 内容