⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 用AVR atmega16做的一个完整彩色LED控制程序
💻 C
📖 第 1 页 / 共 5 页
字号:
			if(UniteColorEdgeToMiddle(value, UNITEC1,UNITEC2,UNITEC3,  UNITEC4,  UNITEC5,mode)==1) break;
		}
		if(SpeedDelay(mode & 0x03)) return ;		
	}
}
void		AllStarProcess(uchar kind,uchar mode,uchar class,uchar ic_count)
{
	uchar	tim,i,value,k,j;
//	uchar	tim,i=0;//,mode;
//	uchar	loop1=16,loop2=120;
	k=0;
	for(i=0;i<val_lenght;)
	{
		value=KindGroudData[kind][k];
		if(value==0x00)
		{
			k=0;
			value=KindGroudData[kind][k];
		}
//		GetMiddleColor_all(value);
		k++;

		putSPIchar(value);
		DelayNs(50);
		SendSS(1);
		SendSI(class);		
		putSPIchar(UNLOCKDATA);
		DelayNs(50);
		SendSS(1);

		i=i+1;
		if(i>val_lenght)return;
		for(j=0;j<ic_count;j++)
		{
			SendSI(class);		
			putSPIchar(UNLOCKDATA);
			DelayNs(50);
			SendSS(1);
			SendSI(class);		
			putSPIchar(UNLOCKDATA);
			DelayNs(50);
			SendSS(1);
			i=i+1;
			if(i>val_lenght)return;
		}
		
		if(SpeedDelay(mode & 0x03)==1) return ;
//		i=i+1;
		
	}	
}

//从中间向两边。
void		AllStarProcess_2(uchar kind,uchar mode,uchar cclass,uchar ic_count)
{
	uchar	tim,value,k,j;
	uchar	level;
	uchar	data[6],data1[6],fullflag,looplenght;
	uint		newlenght,jj,i;
	uchar	one_l,two_l,three_l,four_l,five_l,six_l;
	uchar	one,two,three,four,five,six;

	//芯片数为双数, 为单数
	HalfLenght=val_lenght;
//	FLenghtCount=0;
	newlenght=val_lenght;
	BLenghtCount=newlenght;
	
	data[0]	=KindGroudData[kind][0];
	data[1]	=KindGroudData[kind][1];
	data[2]	=KindGroudData[kind][2];
	data[3]	=KindGroudData[kind][3];
	data[4]	=KindGroudData[kind][4];
	data[5]	=KindGroudData[kind][5];
	data1[0]	=KindGroudData[kind][5];
	data1[1]	=KindGroudData[kind][4];
	data1[2]	=KindGroudData[kind][3];
	data1[3]	=KindGroudData[kind][2];
	data1[4]	=KindGroudData[kind][1];
	data1[5]	=KindGroudData[kind][0];

	k=0;
	level=0;
	one=0;two=0;three=0;four=0;five=0;six=0;
	one_l=0;	two_l=0;	three_l=0;four_l=0;five_l=0;	six_l=0;
	fullflag=0;
	looplenght=2*ic_count;
	i=0;
	for(i=0;i<newlenght;)
	{

	    for(k=0;k<looplenght;k++){
////////////////////////////////////////
		if(fullflag)
		{
			FullProcess(fullflag,looplenght,data);
		}

			if(one<looplenght)
				one++;
			Send_Data(data[0],1);
			for(j=1;j<one;j++)
			{
				Send_Data(UNLOCKDATA,1);
			}
		if(level>=1)
		{
			if(two<looplenght)
				two++;
			Send_Data(data[1],1);
			for(j=1;j<two;j++)
			{
				Send_Data(UNLOCKDATA,1);
			}
		}
		if(level>=2)
		{
			if(three<looplenght)
				three++;
			Send_Data(data[2],1);
			for(j=1;j<three;j++)
			{
				Send_Data(UNLOCKDATA,1);
			}
		}
		if(level>=3)
		{
			if(four<looplenght)
				four++;
			Send_Data(data[3],1);
			for(j=1;j<four;j++)
			{
				Send_Data(UNLOCKDATA,1);
			}
		}
		if(level>=4)
		{
			if(five<looplenght)
				five++;
			Send_Data(data[4],1);
			for(j=1;j<five;j++)
			{
				Send_Data(UNLOCKDATA,1);
			}
		}
		if(level>=5)
		{
			if(six<looplenght)
				six++;
			Send_Data(data[5],1);
			for(j=1;j<six;j++)
			{
				Send_Data(UNLOCKDATA,1);
			}
		}

////////////////////////////////////////
			
		switch(level)
		{
		case	5:
			if(six_l<looplenght)
				six_l++;
			for(j=1;j<six_l;j++)
			{
				Send_Data(UNLOCKDATA,1);
			}
			Send_Data(data[5],1);
		
		case	4:
			if(five_l<looplenght)
				five_l++;
			for(j=1;j<five_l;j++)
			{
				Send_Data(UNLOCKDATA,1);
			}
			Send_Data(data[4],1);
			
		case	3:
			if(four_l<looplenght)
				four_l++;
			for(j=1;j<four_l;j++)
			{
				Send_Data(UNLOCKDATA,1);
			}
			Send_Data(data[3],1);

		case	2:
			if(three_l<looplenght)
				three_l++;
			for(j=1;j<three_l;j++)
			{
				Send_Data(UNLOCKDATA,1);
			}
			Send_Data(data[2],1);

		case	1:
			if(two_l<looplenght)
				two_l++;
			for(j=1;j<two_l;j++)
			{
				Send_Data(UNLOCKDATA,1);
			}
			Send_Data(data[1],1);
			
		case	0:
		default:
			if(one_l<looplenght)
				one_l++;
			for(j=1;j<one_l;j++)
			{
				Send_Data(UNLOCKDATA,1);
			}
			Send_Data(data[0],1);
			
			if(fullflag)
			{
				FullProcess(fullflag,looplenght,data1);
			}
			jj=one_l+two_l+three_l+four_l+five_l+six_l+fullflag *60;
			i=jj;
			for(;jj<BLenghtCount;jj++)
			{
				Send_Data(UNLOCKDATA,1);
			}
			SendSS(1);
			SendSI(cclass);		
			if(i>=newlenght)return;
			break;
		}

	  }
         level++;
	  if(level>5)
	  {
		level=0;
		fullflag++;
		one=0;two=0;three=0;four=0;five=0;six=0;
		one_l=0;	two_l=0;	three_l=0;four_l=0;five_l=0;	six_l=0;
	  }

	if(SpeedDelay(mode & 0x03)==1) return ;
		
	}	

}


