永发信息网

51单片机 编写4个LED数码管同时循环显示0—9的数字 的程序。

答案:2  悬赏:60  手机版
解决时间 2021-03-17 04:01
  • 提问者网友:相思似海深
  • 2021-03-16 19:02
51单片机 编写4个LED数码管同时循环显示0—9的数字 的程序。
最佳答案
  • 五星知识达人网友:夜风逐马
  • 2021-03-16 19:32
#include

#define uchar unsigned char
uchar code ledtab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40};//0-9
uchar time,scanled,tiao;
uchar disdat[6]="201803";
void delay(unsigned int x)
{
unsigned int i,j;
for(i=0;i for(j=0;j<120;j++);
}
void t0isr() interrupt 1 //秒计时
{
TH0=0x3c;
TL0=0xb0;
time++;
if(time==20)
{
time=0;
tiao++;
tiao%=10;
}
}

void t1isr() interrupt 3 //显示
{
TH1=0xec;
TL1=0x78;
P2=1< P0=~ledtab[tiao];
scanled++;
scanled%=4;
}
main()
{
TMOD=0x11;
TH0=0x3c;
TL0=0xb0;
TH1=0xec;
TL1=0x78;
TR1=1;
TR0=1;
ET0=1;
ET1=1;
EA=1;
while(1);
}
全部回答
  • 1楼网友:刀戟声无边
  • 2021-03-16 20:25
#include
//-----------------------------------------------
void delay(unsigned int i) //延时
{
unsigned char j;
while(i--) for(j = 0; j < 115; j++);
}
//-----------------------------------------------
void main(void)
{
unsigned char n1;
unsigned char code SEG[] = {
0xc0, 0xf9, 0xa4, 0xb0, 0x99, //0-4
0x92, 0x82, 0xf8, 0x80, 0x90};//5-9
while(1) {
P0 = SEG[n1]; //P0口,外接共阳数码管的段选端
delay(2000);
n1++; if(n1 > 9) n1 = 0;
}
}

4个(任意个)共阳数码管的段选端,接在 P0,其位选,都接电源即可。
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