想实现:LED自上而下依次点亮熄灭,然后自下而上依次点亮熄灭,而后齐亮齐灭,
现在问题是:
程序如下:依次点亮熄灭可以,但是不能齐亮齐灭
#include<reg52.h>
#include<intrins.h>
unsigned char LED;
sbit spk=P2^0;
void yanshi(unsigned int);
void main()
{
LED=0xfe;
P0=LED;
while(1)
{
unsigned int a;
for(a=0;a<7;a++)
{
LED=_crol_(LED,1);
spk=0;
yanshi(50);
P0=LED;
spk=1;
yanshi(50);
}
for(a=7;a>0;a--)
{
LED=_crol_(LED,-1);
spk=0;
yanshi(50);
P0=LED;
spk=1;
yanshi(50);
}
for(a=0;a<4;a++)
{
LED=0x00;
spk=0;
yanshi(50);
LED=0xff;
spk=1;
yanshi(50);
}
}
}
void yanshi(unsigned int z)
{
unsigned int x,y;
for(x=0;x<z;x++)
for(y=1000;y>0;--y);
}
仿真电路如下
一周热门 更多>