; PWM Function
_pwm movfw vc0 ; AND all 5 bits of vertical counter
andwf vc1,W
andwf vc2,W
andwf vc3,W
andwf vc4,W
iorwf copyPORTB,F ; then OR bits with copyPORTB working variable
movfw copyPORTB ; load in W
movwf PORTB ; and write to physical PORTB
; when 5 bits in vertical count reach 11111
; corresponding Port bit is turned on and then
; remains on until counter is reset
movwf PORTA
; ---------------------------------------
; 2^5 bit x 8 vertical counter
; generates the pwm for the 8 channel LED output
; More info on how this works can be found here
; http://everything2.com/e2node/vertical counter
; http://www.dattalo.com/technical/software/pic/vertcnt.html
_vc32 movf vc3,W
andwf vc2,W
andwf vc1,W
andwf vc0,W
xorwf vc4,F
movf vc2,W
andwf vc1,W
andwf vc0,W
xorwf vc3,F
movf vc1,W
andwf vc0,W
xorwf vc2,F
movf vc0,W
xorwf vc1,F
comf vc0,F
; ---------------------------------------
decfsz pwm,F ; decrement PWM counter
return ; return if count != 0
; reset and reload PWM output / counter
movlw .31 ; reload PWM counter
movwf pwm
clrf copyPORTB ; reset output port working variable
; vertical counter is 8 channels by 5 bits
; rvc1 rvc0 vc4-0 PWM ratio
; 0 0 00000 0/31 off
; 0 1 00001 1/31 dim
; 1 0 00100 8/31 bright
; 1 1 11111 31/31 very bright
;
movfw loReload ; reload the vertical counter
movwf vc0
movfw hiReload
movwf vc3
andwf loReload,W
movwf vc1
movwf vc2
movwf vc4
return