
The following C example shows what the shell of your ISR should be like:
/*-------------------------------------------------------------------------------
| Function:
new_IRQ_handler
| Inputs:
Nothing
| Returns:
Nothing
- Sets the interrupt flag for the EVENT.
|-------------------------------------------------------------------------------*/
void interrupt far new_IRQ_handler(void)
{
IRQ_flag = 1;
// Indicate to main process interrupt has occurred
{
// Your program code should be here
}
outp(BA+0,0x00);
// Clears interrupt on DM6854HR
outp(0x20, 0x20);
/* Acknowledge the interrupt controller. */
}
-Saving the Startup Interrupt Mask Register (IMR) and interrupt vector
The next step after writing the ISR is to save the startup state of the interrupt mask
register (IMR) and the original interrupt vector you are using. The IMR is located in address 21h.
The interrupt vector you will be using is located in the interrupt vector table which is an array of
4-byte pointers (addresses) and it is locate din the first 1024 bytes of the memory (Segment 0
offset 0). You can read this value directly, but it is a better practice to use DOS function 35h
(get interrupt vector) to do this. Most C compilers have a special function available for doing this.
The vectors for the hardware interrupts on the XT - bus are vectors 8-15., where IRQ0 uses
vector 8 and IRQ7 uses vector 15. Thus if your DM6854HR is using IRQ5 it corresponds to
vector number 13.
Before you install your ISR, temporarily mask out the IRQ you will be using. This
prevents the IRQ from requesting an interrupt while you are installing and initializing your ISR.
To mask the IRQ, read the current IMR at I/O port 21h, and set the bit that corresponds to
tout IRQ. The IMR is arranged so that bit 0 is for IRQ0 and bit 7 is for IRQ7. See the paragraph
entitled Interrupt Mask Register (IMR) earlier in this discussion for help in determining your
IRQ's bit. After setting the bit, write the new value to I/O port 21h.
with the startup IMR saved and the interrupts temporarily disabled, you can assign the
interrupt vector to point to your ISR. Again you can overwrite the appropriate entry in the vector
table with a direct memory write, but this is not recommended. Instead use the DOS function 25h
(Set Interrupt Vector) or, if your compiler provides it, the library routine for setting up interrupt
vectors. Remember , that interrupt vector 8 corresponds to IRQ0 , vector 9 for IRQ1 etc.
If you need to program the source of your interrupts, do that next. For example, if you
are using the input compare on the DM6854HR as an interrupt source, program it to do that.
Finally, clear the mask bit for your IRQ in the IMR. This will enable your IRQ.
DM5854HR/DM6854HR Page 39 (c) RTD Finland Oy 1996-2001