今夜无眠,写此博客!
我们先来看时序图!
#include <STC15F2K60S2.H>
#include "intrins.h"
sbit WS2812 = P1^7;
#define numLEDs 8 //灯的个数
unsigned char buf_R[numLEDs] = {0};//颜色缓存
unsigned char buf_G[numLEDs] = {0};
unsigned char buf_B[numLEDs] = {0};
void RGB_Set_Up(); //送0码
void RGB_Set_Down(); //送1码
void HAL_Delay(unsigned int t)
{
unsigned int x,y;
for(x=114;x>0;x--)
for(y=t;y>0;y--);
}
//复位延时
void Delay50us() //@22.1184MHz
{
unsigned char i, j;
_nop_();
_nop_();
i = 2;
j = 15;
do
{
while (--j);
} while (--i);
}
//1码,高电平850ns 低电平400ns 误差正负150ns
void RGB_Set_Up()
{
WS2812 = 1;
//经过逻辑分析仪调试的的延时
_nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_();
_nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_();_nop_();
WS2812 = 0;
}
//1码,高电平400ns 低电平850ns 误差正负150ns
void RGB_Set_Down()
{
WS2812 = 1;
//