Disassembly Listing for led_test Generated From: /home/justin/MPLABXProjects/led_test.X/dist/XC8_PIC12F1840/debug/led_test.X.debug.cof 14-Jun-2013 12:31:18 --- /home/justin/MPLABXProjects/led_test.X/ws2811.c --------------------------------------------------- 1: #include 2: #include 3: 4: #include "system.h" 5: #include "user.h" 6: 7: #include "ws2811.h" 8: 9: // how many LEDs are there 10: #define LED_COUNT 8 11: 12: #define RGB_COUNT (LED_COUNT*3) 13: 14: #define SEND_ONE 0b11111000 15: #define SEND_ZERO 0b11000000 16: 17: unsigned rgbdata[RGB_COUNT]; 18: 19: volatile uint8_t rgb_sample = 0; 20: volatile int8_t rgb_byte = 0; 21: volatile int8_t rgb_bit = 0; 22: 23: #if 0 24: /* interupt handling routine: 25: * aka: send next bit 26: */ 27: #pragma interrupt_level 1 28: void ws2811_int(void) 29: { 30: //if (rgb_byte == 0) return; 31: 32: /* 33: rgb_sample <<= 1; 34: 35: if ( rgb_sample & 0x80 ) 36: SSP1BUF = SEND_ONE; 37: else 38: SSP1BUF = SEND_ZERO; 39: */ 40: 41: asm("MOVLW 0xC0"); 42: asm("RLF _rgb_sample,f"); 43: //asm("BTFSC CARRY"); 44: asm("BTFSC STATUS,0"); 45: asm("MOVLW 0xF8"); 46: asm("BANKSEL (SSP1BUF)"); 47: asm("MOVWF SSP1BUF & 0x7F"); 48: 49: asm("DECFSZ _rgb_bit,f"); 50: asm("RETURN"); 51: 52: /* next byte */ 53: 54: asm("MOVLW 8"); 55: asm("MOVWF _rgb_bit"); 56: asm("DECFSZ _rgb_byte"); 57: asm("BRA ws2811_loadnext"); 58: 59: /* count is zero, were all done */ 60: asm("BANKSEL (PIE1)"); 61: //asm("BCF SSP1IE"); 62: asm("BCF PIE1 & 0x7F,3"); 63: asm("RETURN"); 64: 65: asm("ws2811_loadnext:"); 66: if (rgb_byte) 67: rgb_sample = rgbdata[rgb_byte-1]; 68: else 69: PIE1bits.SSP1IE = 0; 70: 71: } 72: #endif 73: 74: void ws2811_start(void) 75: { 76: rgb_byte = RGB_COUNT; 0760 3018 MOVLW 0x18 0761 00F1 MOVWF 0x71 0762 0871 MOVF 0x71, W 0763 00F8 MOVWF rgb_byte 77: ws2811_send(); // send the first bit 0764 3180 MOVLP 0x0 0765 2000 CALL 0x0 0766 3187 MOVLP 0x7 78: } 0767 0008 RETURN 79: 80: bool ws2811_running(void) 81: { 82: if (rgb_byte) return true; 83: return false; 84: } --- /home/justin/MPLABXProjects/led_test.X/user.c ----------------------------------------------------- 1: /******************************************************************************/ 2: /* Files to Include */ 3: /******************************************************************************/ 4: 5: #if defined(__XC) 6: #include /* XC8 General Include File */ 7: #elif defined(HI_TECH_C) 8: #include /* HiTech General Include File */ 9: #endif 10: 11: #include /* For uint8_t definition */ 12: #include /* For true/false definition */ 13: 14: #include "user.h" 15: 16: /******************************************************************************/ 17: /* User Functions */ 18: /******************************************************************************/ 19: 20: /* */ 21: 22: void InitApp(void) 23: { 24: /* TODO Initialize User Ports/Peripherals/Project here */ 25: 26: /* Setup analog functionality and port direction */ 27: 28: /* Initialize peripherals */ 29: 30: /* Enable interrupts */ 31: 32: // SPI MASTER mode div4 t-to-h 33: SSP1CON1bits.SSPEN = 1; // enable MSSP 0771 0024 MOVLB 0x4 0772 1695 BSF TMR0, 0x5 34: TRISAbits.TRISA0 = 0; // SDO is RA0 0773 0021 MOVLB 0x1 0774 100C BCF PORTA, 0x0 35: ANSELAbits.ANSA0 = 0; // not analog 0775 0023 MOVLB 0x3 0776 100C BCF PORTA, 0x0 36: 37: // SCK (SPI Clock) is RA1 38: // SDI (SPI In) is RA2 39: APFCONbits.SDOSEL = 0; // use RA0 not RA4 for output 0777 0022 MOVLB 0x2 0778 131D BCF 0x1D, 0x6 40: 41: // at 8MHz Tclk 0 = 2 bits, 1 = 6 bits. 42: // write to SSP1BUF 43: SSP1CON1bits.SSPM = 0b0000; // SPI Master Fosc/4 0779 30F0 MOVLW 0xF0 077A 0024 MOVLB 0x4 077B 0595 ANDWF TMR0, F 44: 45: // enable SPI interupts 46: // PIE1bits.SSP1IE = 1; // SPI interupt enable 47: // INTCONbits.PEIE = 1; // peripheral int enable 48: // INTCONbits.GIE = 1; // master int enable 49: 50: } 077C 0008 RETURN 51: 52: --- /home/justin/MPLABXProjects/led_test.X/system.c --------------------------------------------------- 1: /******************************************************************************/ 2: /* Files to Include */ 3: /******************************************************************************/ 4: 5: #if defined(__XC) 6: #include /* XC8 General Include File */ 7: #elif defined(HI_TECH_C) 8: #include /* HiTech General Include File */ 9: #endif 10: 11: #include /* For uint8_t definition */ 12: #include /* For true/false definition */ 13: 14: #include "system.h" 15: 16: /* Refer to the device datasheet for information about available 17: oscillator configurations and to compiler documentation for macro details. */ 18: void ConfigureOscillator(void) 19: { 20: 21: /*If the PIC12 device has an OSCCAL value, the HiTech Compiler provides 22: a macro called _READ_OSCCAL_DATA which can be loaded using this: */ 23: 24: /* TODO Configure OSCCAL if the device has an OSCCAL register */ 25: 26: #if 0 27: 28: OSCCAL=_READ_OSCCAL_DATA(); /* _READ_OSCCAL_DATA macro unloads cal memory */ 29: 30: #endif 31: 32: /*Not all PIC12 devices require this. 33: 34: /* TODO Add clock switching code if appropriate. */ 35: 36: /* Typical actions in this function are to tweak the oscillator tuning 37: register, select new clock sources, and to wait until new clock sources 38: are stable before resuming execution of the main project. */ 39: 40: // Enable 32MHz internal clock 5.2.2.6 41: OSCCONbits.SCS = 0b00; 0768 30FC MOVLW 0xFC 0769 0021 MOVLB 0x1 076A 0599 ANDWF T1GCON, F 42: OSCCONbits.IRCF = 0b1110; 076B 0819 MOVF T1GCON, W 076C 3987 ANDLW 0x87 076D 3870 IORLW 0x70 076E 0099 MOVWF T1GCON 43: OSCCONbits.SPLLEN = 1; 076F 1799 BSF T1GCON, 0x7 44: 45: 46: } 0770 0008 RETURN --- /home/justin/MPLABXProjects/led_test.X/main.c ----------------------------------------------------- 1: /******************************************************************************/ 2: /* Files to Include */ 3: /******************************************************************************/ 4: 5: #if defined(__XC) 6: #include /* XC8 General Include File */ 7: #elif defined(HI_TECH_C) 8: #include /* HiTech General Include File */ 9: #endif 10: 11: #include /* For uint8_t definition */ 12: #include /* For true/false definition */ 13: 14: #include "system.h" /* System funct/params, like osc/peripheral config */ 15: #include "user.h" /* User funct/params, such as InitApp */ 16: 17: #include "ws2811.h" 18: 19: /******************************************************************************/ 20: /* User Global Variable Declaration */ 21: /******************************************************************************/ 22: 23: /* i.e. uint8_t ; */ 24: 25: /******************************************************************************/ 26: /* Main Program */ 27: /******************************************************************************/ 28: 29: void main(void) 30: { 31: /* Configure the oscillator for the device */ 32: ConfigureOscillator(); 078B 3187 MOVLP 0x7 078C 2768 CALL 0x768 078D 3187 MOVLP 0x7 33: 34: /* Initialize I/O and Peripherals for application */ 35: InitApp(); 078E 3187 MOVLP 0x7 078F 2771 CALL 0x771 0790 3187 MOVLP 0x7 36: 37: for (int j=0; j /* XC8 General Include File */ 7: #elif defined(HI_TECH_C) 8: #include /* HiTech General Include File */ 9: #endif 10: 11: #include /* For uint8_t definition */ 12: #include /* For true/false definition */ 13: 14: #include "ws2811.h" 15: 16: /******************************************************************************/ 17: /* Interrupt Routines */ 18: /******************************************************************************/ 19: 20: /* Baseline devices don't have interrupts. Unfortunately the baseline detection 21: * macro is named _PIC12 */ 22: 23: 24: 25: void interrupt isr(void) 26: { 0004 3180 MOVLP 0x0 27: /* This code stub shows general interrupt handling. Note that these 28: conditional statements are not handled within 3 seperate if blocks. 29: Do not use a seperate if block for each interrupt flag to avoid run 30: time errors. */ 31: 32: #if 0 33: if (PIR1bits.SSP1IF) { 34: ws2811_int(); 35: } 36: #endif 37: } 0008 0870 MOVF 0x70, W 38: 39: