ON Interrupt
Action

Execute subroutine when specified interrupt occurs.

Syntax

ON interrupt label [NOSAVE]

Remarks

interrupt INT0, INT1, SERIAL, TIMER0 ,TIMER1 or TIMER2.
Chip specific interrupts can be found under microprocessor support.
Label The label to jump to if the interrupt occurs.
NOSAVE When you specify NOSAVE, no registers are saved and restored in the interrupt routine. So when you use this option be sure to save and restore used registers.
You must return from the interrupt routine with the RETURN statement.
You may have only one RETURN statement in your interrupt routine because the compiler restores the registers and generates a RETI instruction when it encounters a RETURN statement in the ISR.

You can't use TIMER1 when you are using SERIAL routines such as PRINT
because TIMER1 is used as a BAUDRATE generator.

When you use the INT0 or INT1 interrupt you can specify on which condition the interrupt must be triggered.

You can use the Set/Reset statement in combination with the TCON-register for this purpose.

SET TCON.0 : trigger INT0 by falling edge.
RESET TCON.0 : trigger INT0 by low level.
SET TCON.2 : trigger INT1 by falling edge.
RESET TCON.2 : trigger INT1 by low level.

See Hardware for more details

Example


ENABLE INTERRUPTS
ENABLE INT0
'enable the interrupt
ON INT0 Label2 nosave 'jump to label2 on INT0
DO 'endless loop

LOOP
END

Label2:
PRINT " An hardware interrupt occurred!" 'print message
RETURN