311 of 323
ZBasic System Library 301 ZX Microcontroller Family WaitForInterrupt Type Subroutine Invocation WaitForInterrupt(mode) WaitForInterrupt(mode, intNum) Parameter Method Type Description mode ByVal Byte 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 depends on the intNum designator combined with the mode value. There are three general sources of interrupts that can be awaited: external interrupts, analog comparator interrupts and pin change interrupts. External Interrupts 0-7 (ATmega-based devices) A task may await an external interrupt by specifying the value 0 through 7 (corresponding to external interrupts 0-7, respectively) for the intNum parameter. In this case, the allowable values for the mode parameter and their respective meanings are given in the table below. Note, however, that some devices support only a subset of the hardware interrupt channels. See the table in the Resource Usage section for details of the supported interrupt channels and the interrupt input pin for each device. 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, on mega32-based devices, Interrupt 2 is not capable of the first two trigger modes; it can only be triggered on a rising edge or a falling edge. 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 (ATmega-based devices) For some ZX models based on the ATmega processors, a task may await a state change on one or more pins of an I/O port. This mode is selected by specifying a special value for the intNum parameter according to the tables below for the respective processor types. intNum Values for Pin Change Interrupts Value Built-in Constant Trigger – mega644, mega644P, mega1284P Trigger – mega328P &H20 WaitPinChangeA Pin change on Port A &H21 WaitPinChangeB Pin change on Port B Pin change on Port B