/*-----------------------------------------------
功能:花样灯(实现多种闪烁)
作者:fei yu
日期:2010-6-15
------------------------------------------------*/
#include<reg52.h>
#define uint unsigned int
void delay(uint);
main()
{
uint fre=0x04;
uint fre1,fre2;
uint comp1=0xfe,comp2=0x80;
while(1)
{
/*----------------------------------------------------------------------------------
模块一:循环单向闪烁,只有一个灯亮
执行3次,转入下一种闪烁
----------------------------------------------------------------------------------*/
P1=0xfe;
while(1!=fre--)
{
fre1=0x08;
while(1!=fre1--)
{
delay(30000);
P1<<=1;
P1|=0x01;
if(P1==0x7f)
{
delay(30000);
P1=0xfe;
}
}
}
/*----------------------------------------------------------------------------------
模块2:循环单向闪烁,只有两个灯亮
3次,转入下一种闪烁执行
----------------------------------------------------------------------------------*/
P1=0xfc;
while(3!=fre++)
{
fre2=0x04;
while(1!=fre2--)
{
delay(30000);
P1<<=2;
P1|=0x03;
if(P1==0x3f)
{
delay(30000);
P1=0xfc;
}
}
}
/*----------------------------------------------------------------------------------
模块3:循环往复闪烁,只有一个灯亮
执行3次,转入下一种闪烁
----------------------------------------------------------------------------------*/
P1=0xfe;
fre1=0x04;
while(1!=fre1--)
{
while(P1!=0x7f)
{
delay(30000);
P1<<=1;
P1|=0x01;
}
while(P1!=0xfe)
{
delay(30000);
P1>>=1;
P1|=0x80;
}
}
/*----------------------------------------------------------------------------------
模块4:全亮全灭
执行3次,转入下一模块
----------------------------------------------------------------------------------*/
while(3!=fre1++)
{
delay(30000);
P1=0x00;
delay(30000);
P1=0xff;
}
/*----------------------------------------------------------------------------------
模块5:顺次点亮或者熄灭,
多个灯亮,执行3次,转入下一模块
----------------------------------------------------------------------------------*/
while(1!=fre1--)
{
P1=0xfe;
while(P1!=0x00)
{
delay(30000);
P1<<=1;
}
delay(30000);
P1=0x80;
while(P1!=0xff)
{
delay(30000);
P1>>=1;
P1|=0x80;
}
}
/*----------------------------------------------------------------------------------
模块6:顺次点亮或者熄灭,多个灯亮,
一次点亮两个,执行3次,转入下一模块
----------------------------------------------------------------------------------*/
while(3!=fre1++)
{
P1=0xfc;
while(P1!=0x00)
{
delay(30000);
P1<<=2;
}
delay(30000);
P1=0xc0;
while(P1!=0xff)
{
delay(30000);
P1>>=2;
P1|=0xc0;
}
delay(30000);
}
/*----------------------------------------------------------------------------------
模块7:双端对称往返闪烁
执行3次,进行下一轮循环
----------------------------------------------------------------------------------*/
P1=0x7e;
delay(30000);
while(1!=fre1--)
{
fre2=0x00;
while(6!=fre2++)
{
P1=0xff;
comp1<<=1;
comp1|=0x01;
comp2>>=1;
P1&=comp1;
P1^=comp2;
delay(3000000);
if(P1==0xe7)
{
comp1<<=1;
comp1|=0x01;
comp2>>=1;
}
if(comp2==0x01)
{
comp1=0xfe;
comp2=0x80;
}
}
}
}
}
void delay(uint cnt)
{
while(cnt--);
}
