51爱心流水灯32灯炫酷代码

    源代码摘自@远眺883的文章,大佬是30个灯的,感兴趣的铁汁们可以去看看哦~(已取得原作者的许可):基于STC89C51单片机设计的心形流水灯软件代码部分_单片机流水灯代码_远眺883的博客-CSDN博客

  由于博主是个小菜鸡,所以有些地方改的不好的请多多包容。

  修改方面

  调整了开头单个灯的旋转,并加快了旋转速度,并用appear函数无缝衔接后面的呼吸灯,中间基本没有什么太大的改动,个人觉得时间上比较长,于是缩短了循环的次数,最后的部分也稍微换了一下。

  效果: 

爱心流水灯(32灯)

  源代码分享:

#include 
#include 
 
//LED灯引脚,延逆时针定义
sbit LED1=P0^0;  sbit LED2=P0^1;  sbit LED3=P0^2;  sbit LED4=P0^3;  sbit LED5=P0^4;  sbit LED6=P0^5;  sbit LED7=P0^6;  sbit LED8=P0^7;
sbit LED24=P2^7; sbit LED23=P2^6; sbit LED22=P2^5; sbit LED21=P2^4; sbit LED20=P2^3; sbit LED19=P2^2; sbit LED18=P2^1;
sbit LED17=P2^0; sbit LED32=P3^7;sbit LED31=P3^6;sbit LED30=P3^5; sbit LED29=P3^4; sbit LED28=P3^3; sbit LED27=P3^2; sbit LED26=P3^1; sbit LED25=P3^0;
sbit LED16=P1^7; sbit LED15=P1^6; sbit LED14=P1^5; sbit LED13=P1^4; sbit LED12=P1^3; sbit LED11=P1^2; sbit LED10=P1^1; sbit LED9=P1^0;
 
int time = 0; 	//控制呼吸灯亮灯时间
int	mode = 0;  	//呼吸灯模式(渐亮到渐暗)
int i, j;  		//循环变量
 
//10us延时函数
void Delay(int us)		//@12.000MHz
{
	while(us--)
	{
		unsigned char i;
 
		_nop_();
		i = 2;
		while (--i);
	}
}
 
//全开
void turn_on(void)
{
	LED9=1;  LED10=1; LED11=1; LED12=1; LED13=1; LED14=1; LED15=1; LED16=1;
	LED25=1; LED26=1; LED27=1; LED28=1; LED29=1; LED30=1;LED31=1;LED32=1;
	LED17=1; LED18=1; LED19=1; LED20=1; LED21=1; LED22=1; LED23=1; LED24=1;
	LED8=1;  LED7=1;  LED6=1;  LED5=1;  LED4=1;  LED3=1;  LED2=1;  LED1=1;
}
 
//全关
void turn_off(void)
{
	LED9=0;  LED10=0; LED11=0; LED12=0; LED13=0; LED14=0; LED15=0; LED16=0;
	LED25=0; LED26=0; LED27=0; LED28=0; LED29=0; LED30=0;LED31=0;LED32=0;
	LED17=0; LED18=0; LED19=0; LED20=0; LED21=0; LED22=0; LED23=0; LED24=0;
	LED8=0;  LED7=0;  LED6=0;  LED5=0;  LED4=0;  LED3=0;  LED2=0;  LED1=0;
}
 
