ON      (only on ARM7 parts with integer BASIC firmware)

ON is   NOT used with BASICchip, PROstart, PROplus and SuperPRO see INTERRUPT SUB

ON is no longer supported on the Floating point versions of firmware, Use the INTERRUPT SUB or revert to the integer version of firmware can be found in the Coridium Forum.


ON TIMER msec label




These statements will initialize interrupt service routines so that when the interrupt occurs the code at label will be executed.  Label must have been pre-defined and can either be a SUB (without parameters) or code beginning with a label: and ending in a RETURN. The interrupt response time is approximately 3 usec.  Other interrupts may make this time longer.

TIMER interrupts will occur every msec milliseconds. msec may be a variable or constant, expressions are not allowed. The value for msec must be greater than 1.  If TIMER interrupts are used, then only 4 hardware PWM channels are available.

EINT0 and EINT2 are 2 pins that will interrupt when the defined event occurs.  RISE and FALL are the preferred method and will generate interrupts on rising or falling edges on those 2 pins. HIGH and LOW are supported, but if the pin remains in that state interrupts will be continuously generated. 

EINT1 is connected to the RTS line of the PC, and is normally high, so it can be used by a program on the PC to interrupt the ARMmite, rather than having to reset the board.   EINT1 is also available on the ARMexpress modules (pin 21), and should also be kept normally high if used.

Each time the ON statement is executed the interrupt will be initialized, so it is possible to change routines within the program.  Multiple interrupts can be used, but they are serviced in the order received, and each interrupt service routine will complete before the next one is handled (interrupts that occur while one is being serviced will be handled after the current interrupt is processed).

Interrupt routines should normally be short and simple. The state of the other user BASIC code will be restored after the interrupt, with the exception of string functions, which should NOT be done inside an interrupt.  PRINT statements use strings, so other than a temporary debug to see if the interrupt occurs, they should not be inside an interrupt routine.

To disable the interrupt use the following #define

#define VICIntEnClear  *&HFFFFF014

#define TIMERoff    VICIntEnClear = &H20
#define EINT0off     VICIntEnClear = &H4000
#define EINT1off     VICIntEnClear = &H8000
#define EINT2off     VICIntEnClear = &H10000

ON added in version 7.09

The LPC2106 based ARMexpress supports ONLY ON LOW, due to hardware limitations.

ON is a statement that is executed, so if multiple ON statements are in a program the last statement executed will be active command.

Cortex M3 and M0 do not support ON, but use INTERRUPT SUB


IO15up = 0              ' serves to declare IO15up

SUB IO15count
  IO15up = IO15up + 1



IO15up = 0
while 1
  if IO15up <> lastIO15count then
    print IO15up
    lastIO15count = IO15up



  checkIO0 = checkIO0 + (IO(0) and 1)
  IO0samples = IO0samples +1


ON TIMER 20 every20msec


PRINT "Percentage of time IO0 is HIGH =", 100*checkIO0 / IO0samples

Differences from other BASICs

  • no equivalent in VB
  • no equivalent in PBASIC
See also