Pascal Compiler for 8051 Microcontrollers
Interrupts are procedures declared with the Interrupt directive and interrupt address. In this example Timer0 is a constant defined in the System unit. For any procedure we can optionally define register bank to be used in this procedure by Using and number of bank (0 to 3) or we can define bank independent procedure with UsingAny. Such procedure can be called from any interrupt.
Warning: make sure that all varables that might be changed in the interrupt procedure are marked with the Volatile directive. This will tell the compiler that their value can be modified outside of current program flow so many optimizations on these varables will not be performed since their value is not known. Do not place in an interrupt routine time consuming operations like floating point operations, file I/O, string manipulations, large memory moves, etc.
Example of interrupt declaration:
Compiled program above looks like this: