//2022.09.07
//驱动树的灯,功率不能大,大了会影响某些灯珠混色
#include "uart.h"
#include "intrins.h"
#define LED_R 80,0,0,0 //红色
#define LED_G 0,80,0,0 //绿色
#define LED_B 0,0,80,0 //蓝色
#define LED_W 0,0,0,80 //白色
#define LED_C 40,28,30,0 //青色
#define LED_P 40,0,58,0 //紫色
#define LED_M 35,10,35,18 //彩色
#define LED_O 55,22,5,13 //青黄
#define LED_OFF 0,0,0,0
sbit LED_OUT = P5^4; //数据口
bit busy;//忙标志位
bit kjx_stop;//开机秀退出模式
uchar data_num;//数组个数
uchar buffer[5];//接受2.4G模块的数据
uchar mode;//模式变量
uchar spe;//难忘日的号
bit change;//主题改变标志位
uchar colr_R,colr_G,colr_B,ns1;
uint fs;
uchar i,a,b,m,k,bs_r,bs_g,bs_b,bs_w,bs_w1,bs_r1,bs_g1,bs_b1;
uchar yanse_change_num,show_num2,show_num,next;
bit first_in,mak_3;
uchar num_manual;
uchar num[6];
uint time_us;
uchar dz_x;
uchar buf_R[8];
uchar step;
uint show_ms;
uchar color;
uchar key_ms;
bit key_mak,key_value;
void init_port()
{
P5M0 = 0X00;
P5M1 = 0X00;
}
/********************************************
10us延时
********************************************/
void Delay10us() //@11.0592MHz
{
unsigned char i;
_nop_();
i = 25;
while (--i);
}
/********************************************
150us延时
********************************************/
/*
void Delay150us() //@11.0592MHz
{
unsigned char i, j;
_nop_();
_nop_();
_nop_();
i = 2;
j = 153;
do
{
while (--j);
} while (--i);
}
*/
/********************************************
********************************************/
/*
void Delay80us() //@11.0592MHz
{
unsigned char i;
_nop_();
_nop_();
_nop_();
i = 218;
while (--i);
}
*/
//------------------------1ms寤舵椂--------------------------------------
void delayms(uint ms) //@30.000MHz
{
uchar i, j;
while(ms--)
{
// WDTCON |= 0x10;//娓呯湅闂ㄧ嫍
_nop_();
_nop_();
i = 39;
j = 243;
do
{
while (--j);
} while (--i);
}
}
void RGB_Set_Up()//1码80
{
LED_OUT = 0;
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
LED_OUT = 1;
Delay10us();
}
void RGB_Set_Down()//0码40
{
LED_OUT = 0;
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
LED_OUT = 1;
Delay10us();
}
//复位码
void RGB_Rst()
{
LED_OUT = 0;
Delay10us();
// Delay10us();
// Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
LED_OUT = 1;
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
Delay10us();
}
//发送36位数据
void Send_36bits(uchar jiedian,uchar adrr,uchar R8,uchar G8,uchar B8,uchar W8)
{
uchar n = 0;
if(jiedian==1)
RGB_Set_Up();
else
RGB_Set_Down();
for(n=0;n<3;n++)
{
if((adrr & 0x01) == 0x01)
{
RGB_Set_Up();
}
else
{
RGB_Set_Down();
}
adrr>>=1;
}
for(n=0;n<8;n++)
{
if((R8&0x01) == 0x01)
{
RGB_Set_Up();
}
else
{
RGB_Set_Down();
}
R8>>=1;
}
for(n=0;n<8;n++)
{
if((G8&0x01) == 0x01)
{
RGB_Set_Up();
}
else
{
RGB_Set_Down();
}
G8>>=1;
}
for(n=0;n<8;n++)
{
if((B8&0x01) == 0x01)
{
RGB_Set_Up();
}
else
{
RGB_Set_Down();
}
B8>>=1;
}
for(n=0;n<8;n++)
{
if((W8&0x01) == 0x01)
{
RGB_Set_Up();
}
else
{
RGB_Set_Down();
}
W8>>=1;
}
RGB_Rst();
}
/***************************
******全灭******************
****************************/
/*
void quanmie()
{
for(i=1;i++;i<7)
Send_36bits(1,i,0,0,0,0);
}
*/
/**************************
*********熄灭**************
**************************/
void ximie()
{
// for(i=1;i<7;i++)
// {
// Send_36bits(1,i,LED_OFF);
// }
Send_36bits(1,1,LED_OFF);
Send_36bits(1,2,LED_OFF);
Send_36bits(1,3,LED_OFF);
Send_36bits(1,4,LED_OFF);
Send_36bits(1,5,LED_OFF);
Send_36bits(1,6,LED_OFF);
}
void Roller2()//混色移位 //初始a=1;
{
switch(a)
{
case 0:
Send_36bits(1,1,LED_W);
delayms(100);
Send_36bits(1,2,LED_C);
delayms(100);
Send_36bits(1,3,LED_P);
delayms(100);
Send_36bits(1,4,LED_B);
delayms(100);
Send_36bits(1,5,LED_R);
delayms(100);
Send_36bits(1,6,LED_G);
delayms(100);
a++;
break;
case 1:
Send_36bits(1,1,LED_G);
delayms(100);
Send_36bits(1,2,LED_W);
delayms(100);
Send_36bits(1,3,LED_C);
delayms(100);
Send_36bits(1,4,LED_P);
delayms(100);
Send_36bits(1,5,LED_B);
delayms(100);
Send_36bits(1,6,LED_R);
delayms(100);
a++;
break;
case 2:
Send_36bits(1,1,LED_R);
delayms(100);
Send_36bits(1,2,LED_G);
delayms(100);
Send_36bits(1,3,LED_W);
delayms(100);
Send_36bits(1,4,LED_C);
delayms(100);
Send_36bits(1,5,LED_P);
delayms(100);
Send_36bits(1,6,LED_B);
delayms(100);
a++;
break;
case 3:
Send_36bits(1,1,LED_B);
delayms(100);
Send_36bits(1,2,LED_R);
delayms(100);
Send_36bits(1,3,LED_G);
delayms(100);
Send_36bits(1,4,LED_W);
delayms(100);
Send_36bits(1,5,LED_C);
delayms(100);
Send_36bits(1,6,LED_P);
delayms(100);
a++;
break;
case 4:
Send_36bits(1,1,LED_P);
delayms(100);
Send_36bits(1,2,LED_B);
delayms(100);
Send_36bits(1,3,LED_R);
delayms(100);
Send_36bits(1,4,LED_G);
delayms(100);
Send_36bits(1,5,LED_W);
delayms(100);
Send_36bits(1,6,LED_C);
delayms(100);
a++;
break;
case 5:
Send_36bits(1,1,LED_C);
delayms(100);
Send_36bits(1,2,LED_P);
delayms(100);
Send_36bits(1,3,LED_B);
delayms(100);
Send_36bits(1,4,LED_R);
delayms(100);
Send_36bits(1,5,LED_G);
delayms(100);
Send_36bits(1,6,LED_W);
delayms(100);
a++;
break;
case 6:
a=0;
break;
}
}
/*************************************
**************主函数******************
*************************************/
void main()
{
UartInit();//端口初始化
init_port();//串口初始化
// m=0;
ximie();
while(1)
{
Roller2();
}
}
混色移位(流水灯)不熄灭
需积分: 9 179 浏览量
2022-12-14
11:19:43
上传
评论
收藏 152KB ZIP 举报
![avatar](https://profile-avatar.csdnimg.cn/5f7528238e484b04909839422cd5e84b_weixin_65674429.jpg!1)
码卡龙
- 粉丝: 3
- 资源: 4
最新资源
- Ruby的语法类似于英语,易于阅读和理解 它支持多种编程范式,包括面向对象编程、过程式编程和函数式编程
- NX二次开发UF-CGM-ask-session-custom-colors 函数介绍
- 基于深度学习的YOLO目标检测综述.pdf
- NX二次开发UF-CGM-ask-default-custom-widths 函数介绍
- NX二次开发UF-CGM-ask-default-custom-colors 函数介绍
- 编译好的Crashpad库 (x86 & x64) - Release & Debug 版本
- NX二次开发UF-CFI-spawn-check-status 函数介绍
- vue组件间通信的实现方式,父组件可以通过props属性将数据传递给子组件,子组件可以通过$emit方法触发父组件定义的事.md
- NX二次开发UF-CFI-spawn 函数介绍
- React框架:深度解析与应用场景
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)