#include <p16F887.inc>
	__CONFIG    _CONFIG1, _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT
	__CONFIG    _CONFIG2, _WRT_OFF & _BOR21V
	cblock 0x20
Delay1
Delay2
	endc
	org 0
start:	
	bsf STATUS,RP0 ;bank1
	bsf TRISC,2          	 ;1. Disable the PWM pin (CCPx) output drivers as 
				         	 ;an input by setting the associated (társított) TRIS bit.
	clrf TRISD
	movlw .199
	movwf PR2   		 	;2. Set the PWM period by loading the PR2 register.
	bcf STATUS,RP0 			;bank0
	clrf CCPR1L
	clrf CCPR1H
	movlw b'10001111' 		;3. Configure the CCP module for the PWM mode
					 		;by loading the CCPxCON register with the
					 		;appropriate (kellő) values.
					 		
					 	    ;4. Set the PWM duty cycle by loading the CCPRxL
					    	;register and DCxB<1:0> bits of the CCPxCON
					  		;register.
	movwf CCP1CON
							 ;5. Configure Timer2:
							 
	bcf PIR1,TMR2IF 		;* Clear the TMR2IF interrupt flag bit of the PIR1 register.
	
	movlw b'101'   			 ;* Set the Timer2 prescale value by loading the
							 ;T2CKPS bits of the T2CON register.
					    	;* Enable Timer2 by setting the TMR2ON bit of
					         ;the T2CON register.
	movwf T2CON
							;6. Enable PWM output after a new PWM cycle has started:
	btfss PIR1,TMR2IF		 ;* Wait until Timer2 overflows (TMR2IF bit of
							  ;the PIR1 register is set).
	goto $-1
	bsf STATUS,RP0 			;bank1
	bcf TRISC,2		 		 ;* Enable the CCPx pin output driver by clearing
					 		 ;the associated TRIS bit.
	bcf STATUS,RP0 			;bank0
	
main:
	movlw b'00000000'  		; bit 9 - 2
	movwf CCPR1L
	bcf CCP1CON,CCP1X  		; bit 1
	bcf CCP1CON,CCP1Y 		 ; bit 0
ide:
	incf CCPR1L,f
	movf CCPR1L,w
	movwf PORTD
	movlw d'10'
	movwf Delay2
	call delay
	goto ide
	
	nop
	goto $-1
	
delay:
	decfsz    Delay1,f
	goto      delay
	decfsz    Delay2,f
	goto      delay
	return
	
	end