; --- PWM.asm ---- ; This program drives an RGB flashlight based upon the button pressed ; On time is 20% COLOR equ 0 CNT1 equ 1 #include org 0x800 call Init Loop: clrf PORTC ; Turn off the lights for four counts call Wait call Wait call Wait call Wait movf COLOR,W btfsc PORTB,0 ; if RB0 pressed, color = 000 (off) movlw 0 btfsc PORTB,1 ; if RB1 pressed, color = 001 (blue) movlw 1 btfsc PORTB,2 ; if RB2 pressed, color = 010 (green) movlw 2 btfsc PORTB,3 ; if RB3 pressed, color = 100 (red) movlw 4 movwf COLOR ; send the color to PORTC movff COLOR, PORTC call Wait ; Turn on for one count goto Loop Init: movlw 0xFF movwf TRISB clrf TRISC movlw 0x0F movwf ADCON1 clrf COLOR return Wait: ; waste 25,005 clocks (2.5ms) movlw 250 movwf CNT1 L2: nop nop nop nop nop nop decfsz CNT1,F goto L2 return end