#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);
}