list p=16F628A
include <P16F628A.INC>
cblock 0x20
COUNT1
COUNT2
endc
org 0x00
init movlw .50
movwf COUNT1
movwf COUNT2
;;;SET PWM FREQUENCY;;;
bank1 ;SELECT BANK 01
movlw D'128' ;SET PR2 TO 128 DECIMAL SO THE PWM PERIOD = 2064uS => PWM FREQUENCY = 484Hz
movwf PR2
bank0 ;SELECT BANK 00
clrf CCPR1L ;SET PWM STARTING DUTY CYCLE;;;
comf CCPR1L
movlw B'00001100' ;SET PWM MODE, BITS 5 AND 4 ARE THE TWO LSBs OF THE 10BIT DUTY CYCLE REGISTER (CCPR1L:CCP1CON<5:4>)
movwf CCP1CON ;SET PWM PIN TO OUTPUT MODE;;;
bank1 ;SELECT BANK 01
bcf TRISB, 3 ;SET RB3 AS OUTPUT, TO USE FOR PWM
bank0 ;SELECT BANK 00
movlw B'00000010' ;SET TIMER 2 PRESCALE VALUE;;;PRESCALE = 16 SO THE PWM PERIOD = 2064uS => PWM FREQUENCY = 484Hz
movwf T2CON
clrf TMR2 ;CLEAR TIMER 2 MODULE;;;
bsf T2CON, TMR2ON ;ENABLE TIMER 2 MODULE;;;
main call DELAY
goto main
DELAY
loop1 decfsz COUNT1,1
goto loop1
decfsz COUNT2,1
goto loop1
return
end