出来的效果是
第一次按下按键,LED灯从上到下一个一个亮,
第二次按下,LED灯从下到上两个两个亮,
第三次按下,LED灯一次亮四个,交替闪烁。
有没有大佬帮忙改改程序
#include <reg51.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define false 0
#define true 1
#define key P1 //??
#define LED P0 //?
uchar value=0;
uchar aa=0x01;
uchar bb;
uchar cc;
uint x,y,z;
uint i=1;
uint j=1;
void delay1() //??????
{
uint k,j;
for(j=0;j<10;j++)
for(k=0;k<1000;k++);
}
bit scankey()
{
bit flag=false;
if(key!=0xff)
{
delay1();
if(key!=0xff)
{
while(~key);
flag=true;
}
}
return flag;
}
uchar keyvalue()
{
if(scankey())
value++;
if(value>3) value=0;
return value;
}
void delay(uint i) //??????ims
{
uint k,j;
for(j=0;j<i;j++)
{
keyvalue();//?1ms??????,???????????
for(k=0;k<1000;k++);
}
}
void display1()//?????????
{
x=1;
while(x)
{
LED=~aa;
aa=_crol_(aa,1);
delay(100);
if(value==2)
x=0;
}
}
void display2()//?????????
{
y=1;
while(y)
{
if(i)//??if???aa????,???LED???,??????
{
aa=_cror_(aa,2);
bb=_cror_(aa,1);
bb=aa^bb;
LED=~bb;
delay(100);
aa=bb;
i=0;
}
aa=_cror_(aa,2);
LED=~aa;
delay(100);
if(value==3)
y=0;
}
}
void display3()//???,???
{
z=1;
while(z)
{
if(j)//?????
{
aa=_crol_(aa,2);
cc=_crol_(aa,2);
cc=aa^cc;
LED=~cc;
delay(100);
aa=cc;
j=0;
}
aa=_crol_(aa,4);
LED=~aa;
delay(100);
if(value==0)
z=0;
}
}
void main()
{
while(1)
{
keyvalue();
switch (value)
{
case 1:display1();break;
case 2:display2();break;
case 3:display3();break;
default:LED=0xff;aa=0x01;i=1;j=1;break;//?LED,i,j????
}
}
}
|