//从两边向中间。
void		AllStarProcess_3(uchar kind,uchar mode,uchar cclass,uchar ic_count)
{
	uchar	tim,value,k,j;
	uchar	level;
	uchar	data[6],data1[6],fullflag,looplenght;
	uint		newlenght,jj,i;
	uchar	one_l,two_l,three_l,four_l,five_l,six_l;
	uchar	one,two,three,four,five,six;

	//芯片数为双数, 为单数
	HalfLenght=val_lenght;
	FLenghtCount=val_lenght;
	newlenght=val_lenght;
	BLenghtCount=newlenght;
	
	data[0]	=KindGroudData[kind][0];
	data[1]	=KindGroudData[kind][1];
	data[2]	=KindGroudData[kind][2];
	data[3]	=KindGroudData[kind][3];
	data[4]	=KindGroudData[kind][4];
	data[5]	=KindGroudData[kind][5];
	data1[0]	=KindGroudData[kind][5];
	data1[1]	=KindGroudData[kind][4];
	data1[2]	=KindGroudData[kind][3];
	data1[3]	=KindGroudData[kind][2];
	data1[4]	=KindGroudData[kind][1];
	data1[5]	=KindGroudData[kind][0];

	k=0;
	level=0;
	one=0;two=0;three=0;four=0;five=0;six=0;
	one_l=0;	two_l=0;	three_l=0;four_l=0;five_l=0;	six_l=0;
	fullflag=0;
	looplenght=2*ic_count;
	i=0;
	for(i=0;i<newlenght;)
	{

	    for(k=0;k<looplenght;k++){
			
		switch(level)
		{
		case	5:
			if(six_l<looplenght)
				six_l++;
			for(j=1;j<six_l;j++)
			{
				Send_Data(UNLOCKDATA,1);
			}
			Send_Data(data[5],1);
		
		case	4:
			if(five_l<looplenght)
				five_l++;
			for(j=1;j<five_l;j++)
			{
				Send_Data(UNLOCKDATA,1);
			}
			Send_Data(data[4],1);
			
		case	3:
			if(four_l<looplenght)
				four_l++;
			for(j=1;j<four_l;j++)
			{
				Send_Data(UNLOCKDATA,1);
			}
			Send_Data(data[3],1);

		case	2:
			if(three_l<looplenght)
				three_l++;
			for(j=1;j<three_l;j++)
			{
				Send_Data(UNLOCKDATA,1);
			}
			Send_Data(data[2],1);

		case	1:
			if(two_l<looplenght)
				two_l++;
			for(j=1;j<two_l;j++)
			{
				Send_Data(UNLOCKDATA,1);
			}
			Send_Data(data[1],1);
			
		case	0:
		default:
			if(one_l<looplenght)
				one_l++;
			for(j=1;j<one_l;j++)
			{
				Send_Data(UNLOCKDATA,1);
			}
			Send_Data(data[0],1);
			
			if(fullflag)
			{
				FullProcess(fullflag,looplenght,data1);
			}
			jj=one_l+two_l+three_l+four_l+five_l+six_l+fullflag *60;
			i=jj;
			for(;jj<BLenghtCount;jj++)
			{
				Send_Data(UNLOCKDATA,1);
			}

////////////////////////////////////////
		FLenghtCount--;
		Send_Data(UNLOCKDATA,FLenghtCount);

		if(fullflag)
		{
			FullProcess(fullflag,looplenght,data);
		}

			if(one<looplenght)
				one++;
			Send_Data(data[0],1);
			for(j=1;j<one;j++)
			{
				Send_Data(UNLOCKDATA,1);
			}
		if(level>=1)
		{
			if(two<looplenght)
				two++;
			Send_Data(data[1],1);
			for(j=1;j<two;j++)
			{
				Send_Data(UNLOCKDATA,1);
			}
		}
		if(level>=2)
		{
			if(three<looplenght)
				three++;
			Send_Data(data[2],1);
			for(j=1;j<three;j++)
			{
				Send_Data(UNLOCKDATA,1);
			}
		}
		if(level>=3)
		{
			if(four<looplenght)
				four++;
			Send_Data(data[3],1);
			for(j=1;j<four;j++)
			{
				Send_Data(UNLOCKDATA,1);
			}
		}
		if(level>=4)
		{
			if(five<looplenght)
				five++;
			Send_Data(data[4],1);
			for(j=1;j<five;j++)
			{
				Send_Data(UNLOCKDATA,1);
			}
		}
		if(level>=5)
		{
			if(six<looplenght)
				six++;
			Send_Data(data[5],1);
			for(j=1;j<six;j++)
			{
				Send_Data(UNLOCKDATA,1);
			}
		}
////////////////////////////////////////
			
			SendSS(1);
			SendSI(cclass);		
			if(i>=newlenght)return;
			break;
		}

	  }
         level++;
	  if(level>5)
	  {
		level=0;
		fullflag++;
		one=0;two=0;three=0;four=0;five=0;six=0;
		one_l=0;	two_l=0;	three_l=0;four_l=0;five_l=0;	six_l=0;
	  }

	if(SpeedDelay(mode & 0x03)==1) return ;
		
	}	

}

