LIST P=16F627
#INCLUDE P16F627.INC
__CONFIG _CP_OFF&_WDT_OFF&_BODEN_OFF&_PWRTE_ON
_T2CON EQU b'00001100'
_PR2 EQU d'39'
_CCPR1L EQU b'00010100'
org 0x70
interrupt_count RES 1
;Reset vector
org 0x00
goto init
;Interupt vector
org 0x04
;Interupt service Routine
isr
decfsz interrupt_count,F
goto phase_shift ;count, but initialised at startup to a different value
movlw d'125' ;reset interrupt_count variable to 125
movwf interrupt_count
movlw B'00000001'
xorwf PORTB,F ; Toggle the bit0 pin
goto end_isr
phase_shift:
movlw d'83'
subwf interrupt_count,W ; check if (interrupt_count==d'83')
btfss STATUS,Z
goto end_isr
rrf PORTB,W ; move bit0 to carry flag to preserve its state.
rlf PORTB,F ; shift all bits including bit0.
end_isr:
bcf PIR1,TMR2IF ; end isr, resetting interrupts
retfie ; return to main program
init:
clrf STATUS
clrf PCLATH
movlw _T2CON
movwf T2CON
movlw _CCPR1L ;set these + the bits 4 and 5 of CCP1CON
movwf CCPR1L ;to give a value of 80 for 50% duty
bsf CCP1CON, 2
bsf CCP1CON, 3
bcf CCP1CON, 4
bcf CCP1CON, 5
bsf STATUS,RP0 ; select bank one
movlw _PR2 ;
movwf PR2 ; MOVED this to here!
clrf TRISA ; PORTA = all outputs
clrf TRISB ; PORTB = all outputs
bsf PIE1,TMR2IE
bcf STATUS,RP0 ; select bank zero
bsf INTCON,PEIE
clrf PORTA ; PORTA = 0
clrf PORTB
bsf INTCON,GIE
main:
goto main
end