求解如何让变量暂停
#include<reg51.h>sbit k1=P3^5;
sbit k2=P3^6;
sbit SPK=P3^7;
sbit c1=P1^3;
sbit c2=P1^2;
sbit c3=P1^1;
sbit c4=P1^0;
sbit r1=P1^4;
sbit r2=P1^5;
sbit r3=P1^6;
sbit r4=P1^7;
#define uchar unsigned char
uchar code table[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
#define duanport P0
sbit com1=P2^3;
sbit com2=P2^2;
sbit com3=P2^1;
sbit com4=P2^0;
uchar buff[]={0,0,0,0};
unsigned char ms,mg,ss,sg,aa,key,z;
void delay(uchar i)
{
uchar j,k;
for(j=i;j>0;j--)
for(k=125;k>0;k--);
}
char keyscan()
{
char key;
P1=0x0F;
delay(1);
if(c1==0)
key=0;
else if(c2==0)
key=1;
else if(c3==0)
key=2;
else if(c4==0)
key=3;
else key=16;
P1=0xF0;
delay(1);
if(r1==0)
key=key+0;
else if(r2==0)
key=key+4;
else if(r3==0)
key=key+8;
else if(r4==0)
key=key+12;
else key=16;
return key;
}
char keydown(unsigned char z)
{
z=0;
P1=0xF0;
if(P1!=0xF0)
{
key=keyscan();
if(key<10)
z++;
}
return key;
}
void display()
{
duanport=table[buff[ms]];
com1=0;
delay(5);
com1=1;
duanport=table[buff[mg]];
com2=0;
delay(5);
com2=1;
duanport=table[buff[ss]];
com3=0;
delay(5);
com3=1;
duanport=table[buff[sg]];
com4=0;
delay(5);
com4=1;
}
void main()
{
P3=0xFF;
P1=0xFF;
while(1)
{
ms=keydown(1);
mg=keydown(2);
ss=keydown(3);
sg=keydown(4);
if(k1==1)
{
if(aa==20)
{
aa=0;
sg--;
if(sg==-1)
{sg=9;
ss--;
}
if(ss==-1)
{ss=5;
mg--;
}
if(mg==-1)
{
mg=9;
ms--;
}
if(ms==0)
{
delay(5);
SPK=1;
}
}
if(k2==1)
{
sg=sg;
}
}
}
}
当开关k2闭合时如何让变量sg暂停变值;
加一个内部定时器判定aa到一秒