Table of Contents        Previous topic       Next topic       

C COMPILER->Interrupt Functions->Manual Coding of Interrupt Vector

The _interrupt qualifier is used to define a function as an interrupt function.  It is placed before the function name as in the following example:

void _interrupt func()
    /* Your interrupt code goes here */

The routine that the compiler then generates includes additional code to save and restore any internal variables that must not be overwritten and returns with the RETI rather than the RET instruction. The resulting function should only be entered in response to an interrupt.

No special code is generated to perform the actual call to this function in response to an interrupt and so you need to manually edit your startup code to set the appropriate interrupt vector to jump to it.  Since the compiler adds an underscore to all function names, you should add this underscore to the function name when you add the assembler code jump instruction to your startup code.  So if the above interrupt function is to be called when an interrupt occurs on timer 1 overflow, you might add the following lines of assembler to your startup code:

    cseg at 001BH
    jmp _func

If you need to respond instantaneously to the interrupt before entry to the C function then you can include additional assembly code before the jump instruction.  For instance you might want to immediately write a byte to an output port and so might use the following code instead of the above:

    cseg at 001BH
    mov P1, #03H
    jmp _func