Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
CLRF CCP1CON ; CCP Module is off
CLRF TMR2 ; Clear Timer2
MOVLW 0x7F ;
MOVWF PR2 ;
MOVLW 0x1F ;
MOVWF CCPR1L ; Duty Cycle is 25% of PWM Period
CLRF INTCON ; Disable interrupts and clear T0IF
BSF STATUS, RP0 ; Bank1
BCF TRISC, PWM1 ; Make pin output
CLRF PIE1 ; Disable peripheral interrupts
BCF STATUS, RP0 ; Bank0
CLRF PIR1 ; Clear peripheral interrupts Flags
MOVLW 0x2C ; PWM mode, 2 LSbs of Duty cycle = 10
MOVWF CCP1CON ;
BSF T2CON, TMR2ON ; Timer2 starts to increment
;
; The CCP1 interrupt is disabled,
; do polling on the TMR2 Interrupt flag bit
;
PWM_Period_Match
BTFSS PIR1, TMR2IF
GOTO PWM_Period_Match
;
; Update this PWM period and the following PWM Duty cycle
;
BCF PIR1, TMR2IF
;
CLRF CCP1CON ; CCP Module is off |B0
CLRF TMR2 ; Clear Timer2 |B0
MOVLW 0x7F ; |B0
MOVWF PR2 ; |B1 <-- oops!
MOVLW 0x1F ; duty cycle is 25% |B0
MOVWF CCPR1L ; of PWM Period |B0
CLRF INTCON ; Disable interrupts |B0
BSF STATUS, RP0 ; Bank1 |B1
BCF TRISC, PWM1 ; Make pin output |B1
CLRF PIE1 ; Disable peripheral inte|B1
BCF STATUS, RP0 ; Bank0 |B0
;
i am using the 16F628..
;******************************************************************
org 0x0000
RESET clrf STATUS ; |B0
clrf PORTA ; clear Port A data latches |B0
clrf PORTB ; clear Port B data latches |B0
movlw h'07' ; |B0
movwf CMCON ; turn comparator off |B0
bsf STATUS,RP0 ; select bank 1 |B1
clrf TRISA ; port A all outputs |B1
clrf TRISB ; port B all outputs |B1
bcf STATUS,RP0 ; select bank 0 |B0
;
; setup PWM (looks like CCPR1L uses Tosc while PR2 uses Tcyc)
;
clrf T2CON ; TMR2 prescale:1 |B0
movlw d'100' ; same as (100*4)>>2 |B0
movwf CCPR1L ; 100 usecs, 50% duty cycle? |B0
bsf STATUS,RP0 ; select bank 1 |B1
movlw d'200'-1 ; 200 1.0 usec 'ticks' |B1
movwf PR2 ; Period=200 usecs, Freq=5.0 KHz |B1
bcf STATUS,RP0 ; select bank 0 |B0
movlw b'00001100' ; |B0
movwf CCP1CON ; put CCP module in PWM mode |B0
bsf T2CON,TMR2ON ; turn on TMR2 |B0
;
; now test to see if the LED on RB3 is glowing at 50% brightness
;
LOOP goto LOOP ; loop indefinately |B0
;
;***************************************************************