//流水灯
void run_LED(void)
{
	//顺时针流水灯
	for(i = 0; i < 1; i++)
	{
		LED9=1;		Delay(2000);
		LED10=1;	Delay(2000);
		LED11=1;	Delay(2000);
		LED12=1;	Delay(2000);
		LED13=1;	Delay(2000);
		LED14=1;	Delay(2000);
		LED15=1;	Delay(2000);
		LED16=1;	Delay(2000);
		LED25=1;	Delay(2000);
		LED26=1;	Delay(2000);
		LED27=1;	Delay(2000);
		LED28=1;	Delay(2000);
		LED29=1;	Delay(2000);
		LED30=1;	Delay(2000);
		LED31=1;	Delay(2000);
		LED32=1;	Delay(2000);
		LED17=1;	Delay(2000);
		LED18=1;	Delay(2000);
		LED19=1;	Delay(2000);
		LED20=1;	Delay(2000);
		LED21=1;	Delay(2000);
		LED22=1;	Delay(2000);
			LED23=1;	Delay(2000);
		LED24=1;	Delay(2000);
		LED8=1;		Delay(2000);
		LED7=1;		Delay(2000);
			LED6=1;		Delay(2000);
		LED5=1;		Delay(2000);
		LED4=1;		Delay(2000);
		LED3=1;		Delay(2000);
		LED2=1;		Delay(2000);
		LED1=1;		Delay(2000);
		
		LED9=0;		Delay(2000);
		LED10=0;	Delay(2000);
		LED11=0;	Delay(2000);
		LED12=0;	Delay(2000);
		LED13=0;	Delay(2000);
		LED14=0;	Delay(2000);
		LED15=0;	Delay(2000);
		LED16=0;	Delay(2000);
		LED25=0;	Delay(2000);
		LED26=0;	Delay(2000);
		LED27=0;	Delay(2000);
		LED28=0;	Delay(2000);
		LED29=0;	Delay(2000);
		LED30=0;	Delay(2000);
		LED31=0;	Delay(2000);
		LED32=0;	Delay(2000);
		LED17=0;	Delay(2000);
		LED18=0;	Delay(2000);
		LED19=0;	Delay(2000);
		LED20=0;	Delay(2000);
		LED21=0;	Delay(2000);
		LED22=0;	Delay(2000);
		LED23=0;	Delay(2000);
		LED24=0;	Delay(2000);
		LED8=0;		Delay(2000);
		LED7=0;		Delay(2000);
		LED6=0;		Delay(2000);
		LED5=0;		Delay(2000);
		LED4=0;		Delay(2000);
		LED3=0;		Delay(2000);
		LED2=0;		Delay(2000);
		LED1=0;		Delay(2000);
	}
	
	//逆时针流水灯
	for(i = 0; i < 1; i++)
	{
		LED1=1;		Delay(2000);
		LED2=1;		Delay(2000);
		LED3=1;		Delay(2000);
		LED4=1;		Delay(2000);
		LED5=1;		Delay(2000);
		LED6=1;		Delay(2000);
		LED7=1;		Delay(2000);
		LED8=1;		Delay(2000);
		LED24=1;	Delay(2000);
		LED23=1;	Delay(2000);
		LED22=1;	Delay(2000);
		LED21=1;	Delay(2000);
		LED20=1;	Delay(2000);
		LED19=1;	Delay(2000);
		LED18=1;	Delay(2000);
		LED17=1;	Delay(2000);
		LED32=1;	Delay(2000);
		LED31=1;	Delay(2000);
		LED30=1;	Delay(2000);
		LED29=1;	Delay(2000);
		LED28=1;	Delay(2000);
		LED27=1;	Delay(2000);
		LED26=1;	Delay(2000);
		LED25=1;	Delay(2000);
		LED16=1;	Delay(2000);
		LED15=1;	Delay(2000);
		LED14=1;	Delay(2000);
		LED13=1;	Delay(2000);
		LED12=1;	Delay(2000);
		LED11=1;	Delay(2000);
		LED10=1;	Delay(2000);
		LED9=1;		Delay(2000);
 
		LED1=0;		Delay(2000);
		LED2=0;		Delay(2000);
		LED3=0;		Delay(2000);
		LED4=0;		Delay(2000);
		LED5=0;		Delay(2000);
		LED6=0;		Delay(2000);
		LED7=0;		Delay(2000);
		LED8=0;		Delay(2000);
		LED24=0;	Delay(2000);
		LED23=0;	Delay(2000);
		LED22=0;	Delay(2000);
		LED21=0;	Delay(2000);
		LED20=0;	Delay(2000);
		LED19=0;	Delay(2000);
		LED18=0;	Delay(2000);
		LED17=0;	Delay(2000);
		LED32=0;	Delay(2000);
		LED31=0;	Delay(2000);
		LED30=0;	Delay(2000);
		LED29=0;	Delay(2000);
		LED28=0;	Delay(2000);
		LED27=0;	Delay(2000);
		LED26=0;	Delay(2000);
		LED25=0;	Delay(2000);
		LED16=0;	Delay(2000);
		LED15=0;	Delay(2000);
		LED14=0;	Delay(2000);
		LED13=0;	Delay(2000);
		LED12=0;	Delay(2000);
		LED11=0;	Delay(2000);
		LED10=0;	Delay(2000);
		LED9=0;		Delay(2000);
	}
}
 
