Success!
Henrik Thank you very much for your assistance. It looks like I need to spend more time and effort looking at and analysing my configuration registers. Though as you suggested it appears that if I set the various interrupt registers (INTCON and PIE1) you do not need the @ INT_ENABLE TMR1_INT and @ INT_ENABLE AD_INT lines (commented out below), maybe Darrel could shed some light on this? Though I must thank him for the DT-Ints code as it does appear to be excellent piece of code.
To confirm I initially intended to have the analogue attached to AN0 but moved it to AN1 due to realising that I could not have CMCON0 (bits 2-0) set that AN0 as an analogue input and GPIO.1 as a digital input and output. so I swapped them around and unfortunately didn't swap all of the settings in the configuration registers that I should have done.
I have attached the working code below for anyone to reference in the future.
Code:
clear
DEFINE OSC 8
'GP0 LED OUT
'GP1 AD1 FOR POT INPUT
'GP2 LED STATUS
'GP5 LED STATUS 1
'REGISTERS
OPTION_REG = %11000000
INTCON = %11000000
PIE1 = %01000001
PIR1 = %00000000
OSCCON = %01110001
TRISIO = %00000010
ANSEL = %00100010
CCP1CON = %00000000
CMCON0 = %00000100
ADCON0 = %00000101
INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
;---------------------------------------------------------------------------
wsave VAR BYTE $20 SYSTEM ' location for W if in bank0
;wsave VAR BYTE $70 SYSTEM ' alternate save location for W
' if using $70, comment wsave1-3
' --- IF any of these three lines cause an error ?? ------------------------
' Comment them out to fix the problem ----
' -- Which variables are needed, depends on the Chip you are using --
wsave1 VAR BYTE $A0 SYSTEM ' location for W if in bank1
'wsave2 VAR BYTE $120 SYSTEM ' location for W if in bank2
'wsave3 VAR BYTE $1A0 SYSTEM ' location for W if in bank3
' --------------------------------------------------------------------------
'OUTPUT PINS
LEDOut VAR GPIO.0
LEDStatus VAR GPIO.2
LEDStatus1 var GPIO.5
high ledstatus
pause 500
low ledstatus
pause 1000
high ledstatus
pause 500
low ledstatus
T1CON = %00110001
'VARIABLES
LENGTH VAR WORD
PauseA var byte
PASS var byte
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _StateChange, PBP, yes
INT_Handler AD_INT, _PulseLength, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
'@ INT_ENABLE TMR1_INT
'@ INT_ENABLE AD_INT
ADCON0 = %00000111
'MAIN PROGRAM
MAIN:
pausea = 0
WHILE PauseA <= 100
PAUSEA = PAUSEA + 1
pause 1
wend
toggle ledstatus
GOTO MAIN
'SUB PROGRAMS
PulseLength:
LENGTH.highbyte = ADRESH 'SET UP THE TIMER SET UP VARIABLES
LENGTH.lowbyte = ADRESL
toggle ledstatus1
@ INT_RETURN ;RETURN
StateChange:
if pass = 5 then
TOGGLE lEDOUT
pass = 0
else
pass = pass + 1
endif
TMR1H = LENGTH.highbyte 'Transfer the timer variables to the timer register
TMR1L = LENGTH.lowbyte
T1CON = %00010101
ADCON0 = %00000111
@ INT_RETURN ;RETURN
END
Thank you again for your assistance, you have been a real help.
Andrew
Bookmarks