Now I'm sure this is simple - but I've stared at it to the point where I now need to go for a shave, but I need to use PortA.3 (which can be a MCLR pin), as an 'input' for a tactile switch...I want to use an internal weak pullup on that pin too.
What I'm getting Is the PIC resetting everytime I press the switch attached to pin 4 (PortA.3)....so it looks like MCLR is not being disabled. I've checked the associated .inc file in my PC's MPASM directory for the necessary syntax - i think i've got it right.
I've slimmed my program down to the basics...just to get to the bottom of this. A simple loop, when either one of two switches are pressed, A DT interrupt happens & I get some syntax on screen - but it aint right, Sw1 doesn't interrupt at all, Sw2 does, but I just see "Interrupt Sw1" on my screen
...and it doesn't exit until I press Sw1 (which threw me, but then I put a litte trap at the top of my program & established that Sw1 was simply resetting the PIC)
Top tips warmly received.....
Code:
@ __CONFIG _CONFIG1, _FCMEN_OFF & _FOSC_INTOSC & _WDTE_OFF & _MCLRE_OFF & _CP_OFF & _IESO_OFF & _BOREN_OFF & _PWRTE_OFF
DEFINE OSC 4
INCLUDE "DT_INTS-14.bas" ' Base Interrupt System PO90OOO9
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
RCSTA = $90 ' Enable serial port & continuous receive
TXSTA = $24 ' Enable transmit, BRGH = 1
SPBRG = 8 ' 115200 Baud @ 4MHz, -3.55%
SPBRGH = 0
BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
'-------------------------------------------------------------------------
Osccon = %01101010 'sets the internal oscillator
APFCON.2 = 0 ;Hserout onto RC.4 Pin 6
ADCON0 = 0
ADCON1 = 0
CM1CON0 = 0 ' COMPARATORS OFF
CM2CON0 = 0 ' COMPARATORS OFF
ANSELA = %00010000
ANSELC = %00000100
TRISA = %11111111
TRISC = %00000100
OPTION_REG.7 = 0
WPUA = %00101000
IOCAN = %00101000
SW1 VAR PORTA.3
SW2 VAR PORTA.5
hserout ["reset", 13, 10]
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler IOC_INT, _Switch_Interrupt, PBP, YES
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
IOCAF = 0
@ INT_ENABLE IOC_INT ; Enable 'Int On Change' interrupts
Loop1:
hserout ["Waiting", 13, 10]
pause 500
GOTO Loop1
'ENDIF
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Switch_Interrupt:
@ INT_DISABLE IOC_INT ; Disable further IOC interrupts
pause 10
IF sw1 = 0 THEN
HSEROUT ["INTERRUPT Sw1", 13, 10]
goto interrupt_end
endif
IF sw2 = 0 THEN
HSEROUT ["INTERRUPT Sw2", 13, 10]
goto interrupt_end
endif
interrupt_end:
@ INT_ENABLE IOC_INT
@ INT_RETURN
end
Bookmarks