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 Name | Description |
---|---|
__INT | |
__SWI | Software INTR Instruction |
__CANRD | CAN bus receive |
__CANER | CAN bus error |
__CANTX | CAN bus transmit |
__EXT | External Pin G0 edge |
__TIMERIDLE | Idle Timer Underflow |
__TIMERT1A | Timer T1 T1A/Underflow |
__TIMERT1B | Timer T1 T1B |
__MICRO | MICROWIRE/PLUS |
__PWM | PWM Timer |
__PORTL | PortL/wakeup PortL Edge |
__UARTR | UART Recieve |
__UARTT | UART Transmit |
__TIMERT0 | Timer T0 Underflow |
__TIMERT1A | Timer T1 T1A/Underflow |
__TIMERT1B | Timer T1 T1B |
__TIMERT2A | Timer T2 T2A/Underflow |
__TIMERT2B | Timer T2 T2B |
__TIMERT3A | Timer T3 T3A/Underflow |
__COUNT | Counters |
__CAPT | Capture Timer 1 and 2 |
__NMI | Non Maskable Interrupt |
__TIMERT3B | Timer T3 T3B |
__VIS | Default |
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 */ }