69,775
社区成员
按键后一直循环执行不了下一个语句
#include <reg51.h>
#include "key.h"
#include <INTRINS.H>
#include "Delay.h"
unsigned char keynum,ledmod;
void led1()
{
unsigned char i;
P1=0xfe;
P2=0xfe;
for(i=0;i<=7;i++)
{
P1=_crol_(P1,1);
P2=_crol_(P2,1);
Delay(100);
}
i=0;
}
void led2()
{
unsigned char i;
P1=0x7f;
P2=0x7f;
for(i=0;i<=7;i++)
{
P1=_cror_(P1,1);
P2=_cror_(P2,1);
Delay(100);
}
i=0;
}
void led3()
{
while(1){
unsigned char i;
P1=0xFF;
P2=0xFE;
Delay(100);
for(i=0;i<=6;i++)
{
P2=_crol_(P2,1);
Delay(100);
}
i=0;
P1=0xFe;
P2=0xff;
for(i=0;i<=7;i++)
{
P1=_cror_(P1,1);
Delay(100);
}
i=0;
}
}
void led4()
{
unsigned char i;
P1=0xFE;
P2=0xFF;
Delay(100);
for(i=0;i<=6;i++)
{
P1=_crol_(P1,1);
Delay(100);
}
i=0;
P1=0xFF;
P2=0xfe;
for(i=0;i<=7;i++)
{
P2=_cror_(P2,1);
Delay(100);
}
i=0;
}
void main()
{
while(1)
{
keynum=key();
if(keynum)
{
while(keynum==1){led1();}
while(keynum==2){led2();}
while(keynum==3){led3();}
while(keynum==4){led4();}
}
}
}