This is what I have so far:
#include <p32xxxx.h>
#include <plib.h>
#define CLK (80000000L) // system clock
#define PBCLK (CLK / 2)
#define PWM_SIZE 800000 //ws2812 requires 1.25 us = 800 kHz
#define NUM_LEDS 60 //60 leds in a 1 meter strip
int ws2812[NUM_LEDS], PWM_0_HIGH, PWM_1_HIGH, green, red, blue;
void send_byte(int c){
int i;
for(i=1; i<=8; i++){
if((c & 0x80) == 0x80)
SetDCOC1PWM(PWM_1_HIGH);
else
SetDCOC1PWM(PWM_0_HIGH);
c = c << 2; //shift to next bit
}
}
void main(void)
{
SYSTEMConfigPerformance(CCLK);
mOSCSetPBDIV(OSC_PB_DIV_2);
OpenOC1(OC_ON|OC_TIMER_MODE32|OC_TIMER2_SRC|OC_PWM_FAULT_PIN_DISABLE,0,0); //Initialize OC1 for PWM
OpenTimer2(T2_ON | T2_PS_1_1 | T2_SOURCE_INT,MAX_PWM); //Setup Timer2 for PWM = 800 kHz
PWM_0_HIGH = 224000; //0.35 us out of 1.25 us (28% duty cycle)
PWM_1_HIGH = 448000; //0.7 us out of 1.25 us (56% duty cycle)
led[0] = 0xFF;
green = led[0];
output_byte(green);
led[0] = 0xFF;
red = led[0];
output_byte(red);
led[0] = 0xFF;
blue = led[0];
output_byte(blue);
}