给我下面这段程序加一个暂停和清零功能呗
//主程序
#include<reg52.h>
sbit ksec=P3^0;
sbit kmin=P3^1;
sbit khour=P3^2;
unsigned char secshi=0,secge=0,minshi=0,minge=0,hourshi=0,hourge=0;
unsigned int num=0,sec=0,min=0,hour=0;
unsigned char code table[10]={0x3f,0xxx,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void delay(unsigned int);
void keyscan();
void display();
main()
{TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;ET0=1;TR0=1;
while(1)
{display();
keyscan();
}
}
void delay(unsigned int z)
{unsigned int x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);}
//时钟设置子程序
void time0() interrupt 1
{num++;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
}
//定时器中断子程序
void time0() interrupt 1
{num++;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
}
//LED显示子程序
void display()
{if(num==20)
{num=0;
sec++;
if(sec==60)
{sec=0;
min++;
if(min==60)
{min=0;
hour++;
if(hour==24)
{hour=0;
min=0;
sec=0;
}
}
}
}
secge=sec%10;
secshi=sec/10;
minge=min%10;
minshi=min/10;
hourge=hour%10;
hourshi=hour/10;
P2=0xfe;
P0=table[secge];
delay(5);
P2=0xfd;
P0=table[secshi];
delay(5);
P2=0xfb;
P0=0x40;
delay(5);
P2=0xf7;
P0=table[minge];
delay(5);
P2=0xef;
P0=table[minshi];
delay(5);
P2=0xdf;
P0=0x40;
delay(5);
P2=0xbf;
P0=table[hourge];
delay(5);
P2=0x7f;
P0=table[hourshi];
delay(5);
}
//按键控制子程序
void keyscan()
{if(ksec==0)
{delay(10);
if(ksec==0)
{sec++;
if(sec>=60)
sec=0;
}
while(ksec==0)
display();}
if(kmin==0)
{delay(10);
if(kmin==0)
{min++;
if(min>=60)
min=0;
}
while(kmin==0)
display();
}
if(khour==0)
{delay(10);
if(khour==0)
{hour++;
if(hour>=60)
hour=0;
}
while(khour==0)
display();
}
}
此帖出自
小平头技术问答
一周热门 更多>