|
1.png (175.13 KB, 下載次數: 0)
下載附件
2024-12-4 18:28 上傳
- /**********接口說明**********/
- sbit led_in=P2^0;
- /**********全局變量**********/
- #define led_max 256
- xdata unsigned char Buff[led_max][3];
- /******************************
- 發送比特到WS2812
- ******************************/
- void WS2812_Send(bit DI)
- {
- if(DI) //發送1碼
- {
- led_in=1;NOP25(); //580ns~1000ns
- led_in=0;NOP12(); //220ns~420ns
- }
- else //發送0碼
- {
- led_in=1;NOP12(); //220ns~380ns
- led_in=0;NOP25(); //580ns~1000ns
- }
- }
-
- /******************************
- 發送字節到WS2812
- ******************************/
- void WS2812_SendByte(unsigned char dat)
- {
- unsigned char i;
- for (i=0;i<8;i++)
- {
- dat<<=1; //左移一位
- WS2812_Send(CY); //發送最高位
- }
- }
-
- /******************************
- 發送RGB顏色到WS2812
- ******************************/
- void WS2812_SendColor(unsigned char red,unsigned char green,unsigned char blue)
- {
- WS2812_SendByte(green);
- WS2812_SendByte(red);
- WS2812_SendByte(blue);
- }
-
- /******************************
- 刷新LED顯示
- ******************************/
- void WS2812_Display(unsigned char red,unsigned char green,unsigned char blue)
- {
- unsigned int i;
- for (i=0;i<led_max;i++)
- {
- WS2812_SendColor(red,green,blue);
- }
- led_in=0;
- Delay(1);
- }
-
- /******************************
- 清空緩存數組
- ******************************/
- void WS2812_BuffClear()
- {
- unsigned int i;
- for(i=0;i<led_max;i++)
- {
- Buff[i][0]=0;
- Buff[i][1]=0;
- Buff[i][2]=0;
- }
- }
-
- /******************************
- 指定某點,某顏色寫入緩存
- ******************************/
- void WS2812_D0T(unsigned char num,unsigned char red,unsigned char green,unsigned char blue)
- {
- Buff[num][0]=red;
- Buff[num][1]=green;
- Buff[num][2]=blue;
- }
復制代碼 |
-
1.png
(175.13 KB, 下載次數: 0)
下載附件
2024-12-4 18:28 上傳
|