EE 308
Homework #6
Due Feb. 24, 1997

Note: The material on interrupts will be covered in class on Wednesday (2/19) and Friday (2/21). Because of this, this homework is not due until Monday (2/24). This homework will be the pre-lab for next week's lab.

To use interrupts on the HC11, you must do the following things:

  1. Load the stack pointer. (This is done for you in C by the C compiler.)
  2. Write an interrupt service.
    1. Do the stuff you need to do when the interrupt is received.
    2. Be sure that the interrupt service routine clears the source of the interrupt before exiting.
    3. 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
  3. Do any setup needed for the interrupt.
  4. Clear the flag for the interrupt.
  5. Set the appropriate interrupt vector to point to your routine.
  6. Enable the specific interrupt your routine handles by setting the interrupt bit in the appropriate register.
  7. 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 */
        }

  1. What is the address of the 16-bit free-running counter in the HC11?
  2. For an HC11 using an 8 MHz crystal (2 MHz E clock) how often will the TOF interrupt be called?
  3. How do you clear the Timer Overflow Interrupt Flag?
  4. Using the above program as a model, write an interrupt service routine which increments Port B whenever the timer overflows.
  5. How long will it take Port B to overflow, using your program of Problem 4?
  6. To enable the RTI interrupt, which bit of which register must you set?
  7. How do you clear the Real Time Interrupt Flag?
  8. Add a Real Time Interrupt to your program of Problem 4. 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.)
  9. Using your program of Problem 8, how long will it take for Port C to overflow?