大佬求教
这是我写的关于控制流水灯流速的单片机代码。但是不知为何再次按下按键,没有跳入下一个流速。这是为什么呢?
#include<reg51.h>
#define uchar unsigned char
sfr p1=0x90;
sbit p3_0=0xb0;
sbit p3_1=0xb1;
sbit p3_2=0xb2;
sbit p3_3=0xb3;
unsigned int i,j,k;
uchar timeCnt=0;
void delay(i)
{
while(i--);
}
void shanshuo1()
{
p1=~0x01;delay(5000);
for(j=0;j<3;j++)
{
p1=~(0x01<<j);delay(5000);
if(j==2)
{
p1=~0x01;delay(5000);
j=0;
}
}
}
void shanshuo2()
{
p1=~0x01;delay(50000);
for(j=0;j<3;j++)
{
p1=~(0x01<<j);delay(50000);
if(j==2)
{
p1=~0x01;delay(50000);
j=0;
}
}
}
void shanshuo3()
{
p1=~0x01;delay(100000);
for(j=0;j<3;j++)
{
p1=~(0x01<<j);delay(100000);
if(j==2)
{
p1=~0x01;delay(100000);
j=0;
}
}
}
void main()
{
while(1)
{
if(p3_0==0)
{
timeCnt++;
if(timeCnt==4) timeCnt=0;
}
if(timeCnt==1) shanshuo1();
if(timeCnt==2) shanshuo2();
if(timeCnt==3) shanshuo3();
}
}
|