1 Disassembly Listing for led_test
3 /home/justin/MPLABXProjects/led_test.X/dist/XC8_PIC12F1840/debug/led_test.X.debug.cof
6 --- /home/justin/MPLABXProjects/led_test.X/ws2811.c ---------------------------------------------------
8 2: #include <stdbool.h>
10 4: #include "system.h"
13 7: #include "ws2811.h"
15 9: // how many LEDs are there
16 10: #define LED_COUNT 8
18 12: #define RGB_COUNT (LED_COUNT*3)
20 14: #define SEND_ONE 0b11111000
21 15: #define SEND_ZERO 0b11000000
23 17: unsigned rgbdata[RGB_COUNT];
25 19: volatile uint8_t rgb_sample = 0;
26 20: volatile int8_t rgb_byte = 0;
27 21: volatile int8_t rgb_bit = 0;
30 24: /* interupt handling routine:
31 25: * aka: send next bit
33 27: #pragma interrupt_level 1
34 28: void ws2811_int(void)
36 30: //if (rgb_byte == 0) return;
41 35: if ( rgb_sample & 0x80 )
42 36: SSP1BUF = SEND_ONE;
44 38: SSP1BUF = SEND_ZERO;
47 41: asm("MOVLW 0xC0");
48 42: asm("RLF _rgb_sample,f");
49 43: //asm("BTFSC CARRY");
50 44: asm("BTFSC STATUS,0");
51 45: asm("MOVLW 0xF8");
52 46: asm("BANKSEL (SSP1BUF)");
53 47: asm("MOVWF SSP1BUF & 0x7F");
55 49: asm("DECFSZ _rgb_bit,f");
61 55: asm("MOVWF _rgb_bit");
62 56: asm("DECFSZ _rgb_byte");
63 57: asm("BRA ws2811_loadnext");
65 59: /* count is zero, were all done */
66 60: asm("BANKSEL (PIE1)");
67 61: //asm("BCF SSP1IE");
68 62: asm("BCF PIE1 & 0x7F,3");
71 65: asm("ws2811_loadnext:");
73 67: rgb_sample = rgbdata[rgb_byte-1];
75 69: PIE1bits.SSP1IE = 0;
80 74: void ws2811_start(void)
82 76: rgb_byte = RGB_COUNT;
85 0762 0871 MOVF 0x71, W
86 0763 00F8 MOVWF rgb_byte
87 77: ws2811_send(); // send the first bit
94 80: bool ws2811_running(void)
96 82: if (rgb_byte) return true;
99 --- /home/justin/MPLABXProjects/led_test.X/user.c -----------------------------------------------------
100 1: /******************************************************************************/
101 2: /* Files to Include */
102 3: /******************************************************************************/
105 6: #include <xc.h> /* XC8 General Include File */
106 7: #elif defined(HI_TECH_C)
107 8: #include <htc.h> /* HiTech General Include File */
110 11: #include <stdint.h> /* For uint8_t definition */
111 12: #include <stdbool.h> /* For true/false definition */
113 14: #include "user.h"
115 16: /******************************************************************************/
116 17: /* User Functions */
117 18: /******************************************************************************/
119 20: /* <Initialize variables in user.h and insert code for user algorithms.> */
121 22: void InitApp(void)
123 24: /* TODO Initialize User Ports/Peripherals/Project here */
125 26: /* Setup analog functionality and port direction */
127 28: /* Initialize peripherals */
129 30: /* Enable interrupts */
131 32: // SPI MASTER mode div4 t-to-h
132 33: SSP1CON1bits.SSPEN = 1; // enable MSSP
134 0772 1695 BSF TMR0, 0x5
135 34: TRISAbits.TRISA0 = 0; // SDO is RA0
137 0774 100C BCF PORTA, 0x0
138 35: ANSELAbits.ANSA0 = 0; // not analog
140 0776 100C BCF PORTA, 0x0
142 37: // SCK (SPI Clock) is RA1
143 38: // SDI (SPI In) is RA2
144 39: APFCONbits.SDOSEL = 0; // use RA0 not RA4 for output
146 0778 131D BCF 0x1D, 0x6
148 41: // at 8MHz Tclk 0 = 2 bits, 1 = 6 bits.
149 42: // write to SSP1BUF
150 43: SSP1CON1bits.SSPM = 0b0000; // SPI Master Fosc/4
153 077B 0595 ANDWF TMR0, F
155 45: // enable SPI interupts
156 46: // PIE1bits.SSP1IE = 1; // SPI interupt enable
157 47: // INTCONbits.PEIE = 1; // peripheral int enable
158 48: // INTCONbits.GIE = 1; // master int enable
164 --- /home/justin/MPLABXProjects/led_test.X/system.c ---------------------------------------------------
165 1: /******************************************************************************/
166 2: /* Files to Include */
167 3: /******************************************************************************/
170 6: #include <xc.h> /* XC8 General Include File */
171 7: #elif defined(HI_TECH_C)
172 8: #include <htc.h> /* HiTech General Include File */
175 11: #include <stdint.h> /* For uint8_t definition */
176 12: #include <stdbool.h> /* For true/false definition */
178 14: #include "system.h"
180 16: /* Refer to the device datasheet for information about available
181 17: oscillator configurations and to compiler documentation for macro details. */
182 18: void ConfigureOscillator(void)
185 21: /*If the PIC12 device has an OSCCAL value, the HiTech Compiler provides
186 22: a macro called _READ_OSCCAL_DATA which can be loaded using this: */
188 24: /* TODO Configure OSCCAL if the device has an OSCCAL register */
192 28: OSCCAL=_READ_OSCCAL_DATA(); /* _READ_OSCCAL_DATA macro unloads cal memory */
196 32: /*Not all PIC12 devices require this.
198 34: /* TODO Add clock switching code if appropriate. */
200 36: /* Typical actions in this function are to tweak the oscillator tuning
201 37: register, select new clock sources, and to wait until new clock sources
202 38: are stable before resuming execution of the main project. */
204 40: // Enable 32MHz internal clock 5.2.2.6
205 41: OSCCONbits.SCS = 0b00;
208 076A 0599 ANDWF T1GCON, F
209 42: OSCCONbits.IRCF = 0b1110;
210 076B 0819 MOVF T1GCON, W
213 076E 0099 MOVWF T1GCON
214 43: OSCCONbits.SPLLEN = 1;
215 076F 1799 BSF T1GCON, 0x7
220 --- /home/justin/MPLABXProjects/led_test.X/main.c -----------------------------------------------------
221 1: /******************************************************************************/
222 2: /* Files to Include */
223 3: /******************************************************************************/
226 6: #include <xc.h> /* XC8 General Include File */
227 7: #elif defined(HI_TECH_C)
228 8: #include <htc.h> /* HiTech General Include File */
231 11: #include <stdint.h> /* For uint8_t definition */
232 12: #include <stdbool.h> /* For true/false definition */
234 14: #include "system.h" /* System funct/params, like osc/peripheral config */
235 15: #include "user.h" /* User funct/params, such as InitApp */
237 17: #include "ws2811.h"
239 19: /******************************************************************************/
240 20: /* User Global Variable Declaration */
241 21: /******************************************************************************/
243 23: /* i.e. uint8_t <variable_name>; */
245 25: /******************************************************************************/
246 26: /* Main Program */
247 27: /******************************************************************************/
251 31: /* Configure the oscillator for the device */
252 32: ConfigureOscillator();
257 34: /* Initialize I/O and Peripherals for application */
263 37: for (int j=0; j<RGB_COUNT; j+=3) {
266 0793 0876 MOVF 0x76, W
270 0797 027F SUBWF 0x7F, W
271 0798 1D03 BTFSS STATUS, 0x2
275 079C 1C03 BTFSS STATUS, 0x0
284 07C2 3DF6 ADDWFC 0x76, F
285 07C3 0876 MOVF 0x76, W
289 07C7 027F SUBWF 0x7F, W
290 07C8 1D03 BTFSS STATUS, 0x2
294 07CC 1C03 BTFSS STATUS, 0x0
300 38: rgbdata[j+0] = 0x20; // R
302 07A3 0709 ADDWF WREG, W
304 07A5 0086 MOVWF FSR1L
307 07A8 3FC0 MOVWI [0]FSR1
309 07AA 3FC1 MOVWI [1]FSR1
310 39: rgbdata[j+1] = 0x20; // G
312 07AC 0709 ADDWF WREG, W
315 07AF 0086 MOVWF FSR1L
318 07B2 3FC0 MOVWI [0]FSR1
320 07B4 3FC1 MOVWI [1]FSR1
321 40: rgbdata[j+2] = 0x00; // B
323 07B6 0709 ADDWF WREG, W
326 07B9 0086 MOVWF FSR1L
329 07BC 3FC0 MOVWI [0]FSR1
331 07BE 3FC1 MOVWI [1]FSR1
342 47: for (int j=0; j<10; j++)
345 07D7 0874 MOVF 0x74, W
349 07DB 027F SUBWF 0x7F, W
350 07DC 1D03 BTFSS STATUS, 0x2
353 07DF 0273 SUBWF j_41, W
354 07E0 1C03 BTFSS STATUS, 0x0
361 07EB 07F3 ADDWF j_41, F
363 07ED 3DF4 ADDWFC 0x74, F
364 07EE 0874 MOVF 0x74, W
368 07F2 027F SUBWF 0x7F, W
369 07F3 1D03 BTFSS STATUS, 0x2
372 07F6 0273 SUBWF j_41, W
373 07F7 1C03 BTFSS STATUS, 0x0
382 07E8 0BF2 DECFSZ 0x72, F
389 --- /home/justin/MPLABXProjects/led_test.X/interrupts.c -----------------------------------------------
390 1: /******************************************************************************/
391 2: /*Files to Include */
392 3: /******************************************************************************/
395 6: #include <xc.h> /* XC8 General Include File */
396 7: #elif defined(HI_TECH_C)
397 8: #include <htc.h> /* HiTech General Include File */
400 11: #include <stdint.h> /* For uint8_t definition */
401 12: #include <stdbool.h> /* For true/false definition */
403 14: #include "ws2811.h"
405 16: /******************************************************************************/
406 17: /* Interrupt Routines */
407 18: /******************************************************************************/
409 20: /* Baseline devices don't have interrupts. Unfortunately the baseline detection
410 21: * macro is named _PIC12 */
414 25: void interrupt isr(void)
417 27: /* This code stub shows general interrupt handling. Note that these
418 28: conditional statements are not handled within 3 seperate if blocks.
419 29: Do not use a seperate if block for each interrupt flag to avoid run
423 33: if (PIR1bits.SSP1IF) {
428 0008 0870 MOVF 0x70, W