Initial import of v2 goggles that use ws2812 rings from adafruit
[goggles] / helper.asm
CommitLineData
5fc23db2
JM
1#include <xc.inc>
2#include <pic12f1840.inc>
3
4 OPT LIST
5
6GLOBAL _rgb_sample
7GLOBAL _rgb_bit
8GLOBAL _rgb_byte
9GLOBAL _rgbdata
10
11GLOBAL _ws2811_send
12
13PSECT mytext,local,class=CODE,delta=2
14
15; send the whole pile of data
16_ws2811_send:
17 ; copy the led colour array into FSR0 for fast access
18 MOVLW _rgbdata >> 8
19 MOVWF FSR0H
20 MOVLW _rgbdata & 0xFF
21 MOVWF FSR0L
22
23
24 ; load next byte from array into working reg
25ws2811_nextbyte:
26 MOVIW FSR0++
27 MOVWF _rgb_sample
28 MOVLW 8 ; reset bit count
29 MOVWF _rgb_bit
30
31ws2811_sendbit:
32 ; you assume its a zero then test if its one
33 MOVLW 0xC0 ;11000000B
34 RLF _rgb_sample,f
35 BTFSC CARRY
36 MOVLW 0xF8 ; 11111000B
37
38; // wait until the buffer is empty
39;ws2811_waitsend:
40; BTFSC PIR1, 3
41; BRA ws2811_waitsend
42
43 ; send the bit
44 BANKSEL (SSP1BUF)
45 MOVWF BANKMASK(SSP1BUF)
46
47 ; any more bits
48 DECFSZ _rgb_bit,f
49 BRA ws2811_sendbit
50
51 ; any more bytes
52 DECFSZ _rgb_byte,f
53 BRA ws2811_nextbyte
54
55 ; all done
56 RETURN