EE 308 -- LAB 06
Simple Timer Interrupts

Start with the following program, which is just a do-nothing infinite loop:

             #include <hc11.h>

             #define TRUE 1

                 DDRC = 0xff;       /* Make all bits of Port C output */
                 while (TRUE) { }

  1. Add a Timer Overflow Interrupt service routine to increment Port B. Test your program on the simulator. As in Lab 4, mount the E: drive and give the command SCRIPT E:EE308.SCR to load BUFFALO into the simulator's memory, and initialize all other memory in the simulator so you don't get an uninitialized memory error.

    Answer the following questions:

    1. How long does it take Port B to overflow on the simulator? The EVBU has a 2 MHz clock. What is the approximate `clock rate' on the simulator?

    2. Observe the TCNT register in the TIMER window. Does Port B increment when TCNT rolls over from 0xFFFF to 0x0000?

    3. Set a break point at the first address in your interrupt service routine. (You can determine this by looking at your .map file.) Run your program again.

      1. What value does TCNT have when you hit your breakpoint? Try this several times. Why does TCNT have this value?

      2. When you reach the breakpoint in your interrupt service routine, what value does the I bit of the CCR have? Why? When your program is running between breaks, what value does the I bit have?

      3. Exam the stack and stack pointer. Identify the return address on the stack.

    4. Stop your program. Try to reset TCNT to 0x0000. What happens?

    5. Set the interrupt bit to 1 ( I = 1 in the command window). Start your program running again ( GO in the command window -- do not reset your PC when you type in the GO command). What happens to Port B now? Why?

    6. Set the interrupt bit back to 0. Start your program running again. What happens to Port B now? Why?

    7. What happens when you fail to clear the TOF flag as part of your TOF interrupt service routine? Check your conjecture by commenting this line out of your program and running the new program on the simulator.

  2. To your program from Part 1, add a Real Time Interrupt to increment Port C. Set the RTI interrupt period to 8.19 ms. Observe the operation of this program on the simulator. About how long will it take this program to overflow Port C on the EVBU?

  3. Test your TOI and RTI program on the EVBU. Do the Port B and Port C overflow times agree with your predictions?

  4. Change the prescaler so the timer will overflow every 128 ms. First, do this in your C program, and load and run your program the way you normally do. Does the rate at which Port B increments change? Does the rate at which Port C increments change?

  5. Change the prescaler in the following manner: In BUFFALO, give the following commands:
          >asm b600
               >ldaa #1
               >staa 1024
               >jmp e00a
    Next, move jumper J2 to short pins 1 and 2, and hit the reset button. This will cause BUFFALO to run your code in EEPROM (the code you entered above), then return to BUFFALO at address 0xE00A. Now load and run your program the way you normally do. Does the rate at which Port B increments change? Does the rate at which Port C increments change?

Bill Rison, < >
Wed Feb 19 1998

© 1998, New Mexico Tech