Fade: BTFSC mode, FADER ; fade out? GOTO FadeOut FadeIn: MOVLW PWMPR ; put the value to compare with in W SUBWF CCPR1L, W ; subtract W from the File Register and Set result in W BTFSC STATUS,C ; if CCPR1L >= PWMPR GOTO SetFadeOut ; yes MOVLW d'2' ADDWF CCPR1L,F GOTO Main SetFadeOut: BSF mode, FADER FadeOut: MOVLW d'2' SUBWF CCPR1L, F ; CLRW MOVLW d'2' SUBWF CCPR1L, W BTFSC STATUS,C ; if CCPR1L >= 1? GOTO Main ; Yes ; Swich to Fade In BCF mode, FADER CLRF CCPR1L GOTO Main