Table of Contents Previous topic Next topic
C COMPILER->Interrupt Functions->Automatic Coding of Interrupt Vector
An alternative way of declaring an interrupt function is to use the _interrupt n qualifier. The compiler generates exactly the same code for the function as it does when the _interrupt qualifier is used but in addition it also creates the code to set up the interrupt vector itself. There is therefore no need to modify your startup code.
The interrupt vector used corresponds to the value of n and is calculated as follows:
Vector address = n*8 + 3
File os.h contains a set of defines for the standard 8051 and 8052 vectors which you can use and so you might define func() as follows:
void _interrupt IVN_TIMER1 func()
/* Your interrupt code goes here */
(IVN_TIMER1 is defined as 3 in os.h)
To locate your vector table at an address other than zero, use the /VO compiler option. This tells the compiler to add the specified offset to the calculated vector address. For example if you want your vector table to be located at 8000h, the /VO:8000 compiler option should be used. The vector address used will then be:
Vector address = n*8+3+$8000
If you are working from within the Embedded Development Studio, you can specify the vector offset in the Compiler Settings tab (Build->Settings->Compiler).