Skip to content

Instantly share code, notes, and snippets.

@julianh2o
Created August 6, 2015 03:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julianh2o/99443c2396dcbcfda452 to your computer and use it in GitHub Desktop.
Save julianh2o/99443c2396dcbcfda452 to your computer and use it in GitHub Desktop.
#include <xc.inc>
#define STRIP_LENGTH 10
#define LED_STRIP PORTA, 0
GLOBAL _led_buffer
GLOBAL _populateLeds
PSECT ledcode,class=CODE,reloc=2
_populateLeds:
BSF PIR1, 1 //Set the interrupt flag so that we pass through the initial wait loop without waiting
; LFSR 0,_led_buffer //1
; MOVF POSTINC0, 0 //1
; BZ zeroresult
; BSF PORTB, 5
; RETURN
;
;zeroresult:
; BCF PORTB, 5
; RETURN
LFSR 0,_led_buffer //1
MOVF POSTINC0, 0 //1
MOVWF RXB1D7 //1
startStrip:
//CURRENT LED
MOVLW 10//1
MOVWF RXB1D4 //1
//CURRENT COLOR COMPONENT
MOVLW 3//1
MOVWF RXB1D5 //1
//CURRENT BIT
MOVLW 8//1
MOVWF RXB1D6 //1
timerWaitLoop2:
BTFSS PIR1, 1 //1, 2 or 3
BRA timerWaitLoop2
BSF LED_STRIP ///////////////////////////////////////////////// SET
//clear timer overflow (timer trips again in 20 cycles)
BCF PIR1, 1 //1
//bit shift and set carry flag
RLCF RXB1D7, 1, 0 //1
//BRA transmitOne
//BC transmitOne //1 or 2
NOP
transmitZero:
BCF LED_STRIP///////////////////////////////////////////////// CLEAR
//Decrement current bit, jump if nonzero
DECF RXB1D6, 1 //1
BNZ timerWaitLoop2
//load a new byte into memory
MOVF POSTINC0, 0 //1
MOVWF RXB1D7 //1
//CURRENT BIT
MOVLW 8//1
MOVWF RXB1D6 //1
//Decrement component count
DECF RXB1D5, 1 //1
BNZ timerWaitLoop2
MOVLW 3//1
MOVWF RXB1D5 //1
//Decrement LED count
DECF RXB1D4, 1 //1
BNZ timerWaitLoop2
BRA done
transmitOne:
//we have a maximum of 5 cycles here
//count NOPs
NOP
NOP
NOP
NOP
NOP
BCF LED_STRIP ///////////////////////////////////////////////// CLEAR
//Decrement current bit, jump if nonzero
DECF RXB1D6, 1 //1
BNZ timerWaitLoop2
//load a new byte into memory
MOVF POSTINC0, 0 //1
//MOVLW 10//1
MOVWF RXB1D7 //1
//CURRENT BIT
MOVLW 8//1
MOVWF RXB1D6 //1
//decrement component count
DECF RXB1D5, 1 //1
BNZ timerWaitLoop2
MOVLW 3//1
MOVWF RXB1D5 //1
//decrement LED count
DECF RXB1D4, 1 //1
BNZ timerWaitLoop2
done:
//################### ASM RESET ##############
// sents a reset to the LED strip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment