;=======CCP_Tach.ASM====================================4/Sept/2015==
;
list p=PIC18f23K22 ;list directive to define processor
#include <p18f23K22.inc> ;processor specific definitions
;Setup CONFIG1H
CONFIG FOSC = HSHP, PLLCFG = OFF, PRICLKEN = OFF, FCMEN = OFF, IESO = OFF
;Setup CONFIG2L
CONFIG PWRTEN = OFF, BOREN = OFF, BORV = 190
;Setup CONFIG2H
CONFIG WDTEN = OFF, WDTPS = 1
;Setup CONFIG3H
CONFIG MCLRE = EXTMCLR, CCP2MX = PORTB3, CCP3MX = PORTC6, HFOFST = OFF, T3CMX = PORTB5, P2BMX = PORTC0
;Setup CONFIG4L
CONFIG STVREN = OFF, LVP = OFF, XINST = OFF
;Setup CONFIG5L
CONFIG CP0 = OFF, CP1 = OFF ;CP2 = OFF, CP3 = OFF
;Setup CONFIG5H
CONFIG CPB = OFF, CPD = OFF
;Setup CONFIG6L
CONFIG WRT0 = OFF, WRT1 = OFF ;, WRT2 = OFF, WRT3 = OFF
;Setup CONFIG6H
CONFIG WRTB = OFF, WRTC = OFF, WRTD = OFF
;Setup CONFIG7L
CONFIG EBTR0 = OFF, EBTR1 = OFF ;, EBTR2 = OFF, EBTR3 = OFF
;Setup CONFIG7H
CONFIG EBTRB = OFF
;------------------------------------------------------------
; ------------------------------------------------------------
;------------------------------------------------------------
;This code executes when a reset occurs.
ORG 0x0000 ;place code at reset vector
ResetCode:
bra Start ;go to beginning of program
;----------------------------------------------------------------------------
;This code executes when a high priority interrupt occurs.
ORG 0x0008 ;place code at interrupt vector
HighInt:
bra HighIntCode ;go to high priority interrupt routine
;----------------------------------------------------------------------------
;This code executes when a low priority interrupt occurs.
ORG 0x0018 ;place code at interrupt vector
LoIntCode:
goto iserv ;do interrupts here
reset ;error if no valid interrupt so reset
;---------------------------------------------------------
;High priority interrupt routine.
HighIntCode:
retfie
;
Start:
clrf ANSELA
clrf ANSELB
clrf ANSELC
; movlw b'00000110' ;turn off A/D, port A
; movwf ADCON1
movlw b'00000000' ;port B outputs
movwf TRISB
bsf TRISC, 0 ;port C, bit 0 timer 1 input
bsf TRISC, CCP1 ;CCP1 pin input
; movlw b'00000000' ;port B lines low
clrf PORTB
bcf INTCON, GIE ;disable global interrupts
bcf INTCON, PEIE ;disable peripheral interrupts
bcf PIE1,TMR1IE ;disable TMR1 interrupt
bcf PIE1, CCP1IE ;disable CCP1 interrupt
bcf PIR1, CCP1IF ;clear CCP1 interrupt flag
clrf CCP1CON ;CCP1 module off, clear CCP1 prescaler
movlw b'10000000' ;TMR1 prescaler and TMR1 setup,
movwf T1CON ; and TMR1 off
clrf TMR1H ;clear timer 1 high
clrf TMR1L ;clear timer 1 low, clear prescaler
clrf CCPR1H ;clear capture register high
clrf CCPR1L ;clear capture register low
movlw b'00000101' ;CCP1 prescaler mode,
movwf CCP1CON ; CCP1 capture mode, CCP1 on
bsf INTCON, GIE ;enable global interrupts
bsf INTCON, PEIE ;enable peripheral interrupts
bsf T1CON, 0 ;timer 1 on
circle:
goto circle ;done
;
iserv:
bcf PIR1, CCP1IF ;clear ccp1 interrupt flag,
; enable further interrupts
movf CCPR1L, W ;read capture register low
movwf PORTB ;display captured count at port B
retfie ;return from interrupt
;
end
;------------------------------------------------------------
;at device programming time, select:
; memory unprotected
; watchdog timer disabled (default is enabled)
; standard crystal XT (using 4 MHz osc for test)
; power-up timer on
; brown-out reset enabled
; lvp disabled
; debug mode disabled
;============================================================