8 /* this holds the G R B bytes for the entire string */
9 unsigned char rgbdata[RGB_COUNT];
12 /* These values are placed in common memory so that they can be accessed
13 * quickly without a bank switch by the routines below, THIS IS IMPORTANT,
14 * it will not run properly without it */
15 volatile uint8_t rgb_sample @ 0x7B;
16 volatile uint8_t rgb_byte @ 0x7C;
17 volatile uint8_t rgb_bit @ 0x7D;
19 // send the whole pile of data
20 static void ws2811_send(void)
23 // copy the led colour array location into FSR0 for fast access
29 // load next byte from array into working reg
33 MOVLW 8 // reset bit count
37 // you assume its a zero then test if its one
38 // MOVLW 0xC0 ;11000000B
42 BTFSC STATUS,0 // CARRY
43 //asm("MOVLW 0xF8 "); // 11111000B
44 MOVLW 0xF0 // 11110000B
47 MOVWF BANKMASK(SSP1BUF)
72 #if _XTAL_FREQ != 32000000L
73 #error "This code requires 32MHz system clock or above"
76 void ws2811_init(void)
79 TRISAbits.TRISA0 = 0; // SDO is RA0
80 ANSELAbits.ANSA0 = 0; // not analog
82 // SCK (SPI Clock) is RA1
83 // SDI (SPI In) is RA2
84 APFCONbits.SDOSEL = 0; // use RA0 not RA4 for output
86 // at 8MHz Tclk 0 = 2 bits, 1 = 6 bits.
88 SSP1CON1bits.SSPM = 0b0000; // SPI Master Fosc/4
89 SSP1CON1bits.SSPEN = 1; // enable MSSP
92 void ws2811_transmit(void)
95 ws2811_send(); // send the first bit