sk9822.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "sk9822.h"
  2. #include "public.h"
  3. //写一个字节数据函数
  4. void SK9822_Write_Byte(unsigned char Data)
  5. {
  6. unsigned char i=0;
  7. for(i=0;i<8;i++)
  8. {
  9. //SDI=(Data&0x80)>>7;
  10. if(Data&0x80)
  11. {
  12. SK9822_SDI_PIN_H();
  13. }else
  14. {
  15. SK9822_SDI_PIN_L();
  16. }
  17. Data<<=1;
  18. system_delay_us(1);
  19. SK9822_SCK_PIN_H();
  20. system_delay_us(1);
  21. SK9822_SCK_PIN_L();
  22. system_delay_us(1);
  23. }
  24. }
  25. //函数名称:SK9822写数据函数
  26. //输入参数:Bri 亮度调整 高3位固定为1 取值范围00000-11111
  27. //输入参数:RED 红色灰度值 取值范围0-255
  28. //输入参数:GREEN 绿色灰度值
  29. //输入参数:BLUE 蓝色灰度值
  30. void SK9822_Write_Data(unsigned char Bri,unsigned char RED,unsigned char GREEN,unsigned char BLUE)
  31. {
  32. SK9822_Write_Byte(0x00);//写开始帧
  33. SK9822_Write_Byte(0x00);
  34. SK9822_Write_Byte(0x00);
  35. SK9822_Write_Byte(0x00);
  36. SK9822_Write_Byte(Bri);//写亮度值
  37. SK9822_Write_Byte(BLUE);//写蓝色灰度
  38. SK9822_Write_Byte(GREEN);//写绿色灰度
  39. SK9822_Write_Byte(RED);//写红色灰度
  40. SK9822_Write_Byte(0xFF);//写结束帧
  41. SK9822_Write_Byte(0xFF);
  42. SK9822_Write_Byte(0xFF);
  43. SK9822_Write_Byte(0xFF);
  44. }
  45. void SK9822_Intit(void)
  46. {
  47. SK9822_SCK_PIN_OUT();
  48. SK9822_SDI_PIN_OUT();
  49. SK9822_Write_Data(0,0,0,0);
  50. }