Start Back Next End
  
ZBasic System Library
339
ZBasic Microcontrollers
WaitForInterrupt
Type
Subroutine
Invocation
WaitForInterrupt(mode)
WaitForInterrupt(mode, intNum) 
Parameter
Method
Type
Description
mode
ByVal
integral
A value specifying what action will trigger the interrupt.  See the
discussion below.
intNum
ByVal
Byte
A designator for the interrupt to await (see discussion below).
Discussion
This routine allows a task to suspend itself and wait for an interrupt.  The particular interrupt awaited is
controlled by the intNum designator in combination with the mode value.   There are three general
sources of interrupts that can be awaited: external interrupts, pin change interrupts and analog
comparator interrupts.
External Interrupts 0-7 (ATtiny and ATmega targets)
A task may await an external interrupt by specifying the value 0 through 7 (corresponding to external
interrupt INT0 to INT7, respectively) for the intNum parameter.  Not all target devices support the full
range of external interrupts.  See the Resource Usage sub-section External Interrupts for information on
the available external interrupts for each target device along with the corresponding intNum value and
the interrupt input pin for each.  The allowable values for the mode parameter and their respective
meanings are given in the table below.  
Hardware Interrupt Mode Values
Value
Built-in Constant
Interrupt Trigger
&H10
zxPinLow
A low level on the interrupt pin.
&H14
zxPinChange
Any logic level change on the interrupt pin.
&H18
zxPinFallingEdge
A high to low transition on the interrupt pin.
&H1C
zxPinRisingEdge
A low to high transition on the interrupt pin.
All other values are reserved for future use.  For compatibility with BasicX, there are similarly named built-
in constants that begin with the prefix bx instead of zx except that there is no equivalent for
zxPinChange.  Additionally, for all of the targets in the table below, Interrupt 2 is not capable of the first
two trigger modes; it can only be triggered on a rising edge or a falling edge.  
Target Devices with Limited Functionality on INT2
mega16
mega16A
mega32
mega32A
mega161
mega162
mega323
mega8515
mega8535
The built-in constants WaitInt0 through WaitInt7 may be used to specify the intNum parameter.  If
no intNum parameter is given, Interrupt 1 is assumed (for compatibility with BasicX).  This is equivalent
to using WaitForInterrupt(mode, 1).
Pin Change Interrupts (ATtiny and ATmega targets)
For most ATtiny and ATmega target devices, a task may await a state change on one or more pins of one
or more I/O ports.  This mode is selected by specifying a special value for the intNum parameter that
indicates the port(s) and the mode parameter contains a bit mask indicating the bits of interest.  For
Previous page Top Next page