求助:怎么实现在循环的时候按下按钮跳出或者复位
#include<reg51.h>#include<intrins.h>
#define uchar unsigned char
#define uint unsigned char
uchar num;
sbit K1=P3^2;
sbit K2=P3^3;
bit states=1,auto_run=1;
void my_delay(uchar set_second);
void Delay1000ms();
void Delay100ms();
void scan_key();
void out_put();
void Auto_watering();
void main()
{
while(1)
{
scan_key();
out_put();
}
}
void scan_key()
{
if(K1==0)
{
P0=0xff;
P1=0xff;
states=~states;
Delay100ms();
while(K1==0);
Delay100ms();
}
if(K2==0)
{
auto_run=~auto_run ;
Delay100ms();
while(K2==0);
Delay100ms();
}
}
void out_put()
{
if(states==0)
{
if(auto_run==0)
{
P0=0xff;
my_delay(100);“这里延时设定很久,我想通过按下K2来跳出这个if的循环”
P0=0x00;
my_delay(100);
}
else
P0=0x0f;
}
else if(states==1)
{
if(auto_run==0)
P1=0x55;
else
P1=0xf0;
}
}
void my_delay(uchar set_second)
{
uchar j;
for(j=0;j<set_second;j++)
{
Delay1000ms();
}
}
void Delay1000ms() //@11.0592MHz
{
unsigned char i, j, k;
_nop_();
i = 8;
j = 1;
k = 243;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
void Auto_watering()
{
P0=0xff;
my_delay(2);
P0=0x00;
my_delay(2);
}
void Delay100ms() //@11.0592MHz
{
unsigned char i, j;
i = 180;
j = 73;
do
{
while (--j);
} while (--i);
}