Creating a Comparator Interrupt

Version 1
    Question: How do I enable an interrupt from a comparator?



    Unlike other user modules, the comparator does not provide a stub for an interrupt service routine (ISR). You must create your own ISR and call it from the appropriate place in boot.asm. For this the interrupt vector for the analog column has to be updated in the boot.tpl file.

    There are four places in boot.tpl for the analog column interrupt routines.

        org   08h                      ;Analog Column 0 Interrupt Vector

        org   0Ch                      ;Analog Column 1 Interrupt Vector

        org   10h                      ;Analog Column 2 Interrupt Vector

        org   14h                      ;Analog Column 3 Interrupt Vector

    In the interrupt vector of the analog column where the comparator is placed, replace the @INTERRUPT_x instruction with an ljmp instruction to your comparator ISR.  For example, if the comparator is in Analog_Column_0 and the ISR is named ComparatorISR then replace the '@INTERRUPT_2' in Analog Column 0 interrupt vector with the jump to the ISR 

        org   08h                      ;Analog Column 0 Interrupt Vector
        ljmp ComparatorISR

    If your ISR is in C, then add an underscore before the name of the ISR (ljmp _ComparatorISR).  Save the boot.tpl and Generate Application.  The boot.asm file will now get updated with the changes made to the boot.tpl.

    Now that you have an ISR and and LJMP to the ISR in your boot code, you need to enable the interrupt, including globals. Global interrupts can be enabled with the "M8C_EnableGInt" macro. The column interrupt can be enabled with the "M8C_EnableIntMask" macro. The following code would enable an interrupt for analog column zero:

    M8C_EnableIntMask INT_MSK0, INT_MSK0_ACOLUMN_0

    The comparator will then generate an interrupt whenever it crosses the threshold from LOW to HIGH.