20x2 Interrupts

Dave E

Senior Member
This seems to be the week for x2 interrupt questions.
I have a 20x2 (c.0) using these commands:
hintsetup %00000110
setintflags %00000110, %00000110

What happens is that the INTERRUPT: subroutine does not run until BOTH hint1 and hint2 pins have been activated. In this case they are set to activate when the pin goes from a high to a low.

I can press one button, wait a while then press the other button. The INTERRUPT: routine does not run until after both buttons have been pressed.
When running DEBUG, the proper flags are set depending on which button I press.
Press button connected to hint1--flag register changes to %00001010
Press button connected to hint2--flag register changes to %00001100

However, only when the flag register = %00001110 does the INTERRUPT: routine run. Is this correct?

Below is the guts of my code:
All I am doing is counting and printing to an LCD.
After an Interrupt, the LCD should display wether the interrupt was from hint1 or hint2.

Code:
HINTSETUP %00000110	'MAKE B.0 OR B.1 GO HIGH TO LOW TO INTERRUPT
SETINTFLAGS %00000110,%00000110
'-------------------------- MAIN --------------------------
DO
	SEROUT LCD, BAUD, (128, #WORK)
	WORK = WORK + 1
	DEBUG
LOOP

'-------------------------- SUBROUTINES -------------------
INTERRUPT:
DEBUG
	IF HINT1FLAG = 1 THEN
		SEROUT LCD, BAUD, (148, "HINT1")
	ENDIF
	IF HINT2FLAG = 1 THEN
		SEROUT LCD, BAUD, (168, "HINT2")
	ENDIF
	PAUSE 2000
	SEROUT LCD, BAUD, (148, "     ")
	SEROUT LCD, BAUD, (168, "     ")

	HINT1FLAG = 0
	HINT2FLAG = 0
	HINTFLAG = 0
	HINTSETUP %00000110
	SETINTFLAGS %00000110,%00000110
DEBUG
RETURN
Any input would be appreciated.

Dave E
 
Last edited:

inglewoodpete

Senior Member
I suspect you need to read up on SetIntFlags NOT <flags>, <mask>

The NOT configuration can trigger on 1 or another input state rather than both at once.
 

hippy

Ex-Staff (retired)
What you are trying to do is interrupt when either pin goes low, so rather than interrupt on hint1flag and/or hint2flag you need to interrupt on the hintflag. This should work -

HIntSetup %00000110
SetIntFlags %00001000, %00001000

In the interrupt routine you would then check hint1flag and hint2flag to determine which caused the interrupt.

Code:
Interrupt:
  hintflag = 0
  If hint1flag = 1 Then
    SerTxd( "INT1 ")
    hint1flag = 0
  End If
  If hint2flag = 1 Then
    SerTxd( "INT2 ")
    hint2flag = 0
  End If
  SetIntFlags %00001000, %00001000
  Return
Added : Works for me on a PICAXE-20X2.
 
Last edited:
Top