用89C52单片机共阴极, 让数码管第一第二位间隔500ms从0显示到20,然后从20显示到0
答案:1 悬赏:60 手机版
解决时间 2021-04-08 14:47
- 提问者网友:呐年旧曙光
- 2021-04-07 13:50
用89C52单片机共阴极, 让数码管第一第二位间隔500ms从0显示到20,然后从20显示到0
最佳答案
- 五星知识达人网友:猎心人
- 2021-04-07 14:38
#include
#define uchar unsigned char;
uchar distab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00}; //0到f
uchar number,dat,time=0;
bit flag=0;
void t0isr() interrupt 1
{
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
number++;
if(number>1)number=0;
switch(number)
{
case 0:P2=0x02;P0=distab[dat/10];
break;
case 1:P2=0x01;P0=distab[dat%10];
break;
default:break;
}
time++;
if(time>=200)
{
time=0;
if(flag==0)
{
dat++;
if(dat>>=20)
flag=1;
}
if(flag==1)
{
dat--;
if(dat==0)flag=1;
}
}
}
main()
{
TMOD=0x61;
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
TR0=1;
ET0=1;
EA=1;
while(1);
}
#define uchar unsigned char;
uchar distab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00}; //0到f
uchar number,dat,time=0;
bit flag=0;
void t0isr() interrupt 1
{
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
number++;
if(number>1)number=0;
switch(number)
{
case 0:P2=0x02;P0=distab[dat/10];
break;
case 1:P2=0x01;P0=distab[dat%10];
break;
default:break;
}
time++;
if(time>=200)
{
time=0;
if(flag==0)
{
dat++;
if(dat>>=20)
flag=1;
}
if(flag==1)
{
dat--;
if(dat==0)flag=1;
}
}
}
main()
{
TMOD=0x61;
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
TR0=1;
ET0=1;
EA=1;
while(1);
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