#include #include OPT LIST GLOBAL _rgb_sample GLOBAL _rgb_bit GLOBAL _rgb_byte GLOBAL _rgbdata GLOBAL _ws2811_send PSECT mytext,local,class=CODE,delta=2 ; send the whole pile of data _ws2811_send: ; copy the led colour array into FSR0 for fast access MOVLW _rgbdata >> 8 MOVWF FSR0H MOVLW _rgbdata & 0xFF MOVWF FSR0L ; load next byte from array into working reg ws2811_nextbyte: MOVIW FSR0++ MOVWF _rgb_sample MOVLW 8 ; reset bit count MOVWF _rgb_bit ws2811_sendbit: ; you assume its a zero then test if its one MOVLW 0xC0 ;11000000B RLF _rgb_sample,f BTFSC CARRY MOVLW 0xF8 ; 11111000B ; // wait until the buffer is empty ;ws2811_waitsend: ; BTFSC PIR1, 3 ; BRA ws2811_waitsend ; send the bit BANKSEL (SSP1BUF) MOVWF BANKMASK(SSP1BUF) ; any more bits DECFSZ _rgb_bit,f BRA ws2811_sendbit ; any more bytes DECFSZ _rgb_byte,f BRA ws2811_nextbyte ; all done RETURN