PDA

View Full Version : Can't get IOC on pin change working



huntrashm
- 11th September 2024, 03:08
Can't get IOC on pin change working


#CONFIG
__config _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT32 & _CLKOUTEN_OFF & _CSWEN_OFF & _FCMEN_ON
__config _CONFIG2, _MCLRE_ON & _PWRTE_OFF & _LPBOREN_OFF & _BOREN_ON & _BORV_LO & _ZCD_OFF & _PPS1WAY_OFF & _STVREN_ON & _DEBUG_OFF
__config _CONFIG3, _WDTCPS_WDTCPS_11 & _WDTE_ON & _WDTCWS_WDTCWS_7 & _WDTCCS_LFINTOSC
__config _CONFIG4, _WRT_OFF & _SCANE_available & _LVP_OFF
__config _CONFIG5, _CP_OFF & _CPD_OFF
#ENDCONFIG


DEFINE OSC 32


include "DT_INTS-14.bas"
include "ReEnterPBP.bas"


ASM
INT_LIST macro ;IntSource, Label, Type, ResetFlag?
INT_Handler IOC_INT, _IOCinterrupts, PBP, yes
endm
INT_CREATE ;Creates the interrupt processor
ENDASM


INTCON = 000000
' bit 7 GIE Global Interrupt Enable bit
' 1 = Enables all active interrupts
' bit 6 PEIE Peripheral Interrupt Enable bit
' bit 5-1 Unimplemented: Read as ‘0’
' bit 0 INTEDG Interrupt Edge Select bit


PIE0 = 010000 ' PERIPHERAL INTERRUPT ENABLE REGISTER 0
' bit 7-6 Unimplemented: Read as ‘0’
' bit 5 TMR0IE: TMR0 Overflow Interrupt Enable bit
' bit 4 IOCIE: Interrupt-on-Change Interrupt Enable bit
' 1 = Enables the IOC change interrupt
' bit 3-1 Unimplemented: Read as ‘0’
' bit 0 INTE: INT External Interrupt Flag bit


IOCCP = 010000 ' INTERRUPT-ON-CHANGE PORTC POSITIVE EDGE REGISTER
' bit 7-0 IOCCP<7:0> Interrupt-on-Change PORTC Positive Edge Enable bits
' 1 = Interrupt-on-Change enabled on the pin
' for a positive-going edge. IOCCFx bit
' and IOCIF flag will be set upon detecting an edge.


IOCCN = 000000 ' INTERRUPT-ON-CHANGE PORTC NEGATIVE EDGE REGISTER
' bit 7-0 IOCCP<7:0> Interrupt-on-Change PORTC Negative Edge Enable bits
' 1 = Interrupt-on-Change enabled on the pin
' for a Negative-going edge. IOCCFx bit
' and IOCIF flag will be set upon detecting an edge.


ANSELA = 000000
ANSELB = 000000
ANSELC = 000000
ANSELD = 000000
ANSELE = 000000


TRISA = 000000
TRISB = 000000
TRISC = 010000
TRISD = 000000
TRISE = 000000


PushSwitch VAR PortC.4
InterruptLED VAR LatC.2
HeartbeatLED VAR LatC.3


ButtonWasPressed VAR byte


Pause 500 ' Let PIC and LCD stabilize
InterruptLED = 0
ButtonWasPressed = 0


IOCCF.4 = 0

@ INT_ENABLE IOC_INT

goto Mainloop


IOCinterrupts:
if IOCCF.4 = 1 then
ButtonWasPressed = 1 ' set a flag
IOCCF.4 = 0
endif
@ INT_RETURN


Mainloop:
if ButtonWasPressed = 1 then ' Check flag
InterruptLED = 1
endif


HeartbeatLED = 1
pause 500
HeartbeatLED = 0
pause 500

goto mainloop
end

InterruptLED never lights up when I press PushSwitch, and the HeartbeatLED seems to hang for 2-3 seconds when I press.

aerostar
- 11th September 2024, 06:32
You appear to have forgotten the % for bit definitions

eg variable = %10100110

not variable = 10100110

richard
- 11th September 2024, 09:05
congrats on posting your code in code tags
while its unfortunate that the forum mangles % notation i guess that mangled binary notation is not your trouble

you have neglected to tell us what pic chip you are using but looking at the config section it has PPS
therefore dt-ints will not in all likelihood function for your chip without modifications
secondly you have not set up the internal osc at all, that will cause a very slow default int osc to be used. depending on the pic chip you are using of course

rocket_troy
- 12th September 2024, 00:04
congrats on posting your code in code tags
you have neglected to tell us what pic chip you are using but looking at the config section it has PPS
therefore dt-ints will not in all likelihood function for your chip without modifications

Richard,
can you elaborate or provide some pointers for that? You're suggesting there's more mods needed than to simply assign the appropriate PPSs ?

Troy

richard
- 12th September 2024, 00:37
can you elaborate
nobody keeps dt-ints upto date, the pic world has moved on - pic int flags and enable bits have been changed/modified added to and relocated for enhanced core chips pic16f 1xxxxx
see this
https://www.picbasic.co.uk/forum/showthread.php/26776-SOLVED-Can-t-get-IOC-on-pin-change-working

rocket_troy
- 12th September 2024, 23:31
Thanks Richard,

Troy