void run_LED_2(void)
{
	//顺时针流水灯
	for(i = 0; i < 1; i++)
	{
		LED9=1;		Delay(2000);
		LED10=1;	Delay(2000);
		LED11=1;	Delay(2000);
		LED12=1;	Delay(2000);
		LED13=1;	Delay(2000);
		LED14=1;	Delay(2000);
		LED15=1;	Delay(2000);
		LED16=1;	Delay(2000);
		LED25=1;	Delay(2000);
		LED26=1;	Delay(2000);
		LED27=1;	Delay(2000);
		LED28=1;	Delay(2000);
		LED29=1;	Delay(2000);
		LED30=1;	Delay(2000);
		LED31=1;	Delay(2000);
		LED32=1;	Delay(2000);
		LED17=1;	Delay(2000);
		LED18=1;	Delay(2000);
		LED19=1;	Delay(2000);
		LED20=1;	Delay(2000);
		LED21=1;	Delay(2000);
		LED22=1;	Delay(2000);
		LED23=1;	Delay(2000);
		LED24=1;	Delay(2000);
		LED8=1;		Delay(2000);
		LED7=1;		Delay(2000);
		LED6=1;		Delay(2000);
		LED5=1;		Delay(2000);
		LED4=1;		Delay(2000);
		LED3=1;		Delay(2000);
		LED2=1;		Delay(2000);
		LED1=1;		Delay(2000);
		
		LED9=0;		Delay(2000);
		LED10=0;	Delay(2000);
		LED11=0;	Delay(2000);
		LED12=0;	Delay(2000);
		LED13=0;	Delay(2000);
		LED14=0;	Delay(2000);
		LED15=0;	Delay(2000);
		LED16=0;	Delay(2000);
		LED25=0;	Delay(2000);
		LED26=0;	Delay(2000);
		LED27=0;	Delay(2000);
		LED28=0;	Delay(2000);
		LED29=0;	Delay(2000);
		LED30=0;	Delay(2000);
		LED31=0;	Delay(2000);
		LED32=0;	Delay(2000);
		LED17=0;	Delay(2000);
		LED18=0;	Delay(2000);
		LED19=0;	Delay(2000);
		LED20=0;	Delay(2000);
		LED21=0;	Delay(2000);
		LED22=0;	Delay(2000);
		LED23=0;	Delay(2000);
		LED24=0;	Delay(2000);
		LED8=0;		Delay(2000);
		LED7=0;		Delay(2000);
		LED6=0;		Delay(2000);
		LED5=0;		Delay(2000);
		LED4=0;		Delay(2000);
		LED3=0;		Delay(2000);
		LED2=0;		Delay(2000);
		LED1=0;		Delay(2000);
		
		//逆时针流水灯
		LED1=1;		Delay(2000);
		LED2=1;		Delay(2000);
		LED3=1;		Delay(2000);
		LED4=1;		Delay(2000);
		LED5=1;		Delay(2000);
		LED6=1;		Delay(2000);
		LED7=1;		Delay(2000);
		LED8=1;		Delay(2000);
		LED24=1;	Delay(2000);
		LED23=1;	Delay(2000);
		LED22=1;	Delay(2000);
		LED21=1;	Delay(2000);
		LED20=1;	Delay(2000);
		LED19=1;	Delay(2000);
		LED18=1;	Delay(2000);
		LED17=1;	Delay(2000);
		LED32=1;	Delay(2000);
		LED31=1;	Delay(2000);
		LED30=1;	Delay(2000);
		LED29=1;	Delay(2000);
		LED28=1;	Delay(2000);
		LED27=1;	Delay(2000);
		LED26=1;	Delay(2000);
		LED25=1;	Delay(2000);
		LED16=1;	Delay(2000);
		LED15=1;	Delay(2000);
		LED14=1;	Delay(2000);
		LED13=1;	Delay(2000);
		LED12=1;	Delay(2000);
		LED11=1;	Delay(2000);
		LED10=1;	Delay(2000);
		LED9=1;		Delay(2000);
 
		LED1=0;		Delay(2000);
		LED2=0;		Delay(2000);
		LED3=0;		Delay(2000);
		LED4=0;		Delay(2000);
		LED5=0;		Delay(2000);
		LED6=0;		Delay(2000);
		LED7=0;		Delay(2000);
		LED8=0;		Delay(2000);
		LED24=0;	Delay(2000);
		LED23=0;	Delay(2000);
		LED22=0;	Delay(2000);
		LED21=0;	Delay(2000);
		LED20=0;	Delay(2000);
		LED19=0;	Delay(2000);
		LED18=0;	Delay(2000);
		LED17=0;	Delay(2000);
		LED32=0;	Delay(2000);
		LED31=0;	Delay(2000);
		LED30=0;	Delay(2000);
		LED29=0;	Delay(2000);
		LED28=0;	Delay(2000);
		LED27=0;	Delay(2000);
		LED26=0;	Delay(2000);
		LED25=0;	Delay(2000);
		LED16=0;	Delay(2000);
		LED15=0;	Delay(2000);
		LED14=0;	Delay(2000);
		LED13=0;	Delay(2000);
		LED12=0;	Delay(2000);
		LED11=0;	Delay(2000);
		LED10=0;	Delay(2000);
		LED9=0;		Delay(2000);
	}
}
 
 
//呼吸灯部分
void breathe_LED(void)
{
	for(i = 0; i < 300; i++)
	{
		//全开
		turn_on();
		Delay(16 * time);
		//全关
		turn_off();
		Delay(16 * (50 - time));
		
		if(mode == 0)	
			time++;
		else if(mode == 1)
			time--;
		
		if(time >= 50 || time <= 0)
		{
			mode++;
			mode %= 2;
		}
	}
}
 
