51单片机怎么用一个按键控两个数码管,按一下改变两个数字的显示速度
51单片机怎么用一个按键控两个数码管,按一下改变两个数字的显示速度,速度变为越来越快,或越来越慢?...
51单片机怎么用一个按键控两个数码管,按一下改变两个数字的显示速度,速度变为越来越快,或越来越慢?
展开
展开全部
#include<reg51.h>
#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,dattop=10,cnt=0;
sbit keyu=P1^0;
sbit keyd=P1^1;
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;
}
}
void t1isr() interrupt 3
{
TH1=(65536-10000)/256;
TL1=(65536-10000)%256;
cnt++;
if(cnt>=dattop)
{
cnt=0;
dat++;
dat%=100;
}
}
main()
{
TMOD=0x11;
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
TH1=(65536-10000)/256;
TL1=(65536-10000)%256;
TR1=1;
ET1=1;
TR0=1;
ET0=1;
EA=1;
while(1)
{
if(keyu==0)
{
while(keyu==0);
if(dattop<100)dattop++;
}
if(keyd==0)
{
while(keyd==0);
if(dattop>0)dattop--;
}
}
}
#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,dattop=10,cnt=0;
sbit keyu=P1^0;
sbit keyd=P1^1;
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;
}
}
void t1isr() interrupt 3
{
TH1=(65536-10000)/256;
TL1=(65536-10000)%256;
cnt++;
if(cnt>=dattop)
{
cnt=0;
dat++;
dat%=100;
}
}
main()
{
TMOD=0x11;
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
TH1=(65536-10000)/256;
TL1=(65536-10000)%256;
TR1=1;
ET1=1;
TR0=1;
ET0=1;
EA=1;
while(1)
{
if(keyu==0)
{
while(keyu==0);
if(dattop<100)dattop++;
}
if(keyd==0)
{
while(keyd==0);
if(dattop>0)dattop--;
}
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询