| 51 Interrupt Vectors Intercepted! | |||||||||||||||||||||||||||||||||||||||||||||
|
Recently I have had a few calls on how to assign interrupt vectors on an 8051 to interrupt functions. It is really quite simple when the method is explained which it is not in the manuals. The syntax for the interrupt call is: void function(void) interrupt 1 using 2 { statements . } The key is in the "interrupt 1 using 2". The "using 2" is optional and refers to which register bank to use. The 8051 family has four register banks. The banks occupy the range D:0x0000 to D:0x001F in four banks of 8 registers (bytes). Normally bank 0 is used for the program. By putting the interrupt routines in another bank (1, 2 or 3) context switching greatly reduced. The judicious use of register banks can have a dramatic effect on execution. If the register banks are not used the spare ones are used by the compiler for Data memory. The main point that holds it all together is the interrupt key word. This works in two parts and it is this that causes the problems. One half is in the Keil C51 manual and the other half in the data book for the part you are using. Keil provides for 32 interrupt vectors. 0003h to 00FBh in steps of 8. The first five interrupt numbers are common to all 8051 types.
So the routine above "void function(void) interrupt 1 using 2" is interrupt 1 (Timer/Counter0) using register bank 2 After this it starts to get a little fuzzy but the method is still the same. The Keil numbers and the vectors continue sequentially but it depends on the part in question as to what they are hooked up to. For example, Keil Interrupt 8 is vector 43h. For the Dallas 390 vector 43h is INT2 External Interrupt 2 but for the Atmel WM CC01 vector 43h is ADC (ADCI). Therefore :- { statements . } will run if on the 390 if there is an EXTernal INTerrupt 2 but it will run for the for the ADC on the Atmel WM CANary. As you can see interrupts are simple once you put the two halves together. The main thing is to make sure the two tables (Keil compiler and the silicon data book) are lined up. Being out by one is going to cause some interesting results that may be hard to find! |
|||||||||||||||||||||||||||||||||||||||||||||
|
Copyright Chris A Hills
2002 Last updated 24-Jan-2003 and still
under construction! |
|||||||||||||||||||||||||||||||||||||||||||||