Heres the code I wrote as promised, this is just the PWM bit cut and pasted, the output is on portc, bit4, you can change that to what you like:
;------------------------------ pulse width generation code ----------------------------------
;
;--------------------------- seconds pwm analogue out ----------------------------------------
;
;pulse actual output set point, only used in main program
;outpulse temporary high count
;outpulselo temporary low count
;
pwm movf outpulse,w
;pulse width modulator
btfss status,z
goto out1
;
bcf portc,4 ;low duration of outpulse pulse
movf outpulselo,w
btfss status,z
goto outlo1
;
movf pulse,w ;reload low and high duration counter
sublw d'255'
movwf outpulselo
movf pulse,w
movwf outpulse
return
;
outlo1 decf outpulselo,f
return
;
out1 bsf portc,4 ;set output bit and decrement outpulse counter
decf outpulse,f
return
;
Pulse is the actual pwm value you want, 0 for off and 255 for on, outpulse and outpulselo are just temporary storage, you need to define a variable for these in the assembler.
The base frequency is 1/256th of the interval you call the routine, in otherwords if you call the routine 10,000 times per second, the routine will output a pwm squarewave at 40hz.
You can write this into a program that doesnt use interrupts, but as I said it was specifically written for asn interrupt based programm, the good thing about it is that the processor can dissapear off and do other stuff while the output is running.