以前回答过这样的问题。
和本次稍有区别是:以前是用“两个独立按键控制”,启动和暂停,用一个按键控制。
现在,按照楼主的要求,进行了改动,程序如下。
//下面是00-99秒计数的语言C程序。
#include<reg52.h>
#include<intrins.h>
unsigned char i, j;
unsigned char code table[] = {
0xc0, 0xf9, 0xa4, 0xb0, 0x99,
0x92, 0x82, 0xf8, 0x80, 0x90
};
sbit QI_DONG = P1^1;
sbit TING_ZH = P1^2;
sbit QING_LY = P1^3;
bit k;
//---------------------------------------------
void Delay_1ms(unsigned int x)
{
unsigned int i, j;
for(i = 0; i < x; i++) for(j = 0; j <= 148; j++);
}
//---------------------------------------------
void main( )
{
TMOD = 0x01; //;T0定时方式1
TH0 = (65536-50000) / 256; //;50ms@12MHz
TL0 = (65536-50000) % 256;
TR0 = 1; //;定时器初始化结束.
ET0 = 1; //;开启定时中断.
EX0 = 1;
EX1 = 1;
EA = 1;
i = 0;
j = 0;
P0 = 0xC0;
P2 = 0xC0;
while(1) {
if (QI_DONG == 0) {
Delay_1ms(10); while(QI_DONG == 0); k = 1;
}
if (TING_ZH == 0) {
Delay_1ms(10); while(TING_ZH == 0); k = 0;
}
if (QING_LY == 0) {
Delay_1ms(10); while(QING_LY == 0);
i = 0; j = 0; P0 = 0xC0; P2 = 0xC0;
}
}
}
//---------------------------------------------
void timer0(void) interrupt 1
{
TL0 = (65536-50000) % 256;
TH0 = (65536-50000) / 256; //;50ms@12MHz
if (k) {
j++;
if (j == 20) {
j = 0;
i++;
if (i == 100) i = 0;
P0 = table[i / 10];
P2 = table[i % 10];
}
}
}
//---------------------------------------------
本程序,经过了PROTEUS检验,截屏如下图。