Has anyone tried controlling a WS2812 RGB led driver from a PIC using flowcode V4?
Datasheet is here http://www.adafruit.com/datasheets/WS2812.pdf
It uses a single data input line that has it's own specifically timed data format (different length of pulse for 1 and 0, at a rate of 800khz with a delay between each group of bytes).
I assume the best way to control it is using bit banging and have had a look at the spi_byte flowcide macro but couldn't work out how to make it run at a precise rate. Would I be best to use an interrupt?
Can anyone suggest the best way to go?
Thanks
James
WS2812 Communication
Moderator: Benj
Re: WS2812 Communication
If anyone is interested then the following code seems to work. This was borrowed from http://www.vectric.com/forum/viewtopic.php?f=3&t=17937 then modified slightly to work with my PIC.
Pin B0 is connected to the data line of the WS2812
This assumes that the code runs at 8M instructions / sec.
James
Pin B0 is connected to the data line of the WS2812
Code: Select all
void OutputAZeroBit ()
{
portb = 0x01;
nop();
nop();
portb = 0x00;
nop();
nop();
nop();
}
//
void OutputAOneBit ()
{
portb = 0x01;
nop();
nop();
nop();
nop();
nop();
portb = 0x00;
}
//
void OutputByte (char Byte)
{
char i;
// data sent to the LEDs must be sent MSB first
for (i=1; i<=8 ; i++)
{
if ( Byte > 127 ) // Is MSB on?
OutputAOneBit();
else
OutputAZeroBit();
Byte = Byte * 2; // shift left one bit
}
}
James