The following is used on a PIC16F1824. Check your Data Sheet to double check the Special Function Registers as applicable to your chip:
Code:
; --- *** Timer 2 SFRs, Used for PWM Period *** --------------------------------
T2CON = %01111011 ;.2 = 1/0
PR2 = %11111111
PIE1.1 = 0 ;TMR2IE
; --- *** CCP1 PWM SFRs *** ----------------------------------------------------
CCP1CON = %00001100
DutyCycle VAR WORD
CCPR1L = DutyCycle.LOWBYTE
;HIGHBYTE comes from bits in CCP1CON
;Fill in other pertinent set-up data.
Label:
PIR1.1 = 0 ;TMR2IF
PIE1.1 = 1 ;TMR2IE
T2CON = %01111111 ;Turns TMR2 ON
do
loop while PIR1.1 = 0 ;TMR2IF
PIR1.1 = 0 ;TMR2IF
DutyCycle = ;desired PWM
Hope this helps.
Bookmarks