There are less complicated ways i think
Code:
'PIC-12F683#CONFIG
__config _FOSC_EC & _WDT_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_ON & _CPD_OFF &_FCMEN_OFF &_IESO_OFF
#ENDCONFIG
DEFINE OSC 8
DEFINE DEBUG_REG GPIO
DEFINE DEBUG_BIT 0
DEFINE DEBUG_BAUD 9600
DEFINE DEBUG_MODE 0
'Initialize Regsters:
TRISIO =% 101110 'I or O; MCLR is pin3
CMCON0 = 7 'Analog comparators off
ANSEL = 0 'all inputs digital, the adcin command automatically converts it to analog
OPTION_REG=% 11000000 ' Interrupt on rising edge INTEDG bit, disable internal pullups
'pins and variables
INT_PIN VAR GPIO.2
OUTPIN VAR GPIO.4 'OUTPIN also hooked up to an LED
wsave var byte $20 SYSTEM
wsave1 var byte $A0 SYSTEM
time1 var word
time2 var word
bvars var byte
ibit VAR bvars.0 ; TIME BEGIN
wbit VAR bvars.1 ; TIME DONE
INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT_INT, _PULSE_WIDTH, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
GPIO.0 = 1 ;DEBUG
T1CON = $10 ' Prescaler = 2:1, off
low OUTPIN
pause 200
debug "ready",13
high OUTPIN
INTCON=$80 ; CLEAR INTF
@ bsf T1CON, TMR1ON ' Start timer
@ INT_ENABLE INT_INT ; enable external (INT) interrupts
main:
if wbit then
@ INT_DISABLE INT_INT ; disable external (INT) interrupts
time1 = time2 - time1
DEBUG #TIME1,13 ; prints out cycle count
;time1 = time2
ibit=0
wbit=0
OUTPIN = !OUTPIN
@ INT_ENABLE INT_INT ; enable external (INT) interrupts
endif
goto main
'---[INT - interrupt handler]---------------------------------------------------
PULSE_WIDTH:
if ibit=1 then
time2.highbyte = TMR1H
time2.lowbyte = TMR1L
wbit=1
else
time1.highbyte = TMR1H
time1.lowbyte = TMR1L
ibit=1
endif
@ INT_RETURN
end
Bookmarks