Chapter 4. Programming with the COP8 Interrupts

Table of Contents
Writing interrupt subroutines
Saving compiler temporary variables

Writing interrupt subroutines

The Byte Craft COP8C compiler has features that simplify the interface between a C program and the interrupt structure of the COP8 microcontroller. This chapter lists these features and provides examples of how use them.

The compiler uses a function to implement an interrupt handler. When a function's name matches the name of an interrupt vector specified in the device header file, the compiler generates interrupt handler code for that function. Interrupt subroutines are similar to normal functions, except their addresses are entered into the interrupt vector table and the return from interrupt (RETI) instruction is used to return.

Here is a list of interrupt subroutines that are available for various devices:

Table 4-1. Interrupt Subroutine Function Names

ISR NameDescription
__INT 
__SWISoftware INTR Instruction
__CANRDCAN bus receive
__CANERCAN bus error
__CANTXCAN bus transmit
__EXTExternal Pin G0 edge
__TIMERIDLEIdle Timer Underflow
__TIMERT1ATimer T1 T1A/Underflow
__TIMERT1BTimer T1 T1B
__MICROMICROWIRE/PLUS
__PWMPWM Timer
__PORTLPortL/wakeup PortL Edge
__UARTRUART Recieve
__UARTTUART Transmit
__TIMERT0Timer T0 Underflow
__TIMERT1ATimer T1 T1A/Underflow
__TIMERT1BTimer T1 T1B
__TIMERT2ATimer T2 T2A/Underflow
__TIMERT2BTimer T2 T2B
__TIMERT3ATimer T3 T3A/Underflow
__COUNTCounters
__CAPTCapture Timer 1 and 2
__NMINon Maskable Interrupt
__TIMERT3BTimer T3 T3B
__VISDefault

Interrupts are processed differently for the "COP8 Basic Family" and the "COP8 Feature Family".

The "COP8 Feature Family" has very powerful interrupt handling. The microcontroller has multiple interrupts with varying priorities. In the Feature Family, an interrupt causes main line execution to halt and the processor jumps to location 0x00FF. The processor has a special instruction to automatically vector to the appropriate interrupt subroutine. This instruction (VIS) is automatically placed at 0x00FF.

The interrupt service routine for "COP8 Basic Family" requires more work. As with the "COP8 Feature Family", interrupt handling jumps to 0x00FF. From 0x00FF the program jumps to the __INT() function , if it is defined. In the __INT() function you must determine the interrupt source by examining the flags. After handling the interrupt, you must clear the GIE flag and return from the function. This will cause the processor to resume normal program execution.

Figure 4-1. simple interrupt subroutine rtccint1.c

#include <cop8_isr.h>
void __INT(void)
{
        if( PSW.TPND ) /* a timer underflow has occured */
        {
                /* handle timer interrupt */
                PSW.TPND = 0; /* clear pending flag */
        }
}

void main(void)
{
        /* -timer with input capture register 
         * -interrup on TIO negative edge 
         * -timer counts on instruction clock
         * -start timer */
        CNTRL=(1<<TC1)|(1<<TC2)|(1<<TC3)|(1<<TRUN);
        PSW.ENTI=1; /* enable timer interrupt */
        PSW.GIE=1; /* enable global interrupts */
        while(1); /* wait for interrupts */
}