Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Check banksel stuff, could be causing issues
- ;
- ; do not change BCM_BITS, its always 8
- BCM_BITS equ 8
- BCM_CHANNELS equ 8
- BCM_BYTES equ (BCM_CHANNELS+7)/8
- messg "BCM_BYTES" #v(BCM_BYTES)
- bcm_variables macro
- bcm_slices res BCM_BITS*BCM_BYTES
- bcm_slices_dbuf res BCM_BITS*BCM_BYTES
- bcm_intensity res BCM_CHANNELS
- ; local variables
- bcm_portbits res 1
- bcm_bitvalue res 1
- bcm_bitpos res 1
- endm
- bcm_correct_data macro ; gamma correction array
- bcm_correct_table
- db 0, 1, 1, 1, 1, 1, 1, 1
- db 1, 1, 1, 1, 1, 1, 1, 1
- db 1, 1, 1, 1, 1, 1, 1, 1
- db 1, 1, 1, 1, 2, 2, 2, 2
- db 2, 2, 2, 2, 2, 2, 2, 2
- db 2, 2, 2, 2, 2, 2, 2, 2
- db 2, 2, 2, 2, 2, 2, 2, 2
- db 2, 3, 3, 3, 3, 3, 3, 3
- db 3, 3, 3, 3, 3, 3, 3, 3
- db 3, 3, 4, 4, 4, 4, 4, 4
- db 4, 4, 4, 4, 4, 4, 5, 5
- db 5, 5, 5, 5, 5, 5, 5, 6
- db 6, 6, 6, 6, 6, 6, 6, 7
- db 7, 7, 7, 7, 7, 7, 8, 8
- db 8, 8, 8, 9, 9, 9, 9, 9
- db 10, 10, 10, 10, 10, 11, 11, 11
- db 11, 12, 12, 12, 13, 13, 13, 13
- db 14, 14, 14, 15, 15, 15, 16, 16
- db 16, 17, 17, 18, 18, 19, 19, 19
- db 20, 20, 21, 21, 22, 22, 23, 23
- db 24, 25, 25, 26, 26, 27, 28, 28
- db 29, 30, 30, 31, 32, 33, 34, 34
- db 35, 36, 37, 38, 39, 40, 41, 42
- db 43, 44, 45, 46, 47, 48, 49, 51
- db 52, 53, 55, 56, 57, 59, 60, 62
- db 63, 65, 67, 68, 70, 72, 73, 75
- db 77, 79, 81, 83, 85, 88, 90, 92
- db 94, 97, 99, 102, 104, 107, 110, 113
- db 116, 118, 122, 125, 128, 131, 135, 138
- db 142, 145, 149, 153, 157, 161, 165, 169
- db 174, 178, 183, 188, 193, 198, 203, 208
- db 214, 219, 225, 231, 237, 243, 249, 255
- endm
- bcm_init macro
- BANKSEL bcm_slices
- CLRF bcm_bitpos, ACCESS
- CLRF bcm_bitvalue, ACCESS
- CLRF bcm_portbits, ACCESS
- LFSR FSR0, bcm_slices
- LFSR FSR1, bcm_slices_dbuf
- LFSR FSR2, bcm_intensity
- variable i
- i = 0
- while(i < BCM_CHANNELS)
- if(i < BCM_BITS)
- CLRF POSTINC0
- CLRF POSTINC1
- endif
- CLRF POSTINC2
- i++
- endw
- ; init timer and (possibly) compare shit here
- BANKSEL PIE1
- BSF PIE1, TMR2IE ; enable timer2 match interrupt
- ; only nesesary if the initial intensity is anything other than 0
- ;bcm_encode_slices ; encode initial timeslices
- CLRF TMR2 ; TMR2 = 0
- BSF PR2, 0x01 ; PR2 = 1
- MOVLW B'00100011' ; postscaler 4x, timer off, prescaler 16x
- MOVWF T2CON
- BSF T2CON, TMR2ON ; enable timer
- endm
- bcm_set_intensity_lit macro output, intensity
- BANKSEL bcm_intensity
- LFSR FSR2, bcm_intensity
- MOVLW output
- MOVFF intensity, PLUSW2
- endm
- bcm_encode_slices_inner_loop macro i
- LFSR FSR1, bcm_intensity
- variable j
- j = 0
- while(j < BCM_CHANNELS)
- local bcm_encode_skip_or_#v(i)_#v(j)
- MOVLW UPPER bcm_correct_table ; load up TBLPTR
- MOVWF TBLPTRU, ACCESS
- MOVLW HIGH bcm_correct_table
- MOVWF TBLPTRH, ACCESS
- MOVLW LOW bcm_correct_table
- MOVWF TBLPTRL, ACCESS
- BANKSEL bcm_intensity
- MOVLW j
- ;if j==0
- ;eusart_writeln_int PLUSW1
- ;endif
- MOVLW j
- MOVF PLUSW1, W, ACCESS
- ; add bcm_intensity[i] to TBLPTR with carry
- ADDWF TBLPTRL, f, ACCESS
- CLRF WREG
- ADDWFC TBLPTRH, f, ACCESS
- ADDWFC TBLPTRU, f, ACCESS
- TBLRD * ; grab corrected value and return in TABLAT
- MOVFF TABLAT, WREG
- ;BANKSEL STATUS
- ;MOVF POSTINC1, W, ACCESS
- ANDLW (0x01 << i)
- ; if W is 0
- bz bcm_encode_skip_or_#v(i)_#v(j) ; skip IORWF
- ; MOVLW (0x01 << j)
- ; IORWF bcm_portbits, f, ACCESS
- ; BANKSEL bcm_bitvalue
- MOVFF bcm_bitvalue, WREG ; bcm_portbits |= bcm_bitvalue
- IORWF bcm_portbits, f, ACCESS
- bcm_encode_skip_or_#v(i)_#v(j)
- ;BANKSEL STATUS
- BCF STATUS, C ; clear carry, makes the rotate op a plain shift op
- BANKSEL bcm_bitvalue
- RLCF bcm_bitvalue, f, ACCESS
- j++
- endw
- endm
- bcm_encode_slices macro
- ; might need to stop the timer here, just to be sure?
- ; at the very least, its probably a good idea to reset the TMR2/PR2 registers.
- variable i
- i = 0
- BANKSEL bcm_slices
- LFSR FSR0, bcm_slices_dbuf
- while(i < BCM_BITS)
- MOVLW 0x00
- MOVWF bcm_portbits, ACCESS
- MOVLW 0x01
- MOVWF bcm_bitvalue, ACCESS
- bcm_encode_slices_inner_loop i
- MOVLW i
- MOVFF bcm_portbits, PLUSW0
- i++
- endw
- LFSR FSR2, bcm_slices
- i=0
- while(i < BCM_BITS)
- MOVLW i
- MOVFF PLUSW0, PLUSW2
- i++
- endw
- endm
- bcm_write macro
- ; if BCM_BYTES == 1 ; shortcut for 8 channels or less
- BANKSEL bcm_slices
- LFSR FSR2, bcm_slices
- MOVFF bcm_bitpos, WREG
- sr_write 1, PLUSW2 ; sr_write(bcm_slices[bcm_bitpos])
- ;BTG PORTE, RE1 ; toggle status led
- ; else
- ; fill shit in later
- ; endif
- endm
- ; timer2 stuff
- ; -------------
- ;
- ; prescaler slows down the internal increment rate up to 16 times
- ; postscaler slows down the external TMR2:PR2 match interupt rate by up to 16 times
- ;
- ; prescaler set to 16x
- ; postscaler set to 4x
- ; scalers to equal a 64x minimum delay
- ; this should give a refresh of 488hz
- ;
- bcm_isr macro
- local bcm_isr_update_match
- local bcm_isr_end
- local bcm_isr_end_write
- BANKSEL PIR1
- BTFSS PIR1, TMR2IF ; if TMR2IF is set, skip the following branch, and run isr code
- bra bcm_isr_end ; if TMR2IF is NOT set, branch to end of bcm isr code
- banksel PORTE
- BTG PORTE, RE1, A ; toggle status led
- ; this is wrong, and I don't know why :(
- ;banksel bcm_slices
- ;bcm_write ; write current value
- ;BANKSEL TMR2
- ;CLRF TMR2 ; clear TMR2 counter
- BANKSEL bcm_bitpos
- INCF bcm_bitpos, F, ACCESS ; bcm_bitpos++
- MOVLW 0x07
- ANDWF bcm_bitpos, F, ACCESS ; bcm_bitpos &= 7
- ;TSTFSZ bcm_bitpos ; if not zero, update match register
- ;bra bcm_isr_update_match ; else reset
- bnz bcm_isr_update_match ; else reset TMR2:PR2
- BANKSEL PR2
- MOVLW 0x01
- MOVWF PR2, ACCESS
- bra bcm_isr_end_write ; stop processing macro, aka skip the bitpos reset
- bcm_isr_update_match
- ; setup delay
- BANKSEL STATUS
- BCF STATUS, C, ACCESS ; clear carry to turn rotate op into pure shift op
- RLCF PR2, f, ACCESS ; PR2 <<= 1
- bcm_isr_end_write
- bcm_write
- CLRF TMR2 ; clear TMR2 counter
- bcm_isr_end
- BCF PIR1, TMR2IF
- endm
Add Comment
Please, Sign In to add comment