//上下往返
void fall_rise_LED(void)
{
	for(i = 0; i < 2; i++)
	{
		//初始时全关闭
		turn_off();
		Delay(10000);
		//从上至下
		LED9=1;  LED1=1;	Delay(2000);
		LED10=1; LED2=1;	Delay(2000);
		LED11=1; LED3=1;	Delay(2000);
		LED12=1; LED4=1;	Delay(2000);
		LED13=1; LED5=1;	Delay(2000);
		LED14=1; LED6=1;	Delay(2000);
		LED15=1; LED7=1;	Delay(2000);
		LED16=1; LED8=1;	Delay(2000);
		LED25=1; LED24=1;	Delay(2000);
		LED26=1; LED23=1;	Delay(2000);
		LED27=1; LED22=1;	Delay(2000);
		LED28=1; LED21=1;	Delay(2000);
		LED29=1; LED20=1;	Delay(2000);
		LED30=1; LED19=1;	Delay(2000);
		LED31=1; LED18=1;	Delay(2000);
		LED32=1; LED17=1;	Delay(2000);
		LED17=1; LED16=1;	Delay(2000);
		//闪烁两次
		for(j = 0; j < 2; j++)
		{
			//全关
			turn_off();
			Delay(10000);
			//全开
			turn_on();
			Delay(10000);
		}
		//全关
		turn_off();
		//从上至下
		LED17=1; LED16=1;	Delay(2000);
		LED32=1; LED17=1;	Delay(2000);
		LED31=1; LED18=1;	Delay(2000);
		LED30=1; LED19=1;	Delay(2000);
		LED29=1; LED20=1;	Delay(2000);
		LED28=1; LED21=1;	Delay(2000);
		LED27=1; LED22=1;	Delay(2000);
		LED26=1; LED23=1;	Delay(2000);
		LED25=1; LED24=1;	Delay(2000);
		LED16=1; LED8=1;	Delay(2000);
		LED15=1; LED7=1;	Delay(2000);
		LED14=1; LED6=1;	Delay(2000);
		LED13=1; LED5=1;	Delay(2000);
		LED12=1; LED4=1;	Delay(2000);
		LED11=1; LED3=1;	Delay(2000);
		LED10=1; LED2=1;	Delay(2000);
		LED9=1;  LED1=1;	Delay(2000);
		for(j = 0; j < 2; j++)
		{
			//全关
			turn_off();
			Delay(10000);
			//全开
			turn_on();
			Delay(10000);
		}
	}
}
 
//满天星
void star_LED(void)
{
	for(i = 0; i < 15; i++)
	{
		//正
		LED9=1;  LED10=0; LED11=1; LED12=0; LED13=1; LED14=0; LED15=1; LED16=0;
		LED25=1; LED26=0; LED27=1; LED28=0; LED29=1; LED30=0;LED31=1;LED32=0;
		LED17=1; LED18=0; LED19=1; LED20=0; LED21=1; LED22=0; LED23=1; LED24=0;
		LED8=1;  LED7=0;  LED6=1;  LED5=0;  LED4=1;  LED3=0;  LED2=1;  LED1=0;
		Delay(6000);
		//反
		LED9=0;  LED10=1; LED11=0; LED12=1; LED13=0; LED14=1; LED15=0; LED16=1;
		LED25=0; LED26=1; LED27=0; LED28=1; LED29=0; LED30=1;LED31=0;LED32=1;
		LED17=0; LED18=1; LED19=0; LED20=1; LED21=0; LED22=1; LED23=0; LED24=1;
		LED8=0;  LED7=1;  LED6=0;  LED5=1;  LED4=0;  LED3=1;  LED2=0;  LED1=1;
		Delay(6000);
	}
}
 
//双线环绕
void chase_LED(void)
{
	LED9=0;	 LED18=0;	Delay(2000);
	LED10=0; LED19=0;	Delay(2000);
	LED11=0; LED20=0;	Delay(2000);
	LED12=0; LED21=0;	Delay(2000);
	LED13=0; LED22=0;	Delay(2000);
	LED14=0; LED23=0;	Delay(2000);
	LED15=0; LED24=0;	Delay(2000);
	LED16=0; LED10=0;	Delay(2000);
	LED25=0; LED9=0;	Delay(2000);
	LED26=0; LED8=0;	Delay(2000);
	LED27=0; LED7=0;	Delay(2000);
	LED28=0; LED6=0;	Delay(2000);
	LED29=0; LED5=0;	Delay(2000);
	LED30=0; LED4=0;	Delay(2000);
	LED31=0; LED3=0;	Delay(2000);
	LED32=0; LED2=0;	Delay(2000);
	LED17=0; LED1=0;	Delay(2000);
	
	LED9=1;	 LED18=1;	Delay(2000);
	LED10=1; LED19=1;	Delay(2000);
	LED11=1; LED20=1;	Delay(2000);
	LED12=1; LED21=1;	Delay(2000);
	LED13=1; LED22=1;	Delay(2000);
	LED14=1; LED23=1;	Delay(2000);
	LED15=1; LED24=1;	Delay(2000);
	LED16=1; LED10=1;	Delay(2000);
	LED25=1; LED9=1;	Delay(2000);
	LED26=1; LED8=1;	Delay(2000);
	LED27=1; LED7=1;	Delay(2000);
	LED28=1; LED6=1;	Delay(2000);
	LED29=1; LED5=1;	Delay(2000);
	LED30=1; LED4=1;	Delay(2000);
	LED31=1; LED3=1;	Delay(2000);
	LED32=1; LED2=1;	Delay(2000);
	LED17=1; LED1=1;	Delay(2000);
	
	Delay(12000);
}
 
//反双线环绕
void chase_LED_reverse(void)
{
	LED17=0; LED1=0;	Delay(2000);
	LED32=0; LED2=0;	Delay(2000);
	LED31=0; LED3=0;	Delay(2000);
	LED30=0; LED4=0;	Delay(2000);
	LED29=0; LED5=0;	Delay(2000);
	LED28=0; LED6=0;	Delay(2000);
	LED27=0; LED7=0;	Delay(2000);
	LED26=0; LED8=0;	Delay(2000);
	LED25=0; LED9=0;	Delay(2000);
	LED16=0; LED10=0;	Delay(2000);
	LED15=0; LED24=0;	Delay(2000);
	LED14=0; LED23=0;	Delay(2000);
	LED13=0; LED22=0;	Delay(2000);
	LED12=0; LED21=0;	Delay(2000);
	LED11=0; LED20=0;	Delay(2000);
	LED10=0; LED19=0;	Delay(2000);
	LED9=0;	 LED18=0;	Delay(2000);
	
	LED17=1; LED1=1;	Delay(2000);
	LED32=1; LED2=1;	Delay(2000);
	LED31=1; LED3=1;	Delay(2000);
	LED30=1; LED4=1;	Delay(2000);
	LED29=1; LED5=1;	Delay(2000);
	LED28=1; LED6=1;	Delay(2000);
	LED27=1; LED7=1;	Delay(2000);
	LED26=1; LED8=1;	Delay(2000);
	LED25=1; LED9=1;	Delay(2000);
	LED16=1; LED10=1;	Delay(2000);
	LED15=1; LED24=1;	Delay(2000);
	LED14=1; LED23=1;	Delay(2000);
	LED13=1; LED22=1;	Delay(2000);
	LED12=1; LED21=1;	Delay(2000);
	LED11=1; LED20=1;	Delay(2000);
	LED10=1; LED19=1;	Delay(2000);
	LED9=1;	 LED18=1;	Delay(2000);
	
	Delay(12000);
}
 
//双线往返环绕
void chase_LED_back(void)
{
	LED17=0; LED1=0;	Delay(2000);
	LED32=0; LED2=0;	Delay(2000);
	LED31=0; LED3=0;	Delay(2000);
	LED30=0; LED4=0;	Delay(2000);
	LED29=0; LED5=0;	Delay(2000);
	LED28=0; LED6=0;	Delay(2000);
	LED27=0; LED7=0;	Delay(2000);
	LED26=0; LED8=0;	Delay(2000);
	LED25=0; LED9=0;	Delay(2000);
	LED16=0; LED10=0;	Delay(2000);
	LED15=0; LED24=0;	Delay(2000);
	LED14=0; LED23=0;	Delay(2000);
	LED13=0; LED22=0;	Delay(2000);
	LED12=0; LED21=0;	Delay(2000);
	LED11=0; LED20=0;	Delay(2000);
	LED10=0; LED19=0;	Delay(2000);
	LED9=0;	 LED18=0;	Delay(2000);
	
	LED9=1;	 LED18=1;	Delay(2000);
	LED10=1; LED19=1;	Delay(2000);
	LED11=1; LED20=1;	Delay(2000);
	LED12=1; LED21=1;	Delay(2000);
	LED13=1; LED22=1;	Delay(2000);
	LED14=1; LED23=1;	Delay(2000);
	LED15=1; LED24=1;	Delay(2000);
	LED16=1; LED10=1;	Delay(2000);
	LED25=1; LED9=1;	Delay(2000);
	LED26=1; LED8=1;	Delay(2000);
	LED27=1; LED7=1;	Delay(2000);
	LED28=1; LED6=1;	Delay(2000);
	LED29=1; LED5=1;	Delay(2000);
	LED30=1; LED4=1;	Delay(2000);
	LED31=1; LED3=1;	Delay(2000);
	LED32=1; LED2=1;	Delay(2000);
	LED17=1; LED1=1;	Delay(2000);
	
	Delay(12000);
}
 
//反双线往返环绕
void chase_LED_back_reverse(void)
{
	LED9=0;	 LED18=0;	Delay(2000);
	LED10=0; LED19=0;	Delay(2000);
	LED11=0; LED20=0;	Delay(2000);
	LED12=0; LED21=0;	Delay(2000);
	LED13=0; LED22=0;	Delay(2000);
	LED14=0; LED23=0;	Delay(2000);
	LED15=0; LED24=0;	Delay(2000);
	LED16=0; LED10=0;	Delay(2000);
	LED25=0; LED9=0;	Delay(2000);
	LED26=0; LED8=0;	Delay(2000);
	LED27=0; LED7=0;	Delay(2000);
	LED28=0; LED6=0;	Delay(2000);
	LED29=0; LED5=0;	Delay(2000);
	LED30=0; LED4=0;	Delay(2000);
	LED31=0; LED3=0;	Delay(2000);
	LED32=0; LED2=0;	Delay(2000);
	LED17=0; LED1=0;	Delay(2000);
	
	LED17=1; LED1=1;	Delay(2000);
	LED32=1; LED2=1;	Delay(2000);
	LED31=1; LED3=1;	Delay(2000);
	LED30=1; LED4=1;	Delay(2000);
	LED29=1; LED5=1;	Delay(2000);
	LED28=1; LED6=1;	Delay(2000);
	LED27=1; LED7=1;	Delay(2000);
	LED26=1; LED8=1;	Delay(2000);
	LED25=1; LED9=1;	Delay(2000);
	LED16=1; LED10=1;	Delay(2000);
	LED15=1; LED24=1;	Delay(2000);
	LED14=1; LED23=1;	Delay(2000);
	LED13=1; LED22=1;	Delay(2000);
	LED12=1; LED21=1;	Delay(2000);
	LED11=1; LED20=1;	Delay(2000);
	LED10=1; LED19=1;	Delay(2000);
	LED9=1;	 LED18=1;	Delay(2000);
	
	Delay(12000);
}
 
//延时控制变量
int one_time = 1500;
 