void		FullProcess(uchar fullflag,uchar looplenght,uchar *data)
{
	uchar i,j,l;
	for(l=0;l<fullflag;l++)
	{
		for(i=0;i<6;i++)
		{
			for(j=1;j<looplenght;j++)
			{
				Send_Data(UNLOCKDATA,1);
			}
			Send_Data(data[i],1);
		}
	}
}

void		SevenColorProcess_1(uchar kind,uchar mode,uchar cclass,uchar ic_count)
{
	uchar	k,j,level;
	uchar	data[6],data1[6],fullflag,looplenght;
	uint		newlenght,jj,i;
	uchar	two_l,three_l,four_l,five_l,six_l;
	
	newlenght=2*val_lenght;
	data[0]	=KindGroudData[kind][0];
	data[1]	=KindGroudData[kind][1];
	data[2]	=KindGroudData[kind][2];
	data[3]	=KindGroudData[kind][3];
	data[4]	=KindGroudData[kind][4];
	data[5]	=KindGroudData[kind][5];
	data1[0]	=KindGroudData[kind][5];
	data1[1]	=KindGroudData[kind][4];
	data1[2]	=KindGroudData[kind][3];
	data1[3]	=KindGroudData[kind][2];
	data1[4]	=KindGroudData[kind][1];
	data1[5]	=KindGroudData[kind][0];

	k=0;
	level=0;
	FLenghtCount=0;
	two_l=0;
	three_l=0;
	four_l=0;
	five_l=0;
	six_l=0;
	BLenghtCount=newlenght;
	fullflag=0;
	looplenght=2*ic_count;
	i=0;
	for(i=0;i<newlenght;)
	{

	    for(k=0;k<looplenght;k++){
		switch(level)
		{
		case	5:
			if(six_l<looplenght)
				six_l++;
			for(j=1;j<six_l;j++)
			{
				Send_Data(UNLOCKDATA,1);
			}
			Send_Data(data[5],1);
		
		case	4:
			if(five_l<looplenght)
				five_l++;
			for(j=1;j<five_l;j++)
			{
				Send_Data(UNLOCKDATA,1);
			}
			Send_Data(data[4],1);
			
		case	3:
			if(four_l<looplenght)
				four_l++;
			for(j=1;j<four_l;j++)
			{
				Send_Data(UNLOCKDATA,1);
			}
			Send_Data(data[3],1);

		case	2:
			if(three_l<looplenght)
				three_l++;
			for(j=1;j<three_l;j++)
			{
				Send_Data(UNLOCKDATA,1);
			}
			Send_Data(data[2],1);

		case	1:
			if(two_l<looplenght)
				two_l++;
			for(j=1;j<two_l;j++)
			{
				Send_Data(UNLOCKDATA,1);
			}
			Send_Data(data[1],1);
			
		case	0:
		default:
			if(FLenghtCount<looplenght)
				FLenghtCount++;
			for(j=1;j<FLenghtCount;j++)
			{
				Send_Data(UNLOCKDATA,1);
			}
			Send_Data(data[0],1);
			
			if(fullflag)
			{
				FullProcess(fullflag,looplenght,data1);
			}
			jj=FLenghtCount+two_l+three_l+four_l+five_l+six_l+fullflag *60;
			i=jj;
			for(;jj<BLenghtCount;jj++)
			{
				Send_Data(UNLOCKDATA,1);
			}
			SendSS(1);
			SendSI(cclass);		
			if(i>=newlenght)return;
			break;
		}

	  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -