EE 308
Homework #6
Due Feb. 21, 1996
To use interrupts on the HC11, you must do the following things:
#pragma interrupt_handler my_isr
Below is a program which uses the Timer Overflow Interrupt. It interrupts the HC11 every 33 ms. On each interrupt, it writes the one's complement of Port C to Port B.
/*
* Program to use Timer Overflow Interrupt
*/
#include <hc11.h>
#define TRUE 1
void tof_isr(void);
main()
{
TOF_JMP = JMP_OP_CODE; /* Set the TOF interrupt vector */
TOF_VEC = tof_isr; /* to point to the tof_isr() routine */
TMSK2 = TMSK2 | 0x80; /* Set Bit 7 (TOI bit) in TMSK2 */
/* to enable the TOF interrupt */
TFLG2 = 0x80; /* Clear TOF flag before enabling ints */
enable(); /* Enable interrupts (clear I bit in CCR) */
while (TRUE) { } /* Do nothing for now */
}
/*
* Inform the C compiler that tof_isr() is an interrupt
* service routine
*/
#pragma interrupt_handler tof_isr
/*
* Tell the HC11 what to do when it receives a TOF interrupt
*/
void tof_isr(void)
{
PORTB = ~PORTC; /* Write 1's complement of C to B */
TFLG2 = 0x80; /* Clear source of interrupt */
}