Code:
'****************************************************************
'* Name : fader.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2016 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 6/30/2016 *
'* Version : 1.0 *
'* Notes : pic16f1825 *
'* : *
'****************************************************************
#CONFIG
__config _CONFIG1, _FOSC_INTOSC & _CP_OFF & _WDTE_ON & _PWRTE_ON & _MCLRE_ON & _CLKOUTEN_OFF
__config _CONFIG2, _PLLEN_ON & _LVP_OFF
#ENDCONFIG
DEFINE OSC 32
goto overpwm
my_pwm:
;100 step 1.35 gamma curve
@ dW 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
@ dW 1, 1, 1, 1, 1, 1, 2, 2, 2, 2
@ dW 2, 2, 2, 2, 2, 3, 3, 3, 3, 3
@ dW 3, 4, 4, 4, 4, 5, 5, 5, 6, 6
@ dW 6, 7, 7, 8, 8, 9, 9, 10, 11, 11
@ dW 12, 13, 14, 15, 16, 17, 18, 20, 21, 23
@ dW 24, 26, 28, 30, 33, 35, 38, 41, 44, 47
@ dW 51, 55, 59, 64, 69, 74, 80, 86, 93,101
@ dW 109,118,128,138,150,162,176,190,206,224
@ dW 243,263,286,310,337,366,398,433,471,511
ASM
;---[Returns the Address of a Label as a Word]------------------------------
GetAddress macro Label, Wout
CHK?RP Wout
movlw low Label ; get low byte
movwf Wout
; movlw High Label ; get high byte MPLAB 8.53 killed high
movlw Label >> 8 ; get high byte
movwf Wout + 1
endm
endasm
overpwm:
OSCCON=$70
ANSELA=0
ANSELC=0
paddress var word
pw var word
pl var byte
pl2 var word
inc var word
t2con=5
TRISA = %111110
TRISC = %11010011 ' set PORTC I/O
led1 var portc.3 ; 10 bit straight pwm
led2 var portc.5 ; 10 bit 100 step gamma corrected pwm
@ GetAddress _my_pwm,_paddress
pl2 =0
pl=100
main:
inc=1
while pl
pl=pl-1
gosub setpwm
pause 50
wend
inc=-1
while pl < 99
pl=pl+1
gosub setpwm
pause 50
wend
goto main
setpwm:
readcode paddress+pl ,pw
CCPR1L = PW>>2;
ccp1con=12|((PW&3)<<4); led2
pl2 =pl2 +inc
if pl2 >1023 then pl2 =0
CCPR2L = Pl2>>2; led1
ccp2con=12|((Pl2&3)<<4);
return
Bookmarks