www.pudn.com > lightCL.rar > lightCL.c, change:2008-08-28,size:4114b


#include <reg51.h>  
#include <INTRINS.H>  
#define uchar unsigned char 
#define uint unsigned int 
sbit STB=P3^5; 
sbit CKI=P1^1; 
sbit DAI=P1^2; 
uchar Red_Data,Green_Data,Blue_Data,red_r,red_1,green_1,blue_1,i,j,z,x,y; 
void light(); 
void delay(uint z);  
void DM413_Send(unsigned char Red_Data,unsigned char Green_Data,unsigned char Blue_Data);  
void main() 
{ 
while(1) 
{ 
light(); 
} 
} 
void light() 
{ 
	for(red_1=0xff;red_1>0;red_1--)   //渐变 
	{ 
		Red_Data=red_1; 
		Green_Data=red_1; 
        Blue_Data=red_1; 
     	delay(100); 
		DM413_Send(Red_Data,Green_Data,Blue_Data);  
	} 
	for(red_1=0x00;red_1<0xff;red_1--) 
	{ 
		Red_Data=red_1; 
		Green_Data=red_1; 
        Blue_Data=red_1; 
     	delay(100); 
		DM413_Send(Red_Data,Green_Data,Blue_Data); 
	} 
			for(i=50;i>0;i--)        //闪 
			{ 
				red_1=0xff; 
				Red_Data=red_1; 
				Green_Data=red_1; 
		        Blue_Data=red_1; 
				DM413_Send(Red_Data,Green_Data,Blue_Data); 
 
		     	delay(100); 
				red_1=0x00; 
				Red_Data=red_1; 
				Green_Data=red_1; 
		        Blue_Data=red_1; 
		     	delay(100); 
				DM413_Send(Red_Data,Green_Data,Blue_Data); 
			} 
					for(i=50;i>0;i--)      //轮流亮 
					{ 
						red_1=0xff; 
						green_1=0x7d; 
						blue_1=0x00; 
 
						Red_Data=blue_1; 
						Green_Data=red_1; 
						Blue_Data=red_1; 
						DM413_Send(Red_Data,Green_Data,Blue_Data); 
						delay(100); 
 
						Red_Data=red_1; 
						Green_Data=blue_1; 
						Blue_Data=red_1; 
						DM413_Send(Red_Data,Green_Data,Blue_Data); 
						delay(100); 
 
						Red_Data=red_1; 
						Green_Data=red_1; 
						Blue_Data=blue_1; 
						DM413_Send(Red_Data,Green_Data,Blue_Data); 
						delay(100); 
 
						Red_Data=blue_1; 
						Green_Data=blue_1; 
						Blue_Data=red_1; 
						DM413_Send(Red_Data,Green_Data,Blue_Data); 
						delay(100); 
 
						Red_Data=red_1; 
						Green_Data=blue_1; 
						Blue_Data=blue_1; 
						DM413_Send(Red_Data,Green_Data,Blue_Data); 
						delay(100); 
 
						Red_Data=blue_1; 
						Green_Data=red_1; 
						Blue_Data=blue_1; 
						DM413_Send(Red_Data,Green_Data,Blue_Data); 
						delay(100); 
 
						Red_Data=blue_1; 
						Green_Data=blue_1; 
						Blue_Data=red_1; 
						DM413_Send(Red_Data,Green_Data,Blue_Data); 
						delay(100); 
 
						Red_Data=red_1; 
						Green_Data=red_1; 
						Blue_Data=red_1; 
						DM413_Send(Red_Data,Green_Data,Blue_Data); 
						delay(100); 
 
						Red_Data=blue_1; 
						Green_Data=blue_1; 
						Blue_Data=blue_1; 
						DM413_Send(Red_Data,Green_Data,Blue_Data); 
						delay(100); 
					} 
 
} 
void delay(uint z)   //延时子程序。 
{ 
	uint x,y; 
	for(x=z;x>0;x--) 
		for(y=110;y>0;y--); 
} 
 
 
//传入的数据依次为红,绿,蓝 ,数据格式为16进制.256个数值.  
void DM413_Send(unsigned char Red_Data,unsigned char Green_Data,unsigned char Blue_Data)  
{  
unsigned char i,Date_R,Date_G,Date_B;   //R变量,G变量,B变量  
Date_R = Red_Data;   //赋予R变量值  
Date_G = Green_Data;   //赋予G变量值  
Date_B = Blue_Data;   //赋予B变量值  
STB = 0;  
DAI = 0;  
CKI = 0;  
 
STB = 1;    //打开使能端  
for(i=8;i>0;i--)   //发送红色数据  
{  
CKI = 0;  
_nop_();  
_nop_();  
_nop_();  
_nop_();  
_nop_();  
_nop_();  
_nop_();  
_nop_();  
if(Date_R & 0x80)     DAI = 1;  
    else         DAI = 0;  
CKI = 1;  
Date_R <<= 1;  
_nop_();  
_nop_();  
_nop_();  
_nop_();  
_nop_();  
_nop_();  
_nop_();  
_nop_();  
DAI = 0;  
}  
for(i=8;i>0;i--)   //发送绿色数据  
{  
CKI = 0;  
_nop_();  
_nop_();  
_nop_();  
_nop_();  
_nop_();  
_nop_();  
_nop_();  
_nop_();  
if(Date_G & 0x80)     DAI = 1;  
    else         DAI = 0;  
CKI = 1;  
Date_G <<= 1;  
_nop_();  
_nop_();  
_nop_();  
_nop_();  
_nop_();  
_nop_();  
_nop_();  
_nop_();  
DAI = 0;  
}  
for(i=8;i>0;i--)   //发送绿色数据  
{  
CKI = 0;  
_nop_();  
_nop_();  
_nop_();  
_nop_();  
_nop_();  
_nop_();  
_nop_();  
_nop_();  
if(Date_B & 0x80)     DAI = 1;  
    else         DAI = 0;  
CKI = 1;  
Date_B <<= 1;  
_nop_();  
_nop_();  
_nop_();  
_nop_();  
_nop_();  
_nop_();  
_nop_();  
_nop_();  
DAI = 0;  
}  
STB = 0;    //关闭使能端  
CKI = 0;  
delay(10); 
      
DAI = 0;  
}