SN3193呼吸灯驱动调试
首先将SN3193的enable引脚拉高
设置 04 05 06 寄存器的PWM为0xff ,亮度为最亮
ox1d 寄存器写07 ,3个LED点亮,
设置以后但是不亮,
后来对 07寄存器写0xff 就亮了,因为4, 5, 6寄存器写后没有生效,要对7寄存器写一个值进去,4 ,5, 6寄存器的值才生效,led就可以点亮了!!!!!!!!!!!!!!!
0x02 寄存器写0x20 ,呼吸功能 写0就是长亮LED功能,默认是0
static int SN3193_SetBreathTime_sled(u8 Ch, u8 T0,u8 T1,u8 T2,u8 T3,u8 T4)
{
int ret=0;
switch ( Ch)
{
case 1:
SN3193_write_reg(0x0a,T0<<4); //T0(time of holding off)
SN3193_write_reg(0x10,(T1<<5)|(T2<<1)); //T1&T2(time of ramping up and hold on
SN3193_write_reg(0x16,(T3<<5)|(T4<<1)); //T3&T4(time of ramping down and hold off)
break;
case 2:
SN3193_write_reg(0x0b,T0<<4);
SN3193_write_reg(0x11,(T1<<5)|(T2<<1));
SN3193_write_reg(0x17,(T3<<5)|(T4<<1));
break;
case 3:
SN3193_write_reg(0x0c,T0<<4);
SN3193_write_reg(0x12,(T1<<5)|(T2<<1));
SN3193_write_reg(0x18,(T3<<5)|(T4<<1));
break;
}
return ret;
}
T2
/---------------\
/ \T3
T1/ \
/ \
T0 / \
---------/ \--------T4-------
0xA 0xB 0xC
D7:D4 T0
0000 0
0001 0.13
0010 0.26
0011 0.52
0100 1.04 -
0101 2.08
0110 4.16
0111 8.32
1000 16.64
1001 33.28
1010 66.56
0x10 0x11 0x12 T1和T2寄存器
D7:D5 T1 0.13---0.26---0.52----1.04----2.08----4.16-----8.32-----16.64S rising level
D4:D1 T2 0--0.13----16.64 high level
D7:D5 T1
000 0.13
001 0.26
010 0.52
011 1.04
100 2.08
101 4.16
110 8.32
111 16.64S
D4:D1 T2
0000 0
0001 0.13
0010 0.26
0011 0.52
0100 1.04 -
0101 2.08
0110 4.16
0111 8.32
1000 16.64
0x16 0x17 0x18
D7:D5 T3 0.13---16.64S falling time
D4:D1 T4 0--0.13----66.56 low time
D7:D5 T3
000 0.13
001 0.26
010 0.52
011 1.04
100 2.08
101 4.16
110 8.32
111 16.64S
D4:D1 T4
0000 0
0001 0.13
0010 0.26
0011 0.52
0100 1.04
0101 2.08
0110 4.16
0111 8.32
1000 16.64
1001 33.28
1010 66.56
0x1c 时间更新寄存器 写任意值进去时间寄存器的值才生效
void display_led(uint8 on)
{
SN3193_hw_enable(); //enable hardware control pin
busywait(100000);
I2C_Byte_Write(0xd0,0x00,0x20); //enable all channel
busywait(10000);
I2C_Byte_Write(0xd0,0x03,0x08); //setting current 5ma
busywait(10000);
if(on)
I2C_Byte_Write(0xd0,0x1d,0x7); //enable red green blue led
else
I2C_Byte_Write(0xd0,0x1d,0x0);
busywait(10000);
I2C_Byte_Write(0xd0,0x4,0xff); //setting red led PWM to max 0xff
busywait(10000);
I2C_Byte_Write(0xd0,0x5,0x0); //setting green led PWM to 0
busywait(10000);
I2C_Byte_Write(0xd0,0x6,0x0); //setting blue led PWM to 0
busywait(10000);
I2C_Byte_Write(0xd0,0x2,0x20); //led control one time program mode
busywait(10000);
I2C_Byte_Write(0xd0,0xa,0x40); //red T0 1.04S low level
busywait(10000);
I2C_Byte_Write(0xd0,0xb,0x40); //green T0 1.04S low level
busywait(10000);
I2C_Byte_Write(0xd0,0xc,0x40); //blue T0 1.04S low level
busywait(10000);
I2C_Byte_Write(0xd0,0x10,0x08); //red T1 0.13S rising level T2 1.04S high level
busywait(10000);
I2C_Byte_Write(0xd0,0x11,0x08); //green T1 0.13S rising level T2 1.04S high level
busywait(10000);
I2C_Byte_Write(0xd0,0x12,0x08); //blue T1 0.13S rising level T2 1.04S high level
busywait(10000);
I2C_Byte_Write(0xd0,0x16,0x08); //red T3 0.13S falling level T4 1.04S low level
busywait(10000);
I2C_Byte_Write(0xd0,0x17,0x08); //green T3 0.13S falling level T4 1.04S low level
busywait(10000);
I2C_Byte_Write(0xd0,0x18,0x08); //blue T3 0.13S falling level T4 1.04S low level
busywait(10000);
I2C_Byte_Write(0xd0,0x1c,0xff); //update time
busywait(10000);
I2C_Byte_Write(0xd0,0x7,0xff); //update pwm
busywait(10000);
}
周期4秒呼吸
void display_led(uint8 on)
{
SN3193_hw_enable(); //enable hardware control pin
busywait(100000);
I2C_Byte_Write(0xd0,0x00,0x20); //enable all channel
busywait(10000);
I2C_Byte_Write(0xd0,0x03,0x08); //setting current 5ma
busywait(10000);
if(on)
I2C_Byte_Write(0xd0,0x1d,0x7); //enable red green blue led
else
I2C_Byte_Write(0xd0,0x1d,0x0);
busywait(10000);
I2C_Byte_Write(0xd0,0x4,0xff); //setting red led PWM to max 0xff
busywait(10000);
I2C_Byte_Write(0xd0,0x5,0x0); //setting green led PWM to 0
busywait(10000);
I2C_Byte_Write(0xd0,0x6,0x0); //setting blue led PWM to 0
busywait(10000);
I2C_Byte_Write(0xd0,0x2,0x20); //led control one time program mode
busywait(10000);
I2C_Byte_Write(0xd0,0xa,0x40); //red T0 1.04S low level
busywait(10000);
I2C_Byte_Write(0xd0,0xb,0x40); //green T0 1.04S low level
busywait(10000);
I2C_Byte_Write(0xd0,0xc,0x40); //blue T0 1.04S low level
busywait(10000);
I2C_Byte_Write(0xd0,0x10,0x68); //red T1 1.04S rising level T2 1.04S high level
busywait(10000);
I2C_Byte_Write(0xd0,0x11,0x68); //green T1 1.04S rising level T2 1.04S high level
busywait(10000);
I2C_Byte_Write(0xd0,0x12,0x68); //blue T1 1.04S rising level T2 1.04S high level
busywait(10000);
I2C_Byte_Write(0xd0,0x16,0x68); //red T3 1.04S falling level T4 1.04S low level
busywait(10000);
I2C_Byte_Write(0xd0,0x17,0x68); //green T3 1.04S falling level T4 1.04S low level
busywait(10000);
I2C_Byte_Write(0xd0,0x18,0x68); //blue T3 1.04S falling level T4 1.04S low level
busywait(10000);
I2C_Byte_Write(0xd0,0x1c,0xff); //update time
busywait(10000);
I2C_Byte_Write(0xd0,0x7,0xff); //update pwm
busywait(10000);
}