村网通总站 姬家寨村 455496.nync.com 欢迎您!
//《C51WS2812》
//软件编程:姬学瑞;硬件设计:姬学瑞;
//版权所有;侵权必究!
//姬家寨村电子科技研究所研制!
#include<reg52.h>
#include<intrins.h>
//单片机为15系列 晶振内部27M 分频为0X02
//可以控制1024个RGB
#define uchar unsigned char
sfr PLC=0X97;
sbit Send_Dat=P3^5;
unsigned char RGB_BUF[24];
void delay();
void RGBA(); //流动效果
void RGBB( unsigned int w);//静态显示全彩
void RGBC (); //全体变色效果
uchar n;
uchar r;
unsigned char *p;
uchar a []={ 0xff,0x00,0x00} ; //绿
uchar b []={ 0x00,0xff,0x00} ; //红
uchar c []={ 0x00,0x00,0xff} ; //蓝
uchar d []={ 0xff,0xff,0x00} ; //黄
uchar e []={ 0xff,0x00,0xff} ; //青
uchar f []={ 0x00,0xff,0xff} ; //紫
uchar g []={ 0xff,0xff,0xff} ; //白
uchar h []={ 0x00,0x00,0x00} ;
uchar shuzud [8] [3]={
{ 0xff,0x00,0x00}, //绿
{ 0x00,0xff,0x00} , //红
{ 0x00,0x00,0xff} , //蓝
{ 0xff,0xff,0x00} , //黄
{ 0xff,0x00,0xff} , //青
{ 0x00,0xff,0xff} , //紫
{ 0xff,0xff,0xff} , //白
{ 0x00,0x00,0x00} ,
};
sfr P3M1 = 0xb1;
sfr P3M0 = 0xb2;
struct shuzu
{
uchar a [3];
uchar b[3] ;
};
struct shuzu;
void delays(uchar t);
void Send_A_bit(uchar v)
{
//
if (v==1)
{
Send_Dat=1;
_nop_();
Send_Dat=0;
}
else
{
Send_Dat=1;
Send_Dat=0;
_nop_();
}
}
void Send_192bits( uchar *p1,uchar z)
{
unsigned int i=0; uchar s; uchar x; unsigned char k;
s=8;
x=0;
// 1
for (i=x;i<s;i++)
{
RGB_BUF[i]=p1[0]>>(i-x)&0x01; //转化R_VAL
}
s=s+8;
x=x+8;
for (i=x;i<s;i++)
{
RGB_BUF[i]=p1[1]>>(i-x)&0x01; //转化G_VAL
}
s=s+8;
x=x+8;
for (i=x;i<s;i++)
{
RGB_BUF[i]=p1[2]>>(i-x)&0x01;
//转化R_VAL
}
s=s+8;
x=x+8;
for (k=0;k<z;k++) //循环RGB数量
{
for (i=0;i<24;i++)
{
Send_A_bit(RGB_BUF[i]);
}
}
}
void main()
{
P3M0 = 0x00;
P3M1 = 0x00;
PLC=0X02;
while(1)
{
RGBB(65000); //全体静态显示全彩效果
delays(10 );
RGBA();//全体流动效果
delays(5);
RGBC();//全体变色效果
delays(5);
}
}
void RGBA() // 流动效果
{
Send_192bits(shuzud[0],9);
delays(1);
for (n=0;n<10;n++)
{
Send_192bits(shuzud[1],n);
delays(1);
}
for (n=0;n<10;n++)
{
Send_192bits(shuzud[2],n);
delays(1);
}
}
void RGBB( unsigned int w ) //全体静态显示全彩效果
{
unsigned int t;
for (t=0;t< w;t++);
Send_192bits(shuzud[2],9);
for (t=0;t< w;w++);
Send_192bits(shuzud[1],8);
for (t=0;t< w;t++);
Send_192bits(shuzud[0],7);
for (t=0;t< w;t++);
Send_192bits(shuzud[5],6);
for (t=0;t< w;t++);
Send_192bits(shuzud[4],5);
for (t=0;t< w;t++);
Send_192bits(shuzud[3],4);
for (t=0;t< w;t++);
Send_192bits(shuzud[2],3);
for (t=0;t< w;t++);
Send_192bits(shuzud[1],2);
for (t=0;t< w;t++);
Send_192bits(shuzud[0],1);
for (t=0;t< w;t++);
}
void RGBC() //全体变色效果
{
Send_192bits(shuzud[0],9);
delays(5);
Send_192bits(shuzud[1],9);
delays(5);
Send_192bits(shuzud[2],9);
delays(5);
Send_192bits(shuzud[3],9);
delays(5);
Send_192bits(shuzud[4],9);
delays(5);
Send_192bits(shuzud[5],9);
delays(5);
}
void delay()
{
unsigned int i,j;
for (i=0;i<250;i++)
{
for (j=0;j<200;j++);
}
}
/*大延时函数*/
/*十几秒*/
void delays(uchar t)
{
uchar p;
for (p=0; p<t;p++)
{
delay();
}
}