Hi Hank, Bert,
Bert already gave you the answer, but just to clarify. The code I showed you doesn't alias anything. It is code that needs to execute when ever you want to change the dutycycle - as you've discovered. The easiest way IMHO is to simply create a subroutine and GOSUB it when you want the dutycycle changed, like:
Code:
Duty VAR BYTE
i VAR Byte
Main:
For i = 0 to 255 'Fade up
Gosub SetIt
Pause 2
Next
For i = 255 to 0 Step -1 'Fade down
Gosub SetIt
Pause 2
Next
Goto Main
SetIt:
CCP2CON.4 = Duty.0
CCP2CON.5 = Duty.1
CCPR2L = Duty >> 2
RETURN
Bookmarks