Hi! I’m working with a simple delay loop that can generate a PWM part (without a PWM module).
My target is to fade a LED smoothly.
I have a pair of tested values. By loading one of these values & call Main routine it will show the LED dim or full brightness.
What I need is to change DIM values to BRIGHT values nicely (linear) to make the LED fade.
Any method greatly appreciated.
Thanks
My target is to fade a LED smoothly.
I have a pair of tested values. By loading one of these values & call Main routine it will show the LED dim or full brightness.
What I need is to change DIM values to BRIGHT values nicely (linear) to make the LED fade.
Any method greatly appreciated.
Thanks
Code:
LED is very DIM by loading these values
;DIM movlw .255
; movwf SaveONtime
; movlw .1
; movwf saveONcount
; movlw .1
; movwf SaveOFFtime
; movlw .40
; movwf saveOFFcount
LED is fully BRIGHT by loading these values
;BRIGHT movlw .1
; movwf SaveONtime
; movlw .40
; movwf saveONcount
; movlw .255
; movwf SaveOFFtime
; movlw .1
; movwf saveOFFcount
Main call ON
call OFF
goto Main
ON movlw 0xff ;turn on leds
movwf PORTB
movf SaveONtime,W
movwf ONtime
movf saveONcount,W
movwf ONcount
loopON incfsz ONtime,F ;count up the on time
goto loopON
decfsz ONcount,F
goto $-3
return
OFF movlw 0x00 ;turn off leds
movwf PORTB
movf SaveOFFtime,W
movwf OFFtime
movf saveOFFcount,W
movwf OFFcount
loopOFF incfsz OFFtime,F ;count up the off time
goto loopOFF
decfsz OFFcount,F
goto $-3
return