123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- #include "sk9822.h"
- #include "public.h"
- //写一个字节数据函数
- void SK9822_Write_Byte(unsigned char Data)
- {
- unsigned char i=0;
- for(i=0;i<8;i++)
- {
- //SDI=(Data&0x80)>>7;
- if(Data&0x80)
- {
- SK9822_SDI_PIN_H();
- }else
- {
- SK9822_SDI_PIN_L();
- }
- Data<<=1;
- system_delay_us(1);
- SK9822_SCK_PIN_H();
- system_delay_us(1);
- SK9822_SCK_PIN_L();
- system_delay_us(1);
- }
- }
- //函数名称:SK9822写数据函数
- //输入参数:Bri 亮度调整 高3位固定为1 取值范围00000-11111
- //输入参数:RED 红色灰度值 取值范围0-255
- //输入参数:GREEN 绿色灰度值
- //输入参数:BLUE 蓝色灰度值
- void SK9822_Write_Data(unsigned char Bri,unsigned char RED,unsigned char GREEN,unsigned char BLUE)
- {
-
- SK9822_Write_Byte(0x00);//写开始帧
- SK9822_Write_Byte(0x00);
- SK9822_Write_Byte(0x00);
- SK9822_Write_Byte(0x00);
- SK9822_Write_Byte(Bri);//写亮度值
- SK9822_Write_Byte(BLUE);//写蓝色灰度
- SK9822_Write_Byte(GREEN);//写绿色灰度
- SK9822_Write_Byte(RED);//写红色灰度
- SK9822_Write_Byte(0xFF);//写结束帧
- SK9822_Write_Byte(0xFF);
- SK9822_Write_Byte(0xFF);
- SK9822_Write_Byte(0xFF);
- }
- void SK9822_Intit(void)
- {
- SK9822_SCK_PIN_OUT();
- SK9822_SDI_PIN_OUT();
- SK9822_Write_Data(0,0,0,0);
- }
|