|
LED使用的5050分裝自帶WS2811.只需要一個IO口控制,可以顯示16777215 種顏色,附源代碼。
9.png (339.27 KB, 下載次數(shù): 99)
下載附件
2018-1-3 13:54 上傳
8.png (338.93 KB, 下載次數(shù): 104)
下載附件
2018-1-3 13:54 上傳
7.png (309.09 KB, 下載次數(shù): 109)
下載附件
2018-1-3 13:54 上傳
6.png (329.94 KB, 下載次數(shù): 101)
下載附件
2018-1-3 13:54 上傳
5.png (318.87 KB, 下載次數(shù): 111)
下載附件
2018-1-3 13:54 上傳
4.png (273.56 KB, 下載次數(shù): 84)
下載附件
2018-1-3 13:54 上傳
3.png (290.33 KB, 下載次數(shù): 105)
下載附件
2018-1-3 13:54 上傳
2.png (336.46 KB, 下載次數(shù): 76)
下載附件
2018-1-3 13:54 上傳
1.png (315.74 KB, 下載次數(shù): 107)
下載附件
2018-1-3 13:54 上傳
單片機(jī)源程序如下:
- #include "main.h"
- #include <STC/STC12C5A60S2.h>
- //#define MAIN_Fosc 24000000L //定義主時鐘
- #define WHITE 0xFFFFFF // 白色
- #define BLACK 0x000000 // 黑色
- #define RED 0x00ff00 // 紅色
- #define GREEN 0xff0000 // 綠色
- #define BLUE 0x0000ff // 藍(lán)色
- #define CHENG 0xff7f00 // 橙色
- #define DIAN 0xff00ff //
- #define ZI 0x00ffff
- #define LED_N 16 //LED的數(shù)量
- //extern unsigned long WsDat[];
- unsigned long WsDat[];
- void main ()//主函數(shù)
- {
- reset();
- //DisP_R_G_B(20);
- ColorToColor(0X000000,0XFF0000);
- ColorToColor(0XFF0000,0xFFFF00);
- ColorToColor(0xFFFF00,0Xffffff);
- ColorToColor(0Xffffff,0X00ffff);
- ColorToColor(0X00ffff,0X0000ff);
- ColorToColor(0X0000ff,0X000000);
- ColorToColor(0X000000,0X00FF00);
- ColorToColor(0X00FF00,0x0FFFF0);
- ColorToColor(0x0FFFF0,0Xffffff);
- ColorToColor(0Xffffff,0XFF00ff);
- ColorToColor(0XFF00ff,0XF0000f);
- ColorToColor(0XF0000f,0X000000);
- }
- void delay(unsigned int time) //延時
- { unsigned int i,j,k;
- for(j=0;j<time;j++)
- for(i=0;i<time;i++)
- for(k=0;k<time;k++)
- Delay();
-
- }
- void Delay() //@24.000MHz
- {
- _nop_();
- }
- void reset(void)
- {
- int i;
- LED=0;
- for(i=0;i<50;i++)
- {Delay();
- }
- }
- void T0(void)
- {
- LED=1;
- LED=0;
- Delay();
-
- }
- void T1(void)
- {
- LED=1;
- Delay();
- LED=0;
- }
- void DisP_Color(unsigned long dat) //控制一個燈
- { unsigned int i;
- for(i=0;i<24;i++)
- { if(0x800000 == (dat & 0x800000)) T1();
- else T0();
- dat<<=1; //左移一位
- }
- }
- void DisP_ALLColor(unsigned long dat) //控制所有燈
- {int j;
- for(j=0;j<LED_N;j++) DisP_Color(dat);
- reset();
- }
- void DisP_R_G_B(unsigned int j) //RGB漸變
- {
- unsigned long i=0;
- while(i<0xffffff)
- {
- if(i<0xff) DisP_ALLColor(i++);
- else if(i<0xffff) { i=i+0x100;DisP_ALLColor(i); }
- else if(i<0xffffff) {i=i+0x10000;DisP_ALLColor(i); }
- delay(j);
- }
- while(i>0)
- {
- if(i>0xffff00) DisP_ALLColor(i--);
- else if(i>0xff0000) {i=i-0x100; DisP_ALLColor(i);}
- else if(i>0) {i=i-0x10000;DisP_ALLColor(i);}
- delay(j);
- }
- reset();
- }
- unsigned char abs0(int num)
- {
- if(num>0) return num;
-
- num = -num;
- return (unsigned char) num;
- }
-
- unsigned long ColorToColor(unsigned long color0, unsigned long color1)
- {
- unsigned char Red0, Green0, Blue0; // 起始三原色
- unsigned char Red1, Green1, Blue1; // 結(jié)果三原色
- int RedMinus, GreenMinus, BlueMinus; // 顏色差(color1 - color0)
- unsigned char NStep; // 需要幾步
- float RedStep, GreenStep, BlueStep; // 各色步進(jìn)值
- unsigned long color; // 結(jié)果色
- unsigned char i;
-
- // 綠 紅 藍(lán) 三原色分解
- Red0 = color0>>8;
- Green0 = color0>>16;
- Blue0 = color0;
-
- Red1 = color1>>8;
- Green1 = color1>>16;
- Blue1 = color1;
-
- // 計算需要多少步(取差值的最大值)
- RedMinus = Red1 - Red0;
- GreenMinus = Green1 - Green0;
- BlueMinus = Blue1 - Blue0;
-
- NStep = ( abs0(RedMinus) > abs0(GreenMinus) ) ? abs0(RedMinus):abs0(GreenMinus);
- NStep = ( NStep > abs0(BlueMinus) ) ? NStep:abs0(BlueMinus);
-
- // 計算出各色步進(jìn)值
- RedStep = (float)RedMinus / NStep;
- GreenStep = (float)GreenMinus / NStep;
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復(fù)制代碼
原理圖: 無
仿真: 無
代碼:
LED漸變.7z
(14.87 KB, 下載次數(shù): 394)
2024-3-17 21:33 上傳
點擊文件名下載附件
LED漸變 下載積分: 黑幣 -5
|
評分
-
查看全部評分
|