void one_LED(void)
{	
	if(one_time > 10)
	{
        //单灯绕圈
		LED25=0; LED16=1;	Delay(one_time);
		LED26=0; LED25=1;	Delay(one_time);
		LED27=0; LED26=1;	Delay(one_time);
		LED28=0; LED27=1;	Delay(one_time);
		LED29=0; LED28=1;	Delay(one_time);
		LED30=0; LED29=1;	Delay(one_time);
		LED31=0; LED30=1;	Delay(one_time);
		LED32=0; LED31=1;	Delay(one_time);
		LED17=0; LED32=1;	Delay(one_time);
		LED18=0; LED17=1;	Delay(one_time);
		LED19=0; LED18=1; 	Delay(one_time);
		LED20=0; LED19=1;	Delay(one_time);
		LED21=0; LED20=1; 	Delay(one_time);
		LED22=0; LED21=1; 	Delay(one_time);
		LED23=0; LED22=1;	Delay(one_time);
		LED24=0; LED23=1;	Delay(one_time);
		LED8=0;	 LED24=1;	Delay(one_time);
		LED7=0;	 LED8=1;	Delay(one_time);
		LED6=0;	 LED7=1; 	Delay(one_time);
		LED5=0;	 LED6=1;	Delay(one_time);
		LED4=0;	 LED5=1;	Delay(one_time);
		LED3=0;	 LED4=1;	Delay(one_time);
		LED2=0;	 LED3=1;	Delay(one_time);
		LED1=0;	 LED2=1;	Delay(one_time);	
		LED9=0;	 LED1=1;	Delay(one_time);
		LED10=0; LED9=1;	Delay(one_time);
		LED11=0; LED10=1;	Delay(one_time);
		LED12=0; LED11=1;	Delay(one_time);
		LED13=0; LED12=1;	Delay(one_time);
		LED14=0; LED13=1; 	Delay(one_time);
		LED15=0; LED14=1;	Delay(one_time);
				LED16=0; LED15=1;	Delay(one_time);
    //反单灯绕圈

LED16=1; LED15=0;	Delay(one_time);
		LED15=1; LED14=0;	Delay(one_time);
				LED14=1; LED13=0; 	Delay(one_time);
		LED13=1; LED12=0;	Delay(one_time);
		LED12=1; LED11=0;	Delay(one_time);
		LED11=1; LED10=0;	Delay(one_time);
		LED10=1; LED9=0;	Delay(one_time);
		LED9=1;	 LED1=0;	Delay(one_time);
		LED1=1;	 LED2=0;	Delay(one_time);	
		LED2=1;	 LED3=0;	Delay(one_time);
		LED3=1;	 LED4=0;	Delay(one_time);
		LED4=1;	 LED5=0;	Delay(one_time);
		LED5=1;	 LED6=0;	Delay(one_time);
		LED6=1;	 LED7=0; 	Delay(one_time);
		LED7=1;	 LED8=0;	Delay(one_time);
		LED8=1;	 LED24=0;	Delay(one_time);
		LED24=1; LED23=0;	Delay(one_time);
		LED23=1; LED22=0;	Delay(one_time);
		LED22=1; LED21=0; 	Delay(one_time);
		LED21=1; LED20=0; 	Delay(one_time);
		LED20=1; LED18=0; 	Delay(one_time);
		LED18=1; LED17=0;	Delay(one_time);
		LED17=1; LED32=0;	Delay(one_time);
		LED32=1; LED31=0;	Delay(one_time);
		LED31=1; LED30=0;	Delay(one_time);
		LED30=1; LED29=0;	Delay(one_time);
		LED29=1; LED28=0;	Delay(one_time);
		LED28=1; LED27=0;	Delay(one_time);
		LED27=1; LED26=0;	Delay(one_time);
		LED26=1; LED25=0;	Delay(one_time);
				LED25=1; LED16=0;	Delay(one_time);
	}
	else
	{
		for(i = 1; i <= 29; i++)
		{
			//全开
			turn_on();
			Delay(i*10);
			//全关
			turn_off();
			Delay((29 - i)*10);
		}
	}
	
	//当延时时间高于10*10us时
	if(one_time > 100)
	{
		one_time -= 300;  //延时每圈减300
	}
	//当延时在10以上以及100以下时
	else if(one_time > 10 && one_time <= 100)
	{
		one_time -= 3;  //延时每圈减3
	}
	//当延时在10以下或者100以上时
	else
	{
		one_time = 10;  //延时10
	}
}
//从下往上依次亮灯
appear_LED(void)
{
	LED16=0;Delay(3000);
		LED15=0;LED25=0;Delay(3000);
		LED14=0;LED26=0;Delay(3000);
		LED13=0;LED27=0;Delay(3000);
		LED12=0;LED28=0;Delay(3000);
		LED11=0;LED29=0;Delay(3000);
		LED10=0;LED30=0;Delay(3000);
		LED9=0;LED31=0;Delay(3000);
		LED1=0;LED32=0;Delay(3000);
		LED2=0;LED17=0;Delay(3000);
		LED3=0;LED18=0;Delay(3000);
		LED4=0;LED19=0;Delay(3000);
		LED5=0;LED20=0;Delay(3000);
		LED6=0;LED21=0;Delay(3000);
		LED7=0;LED22=0;Delay(3000);
		LED8=0;LED23=0;Delay(3000);
		LED24=0;Delay(3000);
		
}
 
