Commit | Line | Data |
---|---|---|
5fc23db2 JM |
1 | Disassembly Listing for led_test |
2 | Generated From: | |
3 | /home/justin/MPLABXProjects/led_test.X/dist/XC8_PIC12F1840/debug/led_test.X.debug.cof | |
4 | 14-Jun-2013 12:31:18 | |
5 | ||
6 | --- /home/justin/MPLABXProjects/led_test.X/ws2811.c --------------------------------------------------- | |
7 | 1: #include <stdint.h> | |
8 | 2: #include <stdbool.h> | |
9 | 3: | |
10 | 4: #include "system.h" | |
11 | 5: #include "user.h" | |
12 | 6: | |
13 | 7: #include "ws2811.h" | |
14 | 8: | |
15 | 9: // how many LEDs are there | |
16 | 10: #define LED_COUNT 8 | |
17 | 11: | |
18 | 12: #define RGB_COUNT (LED_COUNT*3) | |
19 | 13: | |
20 | 14: #define SEND_ONE 0b11111000 | |
21 | 15: #define SEND_ZERO 0b11000000 | |
22 | 16: | |
23 | 17: unsigned rgbdata[RGB_COUNT]; | |
24 | 18: | |
25 | 19: volatile uint8_t rgb_sample = 0; | |
26 | 20: volatile int8_t rgb_byte = 0; | |
27 | 21: volatile int8_t rgb_bit = 0; | |
28 | 22: | |
29 | 23: #if 0 | |
30 | 24: /* interupt handling routine: | |
31 | 25: * aka: send next bit | |
32 | 26: */ | |
33 | 27: #pragma interrupt_level 1 | |
34 | 28: void ws2811_int(void) | |
35 | 29: { | |
36 | 30: //if (rgb_byte == 0) return; | |
37 | 31: | |
38 | 32: /* | |
39 | 33: rgb_sample <<= 1; | |
40 | 34: | |
41 | 35: if ( rgb_sample & 0x80 ) | |
42 | 36: SSP1BUF = SEND_ONE; | |
43 | 37: else | |
44 | 38: SSP1BUF = SEND_ZERO; | |
45 | 39: */ | |
46 | 40: | |
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"); | |
54 | 48: | |
55 | 49: asm("DECFSZ _rgb_bit,f"); | |
56 | 50: asm("RETURN"); | |
57 | 51: | |
58 | 52: /* next byte */ | |
59 | 53: | |
60 | 54: asm("MOVLW 8"); | |
61 | 55: asm("MOVWF _rgb_bit"); | |
62 | 56: asm("DECFSZ _rgb_byte"); | |
63 | 57: asm("BRA ws2811_loadnext"); | |
64 | 58: | |
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"); | |
69 | 63: asm("RETURN"); | |
70 | 64: | |
71 | 65: asm("ws2811_loadnext:"); | |
72 | 66: if (rgb_byte) | |
73 | 67: rgb_sample = rgbdata[rgb_byte-1]; | |
74 | 68: else | |
75 | 69: PIE1bits.SSP1IE = 0; | |
76 | 70: | |
77 | 71: } | |
78 | 72: #endif | |
79 | 73: | |
80 | 74: void ws2811_start(void) | |
81 | 75: { | |
82 | 76: rgb_byte = RGB_COUNT; | |
83 | 0760 3018 MOVLW 0x18 | |
84 | 0761 00F1 MOVWF 0x71 | |
85 | 0762 0871 MOVF 0x71, W | |
86 | 0763 00F8 MOVWF rgb_byte | |
87 | 77: ws2811_send(); // send the first bit | |
88 | 0764 3180 MOVLP 0x0 | |
89 | 0765 2000 CALL 0x0 | |
90 | 0766 3187 MOVLP 0x7 | |
91 | 78: } | |
92 | 0767 0008 RETURN | |
93 | 79: | |
94 | 80: bool ws2811_running(void) | |
95 | 81: { | |
96 | 82: if (rgb_byte) return true; | |
97 | 83: return false; | |
98 | 84: } | |
99 | --- /home/justin/MPLABXProjects/led_test.X/user.c ----------------------------------------------------- | |
100 | 1: /******************************************************************************/ | |
101 | 2: /* Files to Include */ | |
102 | 3: /******************************************************************************/ | |
103 | 4: | |
104 | 5: #if defined(__XC) | |
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 */ | |
108 | 9: #endif | |
109 | 10: | |
110 | 11: #include <stdint.h> /* For uint8_t definition */ | |
111 | 12: #include <stdbool.h> /* For true/false definition */ | |
112 | 13: | |
113 | 14: #include "user.h" | |
114 | 15: | |
115 | 16: /******************************************************************************/ | |
116 | 17: /* User Functions */ | |
117 | 18: /******************************************************************************/ | |
118 | 19: | |
119 | 20: /* <Initialize variables in user.h and insert code for user algorithms.> */ | |
120 | 21: | |
121 | 22: void InitApp(void) | |
122 | 23: { | |
123 | 24: /* TODO Initialize User Ports/Peripherals/Project here */ | |
124 | 25: | |
125 | 26: /* Setup analog functionality and port direction */ | |
126 | 27: | |
127 | 28: /* Initialize peripherals */ | |
128 | 29: | |
129 | 30: /* Enable interrupts */ | |
130 | 31: | |
131 | 32: // SPI MASTER mode div4 t-to-h | |
132 | 33: SSP1CON1bits.SSPEN = 1; // enable MSSP | |
133 | 0771 0024 MOVLB 0x4 | |
134 | 0772 1695 BSF TMR0, 0x5 | |
135 | 34: TRISAbits.TRISA0 = 0; // SDO is RA0 | |
136 | 0773 0021 MOVLB 0x1 | |
137 | 0774 100C BCF PORTA, 0x0 | |
138 | 35: ANSELAbits.ANSA0 = 0; // not analog | |
139 | 0775 0023 MOVLB 0x3 | |
140 | 0776 100C BCF PORTA, 0x0 | |
141 | 36: | |
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 | |
145 | 0777 0022 MOVLB 0x2 | |
146 | 0778 131D BCF 0x1D, 0x6 | |
147 | 40: | |
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 | |
151 | 0779 30F0 MOVLW 0xF0 | |
152 | 077A 0024 MOVLB 0x4 | |
153 | 077B 0595 ANDWF TMR0, F | |
154 | 44: | |
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 | |
159 | 49: | |
160 | 50: } | |
161 | 077C 0008 RETURN | |
162 | 51: | |
163 | 52: | |
164 | --- /home/justin/MPLABXProjects/led_test.X/system.c --------------------------------------------------- | |
165 | 1: /******************************************************************************/ | |
166 | 2: /* Files to Include */ | |
167 | 3: /******************************************************************************/ | |
168 | 4: | |
169 | 5: #if defined(__XC) | |
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 */ | |
173 | 9: #endif | |
174 | 10: | |
175 | 11: #include <stdint.h> /* For uint8_t definition */ | |
176 | 12: #include <stdbool.h> /* For true/false definition */ | |
177 | 13: | |
178 | 14: #include "system.h" | |
179 | 15: | |
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) | |
183 | 19: { | |
184 | 20: | |
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: */ | |
187 | 23: | |
188 | 24: /* TODO Configure OSCCAL if the device has an OSCCAL register */ | |
189 | 25: | |
190 | 26: #if 0 | |
191 | 27: | |
192 | 28: OSCCAL=_READ_OSCCAL_DATA(); /* _READ_OSCCAL_DATA macro unloads cal memory */ | |
193 | 29: | |
194 | 30: #endif | |
195 | 31: | |
196 | 32: /*Not all PIC12 devices require this. | |
197 | 33: | |
198 | 34: /* TODO Add clock switching code if appropriate. */ | |
199 | 35: | |
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. */ | |
203 | 39: | |
204 | 40: // Enable 32MHz internal clock 5.2.2.6 | |
205 | 41: OSCCONbits.SCS = 0b00; | |
206 | 0768 30FC MOVLW 0xFC | |
207 | 0769 0021 MOVLB 0x1 | |
208 | 076A 0599 ANDWF T1GCON, F | |
209 | 42: OSCCONbits.IRCF = 0b1110; | |
210 | 076B 0819 MOVF T1GCON, W | |
211 | 076C 3987 ANDLW 0x87 | |
212 | 076D 3870 IORLW 0x70 | |
213 | 076E 0099 MOVWF T1GCON | |
214 | 43: OSCCONbits.SPLLEN = 1; | |
215 | 076F 1799 BSF T1GCON, 0x7 | |
216 | 44: | |
217 | 45: | |
218 | 46: } | |
219 | 0770 0008 RETURN | |
220 | --- /home/justin/MPLABXProjects/led_test.X/main.c ----------------------------------------------------- | |
221 | 1: /******************************************************************************/ | |
222 | 2: /* Files to Include */ | |
223 | 3: /******************************************************************************/ | |
224 | 4: | |
225 | 5: #if defined(__XC) | |
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 */ | |
229 | 9: #endif | |
230 | 10: | |
231 | 11: #include <stdint.h> /* For uint8_t definition */ | |
232 | 12: #include <stdbool.h> /* For true/false definition */ | |
233 | 13: | |
234 | 14: #include "system.h" /* System funct/params, like osc/peripheral config */ | |
235 | 15: #include "user.h" /* User funct/params, such as InitApp */ | |
236 | 16: | |
237 | 17: #include "ws2811.h" | |
238 | 18: | |
239 | 19: /******************************************************************************/ | |
240 | 20: /* User Global Variable Declaration */ | |
241 | 21: /******************************************************************************/ | |
242 | 22: | |
243 | 23: /* i.e. uint8_t <variable_name>; */ | |
244 | 24: | |
245 | 25: /******************************************************************************/ | |
246 | 26: /* Main Program */ | |
247 | 27: /******************************************************************************/ | |
248 | 28: | |
249 | 29: void main(void) | |
250 | 30: { | |
251 | 31: /* Configure the oscillator for the device */ | |
252 | 32: ConfigureOscillator(); | |
253 | 078B 3187 MOVLP 0x7 | |
254 | 078C 2768 CALL 0x768 | |
255 | 078D 3187 MOVLP 0x7 | |
256 | 33: | |
257 | 34: /* Initialize I/O and Peripherals for application */ | |
258 | 35: InitApp(); | |
259 | 078E 3187 MOVLP 0x7 | |
260 | 078F 2771 CALL 0x771 | |
261 | 0790 3187 MOVLP 0x7 | |
262 | 36: | |
263 | 37: for (int j=0; j<RGB_COUNT; j+=3) { | |
264 | 0791 01F5 CLRF j | |
265 | 0792 01F6 CLRF 0x76 | |
266 | 0793 0876 MOVF 0x76, W | |
267 | 0794 3A80 XORLW 0x80 | |
268 | 0795 00FF MOVWF 0x7F | |
269 | 0796 3080 MOVLW 0x80 | |
270 | 0797 027F SUBWF 0x7F, W | |
271 | 0798 1D03 BTFSS STATUS, 0x2 | |
272 | 0799 2F9C GOTO 0x79C | |
273 | 079A 3018 MOVLW 0x18 | |
274 | 079B 0275 SUBWF j, W | |
275 | 079C 1C03 BTFSS STATUS, 0x0 | |
276 | 079D 2F9F GOTO 0x79F | |
277 | 079E 2FA0 GOTO 0x7A0 | |
278 | 079F 2FA2 GOTO 0x7A2 | |
279 | 07A0 2FD2 GOTO 0x7D2 | |
280 | 07A1 2FD2 GOTO 0x7D2 | |
281 | 07BF 3003 MOVLW 0x3 | |
282 | 07C0 07F5 ADDWF j, F | |
283 | 07C1 3000 MOVLW 0x0 | |
284 | 07C2 3DF6 ADDWFC 0x76, F | |
285 | 07C3 0876 MOVF 0x76, W | |
286 | 07C4 3A80 XORLW 0x80 | |
287 | 07C5 00FF MOVWF 0x7F | |
288 | 07C6 3080 MOVLW 0x80 | |
289 | 07C7 027F SUBWF 0x7F, W | |
290 | 07C8 1D03 BTFSS STATUS, 0x2 | |
291 | 07C9 2FCC GOTO 0x7CC | |
292 | 07CA 3018 MOVLW 0x18 | |
293 | 07CB 0275 SUBWF j, W | |
294 | 07CC 1C03 BTFSS STATUS, 0x0 | |
295 | 07CD 2FCF GOTO 0x7CF | |
296 | 07CE 2FD0 GOTO 0x7D0 | |
297 | 07CF 2FA2 GOTO 0x7A2 | |
298 | 07D0 2FD2 GOTO 0x7D2 | |
299 | 07D1 2FD2 GOTO 0x7D2 | |
300 | 38: rgbdata[j+0] = 0x20; // R | |
301 | 07A2 0875 MOVF j, W | |
302 | 07A3 0709 ADDWF WREG, W | |
303 | 07A4 3E20 ADDLW 0x20 | |
304 | 07A5 0086 MOVWF FSR1L | |
305 | 07A6 0187 CLRF FSR1H | |
306 | 07A7 3020 MOVLW 0x20 | |
307 | 07A8 3FC0 MOVWI [0]FSR1 | |
308 | 07A9 3000 MOVLW 0x0 | |
309 | 07AA 3FC1 MOVWI [1]FSR1 | |
310 | 39: rgbdata[j+1] = 0x20; // G | |
311 | 07AB 0875 MOVF j, W | |
312 | 07AC 0709 ADDWF WREG, W | |
313 | 07AD 3E02 ADDLW 0x2 | |
314 | 07AE 3E20 ADDLW 0x20 | |
315 | 07AF 0086 MOVWF FSR1L | |
316 | 07B0 0187 CLRF FSR1H | |
317 | 07B1 3020 MOVLW 0x20 | |
318 | 07B2 3FC0 MOVWI [0]FSR1 | |
319 | 07B3 3000 MOVLW 0x0 | |
320 | 07B4 3FC1 MOVWI [1]FSR1 | |
321 | 40: rgbdata[j+2] = 0x00; // B | |
322 | 07B5 0875 MOVF j, W | |
323 | 07B6 0709 ADDWF WREG, W | |
324 | 07B7 3E04 ADDLW 0x4 | |
325 | 07B8 3E20 ADDLW 0x20 | |
326 | 07B9 0086 MOVWF FSR1L | |
327 | 07BA 0187 CLRF FSR1H | |
328 | 07BB 3000 MOVLW 0x0 | |
329 | 07BC 3FC0 MOVWI [0]FSR1 | |
330 | 07BD 3000 MOVLW 0x0 | |
331 | 07BE 3FC1 MOVWI [1]FSR1 | |
332 | 41: } | |
333 | 42: | |
334 | 43: while(1) | |
335 | 07FD 2FD2 GOTO 0x7D2 | |
336 | 44: { | |
337 | 45: ws2811_start(); | |
338 | 07D2 3187 MOVLP 0x7 | |
339 | 07D3 2760 CALL 0x760 | |
340 | 07D4 3187 MOVLP 0x7 | |
341 | 46: | |
342 | 47: for (int j=0; j<10; j++) | |
343 | 07D5 01F3 CLRF j_41 | |
344 | 07D6 01F4 CLRF 0x74 | |
345 | 07D7 0874 MOVF 0x74, W | |
346 | 07D8 3A80 XORLW 0x80 | |
347 | 07D9 00FF MOVWF 0x7F | |
348 | 07DA 3080 MOVLW 0x80 | |
349 | 07DB 027F SUBWF 0x7F, W | |
350 | 07DC 1D03 BTFSS STATUS, 0x2 | |
351 | 07DD 2FE0 GOTO 0x7E0 | |
352 | 07DE 300A MOVLW 0xA | |
353 | 07DF 0273 SUBWF j_41, W | |
354 | 07E0 1C03 BTFSS STATUS, 0x0 | |
355 | 07E1 2FE3 GOTO 0x7E3 | |
356 | 07E2 2FE4 GOTO 0x7E4 | |
357 | 07E3 2FE6 GOTO 0x7E6 | |
358 | 07E4 2FD2 GOTO 0x7D2 | |
359 | 07E5 2FD2 GOTO 0x7D2 | |
360 | 07EA 3001 MOVLW 0x1 | |
361 | 07EB 07F3 ADDWF j_41, F | |
362 | 07EC 3000 MOVLW 0x0 | |
363 | 07ED 3DF4 ADDWFC 0x74, F | |
364 | 07EE 0874 MOVF 0x74, W | |
365 | 07EF 3A80 XORLW 0x80 | |
366 | 07F0 00FF MOVWF 0x7F | |
367 | 07F1 3080 MOVLW 0x80 | |
368 | 07F2 027F SUBWF 0x7F, W | |
369 | 07F3 1D03 BTFSS STATUS, 0x2 | |
370 | 07F4 2FF7 GOTO 0x7F7 | |
371 | 07F5 300A MOVLW 0xA | |
372 | 07F6 0273 SUBWF j_41, W | |
373 | 07F7 1C03 BTFSS STATUS, 0x0 | |
374 | 07F8 2FFA GOTO 0x7FA | |
375 | 07F9 2FFB GOTO 0x7FB | |
376 | 07FA 2FE6 GOTO 0x7E6 | |
377 | 07FB 2FD2 GOTO 0x7D2 | |
378 | 07FC 2FD2 GOTO 0x7D2 | |
379 | 48: DelayMs(100); | |
380 | 07E6 30B1 MOVLW 0xB1 | |
381 | 07E7 00F2 MOVWF 0x72 | |
382 | 07E8 0BF2 DECFSZ 0x72, F | |
383 | 07E9 2FE8 GOTO 0x7E8 | |
384 | 49: | |
385 | 50: } | |
386 | 51: } | |
387 | 07FE 3180 MOVLP 0x0 | |
388 | 52: | |
389 | --- /home/justin/MPLABXProjects/led_test.X/interrupts.c ----------------------------------------------- | |
390 | 1: /******************************************************************************/ | |
391 | 2: /*Files to Include */ | |
392 | 3: /******************************************************************************/ | |
393 | 4: | |
394 | 5: #if defined(__XC) | |
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 */ | |
398 | 9: #endif | |
399 | 10: | |
400 | 11: #include <stdint.h> /* For uint8_t definition */ | |
401 | 12: #include <stdbool.h> /* For true/false definition */ | |
402 | 13: | |
403 | 14: #include "ws2811.h" | |
404 | 15: | |
405 | 16: /******************************************************************************/ | |
406 | 17: /* Interrupt Routines */ | |
407 | 18: /******************************************************************************/ | |
408 | 19: | |
409 | 20: /* Baseline devices don't have interrupts. Unfortunately the baseline detection | |
410 | 21: * macro is named _PIC12 */ | |
411 | 22: | |
412 | 23: | |
413 | 24: | |
414 | 25: void interrupt isr(void) | |
415 | 26: { | |
416 | 0004 3180 MOVLP 0x0 | |
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 | |
420 | 30: time errors. */ | |
421 | 31: | |
422 | 32: #if 0 | |
423 | 33: if (PIR1bits.SSP1IF) { | |
424 | 34: ws2811_int(); | |
425 | 35: } | |
426 | 36: #endif | |
427 | 37: } | |
428 | 0008 0870 MOVF 0x70, W | |
429 | 38: | |
430 | 39: |