這個可以透過定時器來實現,比如當按鍵時間小於2秒時,按一次加1,當超過2秒時,沒50毫秒加1實現連加功能。例程如下:
#include
unsigned int a;
unsigned char times;
sbit key=P1^0;
void t0isr() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
times++;
if(times>40)
a++;
printf("%d",a);
}
main()
TMOD=0x21;
TH1=0xfd;
TL1=0xfd;
TR0=1;
TR1=1;
ET0=1;
EA=1;
times=0;
a=0;
while(1)
if(key==0)
while(key==0);
這個可以透過定時器來實現,比如當按鍵時間小於2秒時,按一次加1,當超過2秒時,沒50毫秒加1實現連加功能。例程如下:
#include
unsigned int a;
unsigned char times;
sbit key=P1^0;
void t0isr() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
times++;
if(times>40)
{
a++;
printf("%d",a);
}
}
main()
{
TMOD=0x21;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=0xfd;
TL1=0xfd;
TR0=1;
TR1=1;
ET0=1;
EA=1;
times=0;
a=0;
while(1)
{
if(key==0)
{
a++;
printf("%d",a);
while(key==0);
times=0;
}
}
}