#include "reg51.h"
#define uchar unsigned char
#define uint unsigned int
***it P0_4=P0^4;
***it P0_5=P0^5;//按键
uchar duan[]={0xc0,0xf9,0xa4,0xb0,0x99,
0x92,0x82,0xf8,0x80,0x90};
uchar wei[]={0x02,0x01};
uint count=0;
void delay(uint t)//延时函数
{
uint i,j;
for(i=0;i
for(j=0;j<255;j++);
}
void
time()//定时器
{
TH1=0x3c;
TL1=0xb0;//50ms
TR1=1;
while(!TF1);
}
void zhongduan1()interrupt 3//中断子程序
{
uchar i;
TH1=0x3c;
TL1=0xb0;
i++;
if(i>3)
{
i=0;
if(P0_4==0)
{
count++;
if(count>60)
count=0;
}
if(P0_5==0)
{
if(count>0)
count--;
else
count=0;
}
}
}
void shuma(uchar num1,uchar num2)//数码管显示函数
{
P2=~wei[num2];
P1=~duan[num1];
delay(20);
}
void main()
{
uchar tab[2];
TMOD=0x10;//T1工作方式1
EA=1;
ET1=1;
while(1)
{
tab[0]=count/10;
tab[1]=count%10;
shuma(tab[1],0);
shuma(tab[0],1);
TR1=1;//中断请求标志位
}
}
怎样改改,可以使当按键一直按下去的时候,只使数加一,而不是一直加。
0