//竖向变换
void vertical_LED(void)
{
    //依次亮起两个灯
	LED9=1;  LED1=1;  LED27=0; LED22=0;	Delay(5000);
	LED10=1; LED2=1;  LED28=0; LED21=0;	Delay(5000);
	LED11=1; LED3=1;  LED29=0; LED20=0;	Delay(5000);
	LED12=1; LED4=1;  LED30=0; LED19=0;	Delay(5000);
	LED13=1; LED5=1;  LED17=0; LED18=0;	Delay(5000);
	LED14=1; LED6=1;  LED9=0;  LED1=0;	Delay(5000);
	LED15=1; LED7=1;  LED10=0; LED2=0;	Delay(5000);
	LED16=1; LED8=1;  LED11=0; LED3=0;	Delay(5000);
	LED25=1; LED24=1; LED12=0; LED4=0;	Delay(5000);
	LED26=1; LED23=1; LED13=0; LED5=0;	Delay(5000);
	LED27=1; LED22=1; LED14=0; LED6=0;	Delay(5000);
	LED28=1; LED21=1; LED15=0; LED7=0;	Delay(5000);
	LED29=1; LED20=1; LED16=0; LED8=0;	Delay(5000);
	LED30=1; LED19=1; LED25=0; LED24=0;	Delay(5000);
	LED31=1; LED18=1; LED26=0; LED23=0;	Delay(5000);
	LED32=1; LED17=1; LED27=0; LED22=0;	Delay(5000);
}
 
void transverse_LED(void)
{
    //横向亮灯
	LED16=1;Delay(4000);
	 LED15=1; LED8=1; LED25=1; 	Delay(4000);
	LED14=1; LED7=1; LED26=1; LED24=1;	Delay(4000);
	LED13=1; LED6=1; LED27=1;  LED23=1;	Delay(4000);
	LED12=1; LED5=1; LED28=1; LED22=1;	Delay(4000);
	LED11=1; LED4=1; LED29=1; LED21=1;	Delay(4000);
	LED10=1; LED3=1; LED30=1; LED20=1;	Delay(4000);
	LED9=1; LED2=1; LED31=1; LED19=1;	Delay(4000);
	 LED1=1; LED32=1; LED17=1;LED18=1;	Delay(4000);

	Delay(20000);
}
 //反横向亮灯
void tran_LED(void)
{
	 LED1=0; LED32=0; LED17=0;LED18=0;	Delay(4000);
	LED9=0; LED2=0; LED31=0; LED19=0;	Delay(4000);
	LED10=0; LED3=0; LED30=0; LED20=0;	Delay(4000);
	LED11=0; LED4=0; LED29=0; LED21=0;	Delay(4000);
	LED12=0; LED5=0; LED28=0; LED22=0;	Delay(4000);
	LED13=0; LED6=0; LED27=0;  LED23=0;	Delay(4000);
	LED14=0; LED7=0; LED26=0; LED24=0;		Delay(4000);
	 LED15=0; LED8=0; LED25=0; Delay(4000);
	LED16=0;Delay(4000);
	Delay(20000);
}
void main()
{
	//全关
	turn_off();
	transverse_LED();
		tran_LED();
	turn_on;
	while(1)
	{
		for(i = 0; i < 5; i++){
			//单灯循环
			one_LED();
		}
		
		appear_LED();
        //呼吸灯部分
		breathe_LED();
		turn_off();
		
		//流水灯部分
		run_LED();
		turn_off();
		
		run_LED_2();
		turn_off();
		
		//上下往返
		fall_rise_LED();
		turn_off();
		
		//满天星
		star_LED();
		turn_off();
 
		for(i = 0; i < 2; i++){
			//双线环绕往返正向
			chase_LED();
			//双线环绕往返反向
			chase_LED_reverse();
		}
		for(i = 0; i < 2; i++){
			//双线环绕
			chase_LED_back();
			//双线环绕反方向
			chase_LED_back_reverse();
		}
		turn_off();
	
		
		for(i = 0; i < 2; i++){
			//竖向闪灯
			vertical_LED();
			turn_off();
		}
		
		for(i = 0; i < 2; i++){
            //横向闪灯
			transverse_LED();
						tran_LED();
			if(i < 1){  //第2次不关灯
				turn_off();
			}
		}
		
		for(i = 0; i < 2; i++)
		{
			//呼吸灯
			breathe_LED();
		}
		
		//将单灯循环延时变量恢复原值
		one_time = 1500;
	}
}

  本篇博客就到此为止,谢谢大家的支持!dcbceae2607c46b4ac10f9d6b3e8795a.gif

你可能感兴趣的:(51单片机,单片机,嵌入式硬件)