Setint OR

cpedw

Senior Member
I tried to use variables in SETINT OR ... on a 14M2 but the compiler says

setint 'OR' only supports constants.

The manual says variable/constant for mask and input. I guess the compiler wins, which is a pity.

Derek
 

hippy

Technical Support
Staff member
I expect the issue is that SETINT has to coerce whatever is specified into what the firmware understands and that is basically 'interrupt when inputs anded with the mask match the input value specified'. And to allow the compiler to do that the mask and match have to be numbers for the compiler to manipulate those.

Most SETINT use will be with specific pins. If one needs some programmability it could be possible to use SELECT-CASE or IF statements to select the appropriate SETINT using numbers.

Or one can do the coercion to what one wants programmatically oneself and then use a SETINT or SETINT NOT rather than SETINT OR ...

Consider wanting to interrupt on C.1=1 or C.0=0 -

Code:
#Picaxe 14M2
#Terminal 4800

MainProgram:
  Gosub Interrupt_Enable
  Do
    Pause 10
  Loop

Interrupt:
  SerTxd( "Interrupt ")
  
Interrupt_Enable:
  Do : Loop While pinC.1 = 1 Or pinC.0 = 0
  SerTxd( "Done", CR, LF ) 
  ;           match    mask 
  ;           543210   543210
  SetInt Or  %000010, %000011 ;C.1=1 Or C.0=0
  Return
If we consider 'SETINT OR %00010, %00011', interrupt when C.1=1 or C.0=0, that is -

Code:
C.1 C.0   Outcome
--- ---   -------
 0   0    Interrupt because C.0 = 0
 0   1    No interrupt
 1   0    Interrupt because C.1 = 1 or C.0 = 0
 1   1    Interrupt because C.1 = 1
So that's the equivalent of 'SETINT NOT %00001, %00011'.

That can be tested by replacing the 'SETINT OR' with this 'SETINT NOT'.

The match for SETINT NOT is effectively 'not_match = or_match ^ or_mask'

So, while you cannot do -

Code:
b0 = %00011 ; mask
b1 = %00010 ; match
SetInt Or b1, b0
One can do -

Code:
b0 = %00011 ; mask
b1 = %00010 ; match
b2 = b1 ^ b0
SetInt Not b2, b0
Or even, by altering what's in b1 -

Code:
b0 = %00011 ; mask
b1 = %00001 ; not match
SetInt Not b1, b0
 
Last edited:

hippy

Technical Support
Staff member
You can use this macro -
Code:
#Macro SetIntOr(match,mask)
  match = match ^ mask
  SetInt Not match,mask
  match = match ^ mask
#EndMacro
Then replace "SetInt Or bX, bY" with SetIntOr( bX, bY )"
 

cpedw

Senior Member
That's fantastic thanks. I did try the Select Case route but the way I code, it was messy and obscure. Yours is neat (but a bit obscure to me!).

Derek
 
Top