EE 308
Homework #5
Due Feb. 24, 1998
Note: The material on interrupts will be covered in class on Wednesday
(2/18) and Friday (2/20). Because of this, this homework is not due until
Monday (2/23). This homework will be the pre-lab for next week's lab.
Background on Interrupts on the HC11
To use interrupts on the HC11, you must do the following things:
- Load the stack pointer. (This is done for you in C by the C compiler.)
- Write an interrupt service.
- Do the stuff you need to do when the interrupt is
received.
- Be sure that the interrupt service routine clears the source of
the interrupt before exiting.
- Exit from the routine using an rti instruction rather than
an rts instruction. In C, you need to tell the compiler to use
an rti rather than an rts. With the
ICC11 compiler you do this using a #pragma:
#pragma interrupt_handler my_isr
- Do any setup needed for the interrupt.
- Clear the flag for the interrupt.
- Set the appropriate interrupt vector to point to your routine.
- Enable the specific interrupt your routine handles by setting the
interrupt bit in the appropriate register.
- Enable interrupts in general by clearing the I bit of the
Condition Code Register. This is done in assembly with the cli
instruction, or in C with the enable(); function.
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 */
}
Homework Problems
- What is the address of the 16-bit free-running counter in the HC11?
- Consider an HC11 using an 8 MHz crystal (2 MHz E clock). How often will the
TOF interrupt be called
- if the prescaler bits PR1:0 = 00
- if the prescaler bits PR1:0 = 11
- Give the name of the register, the register address, and the apropriate
bit(s) for the following functions:
- The Timer Overflow Flag.
- The Timer Overflow Interrupt Enable bit.
- The Timer Prescaler Bits.
- How do you clear the Timer Overflow Interrupt Flag?
- What special consideration is necessary in changing the timer prescaler
bits?
- Using the above program as a model, write an interrupt service routine
which increments Port B whenever the timer overflows.
- How long will it take Port B to overflow, using your program of
Problem 6?
- Consider an HC11 using an 8 MHz crystal (2 MHz E clock). How often will the
RTI interrupt be called
- if the RTI rate bits RTR1:0 = 00
- if the RTI rate bits RTR1:0 = 11
- Give the name of the register, the register address, and the apropriate
bit(s) for the following functions:
- The Real Time Interrupt Flag.
- The Real Time Interrupt Enable bit.
- The bits which control the Real Time Interrupt rate.
- To enable the RTI interrupt, which bit of which register must you set?
- How do you clear the Real Time Interrupt Flag?
- Add a Real Time Interrupt to your program of Problem 6. Set the RTI for an
8.19 ms rate. In the RTI interrupt service routine, increment Port C. (In
the main program, make Port C and output port by writing 0xFF to the
DDRC register.)
- Using your program of Problem 12, how long will it take for Port C to
overflow?
Bill Rison,
<rison@ee.nmt.edu >