include"reg52.h"
define uchar unsigned char
uchar i;//LED计数用
void Delay(unsigned int x)//这里不能用unsigned char 因为char不能存储超过255的数(延时用的5位数)
{
while(x--);
while(x--);
}
void SelectHC573(uchar n)
{
switch(n)
{
case 4:
P2=(P2 & 0x1f)|0x80;
break;
case 5:
P2=(P2 & 0x1f)|0xa0;
break;
case 6:
P2=(P2 & 0x1f)|0xc0;
break;
case 7:
P2=(P2 & 0x1f)|0xe0;
break;
case 0://关闭所有锁存器
P2=(P2 & 0x1f)|0x00;
break;
}
}
void LEDRunning()
{
SelectHC573(4);
for(i=0;i<3;i++)//闪烁3遍
{
P0=0x00;
Delay(60000);
Delay(60000);
P0=0xff;
Delay(60000);
Delay(60000);
}
for(i=1;i<=8;i++)//从L1到L8依次点亮
{
P0=0xff<<i;
Delay(60000);
Delay(60000);
}
for(i=1;i<=8;i++)//从L1到L8依次熄灭
{
P0=~(0xff<<i);
Delay(60000);
Delay(60000);
}
}
void main()
{
while(1)
{
LEDRunning();
}
}