EE 308 - LAB 7

Simple Timer Interrupts

First we will explore the timer and the TCNT register. Then we will write some simple programs using the timer overflow interrupt and the real time interrupt. For the pre-lab you should have these programs written, and make sure they compile.

1.
Connect your HC12 to your computer. At the D-Bug12 prompt, display the contents of the TCNT register. Do this several times. How do the values compare?

2.
Use D-Bug12 to modify the TSCR register to enable the counter. Repeat Part 1.

3.
Use D-Bug12 to modify the TSCR register to disable the counter. Repeat Part 1.

4.
Start with the following program, which is just a do-nothing infinite loop:
             #include <hc12.h>

             #define TRUE 1

             main()
             {
                 DDRA = 0xff;       /* Make all bits of Port A output */
                 DDRB = 0xff;       /* Make all bits of Port B output */
                 while (TRUE) { }
             }

Add a Timer Overflow Interrupt service routine to increment Port A. Set the timer to overflow every 16 ms. Answer the following questions:

(a)
Calculate how long it should take Port A to overflow. Measure this time. How long does it take Port A to overflow?

(b)
Change the prescaler so the TOF interrupt will occur every 32 ms. Calculate how long it should take Port A to overflow. Measure this time. How long does it take Port A to overflow?

(c)
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. When done, be sure to restore your program to clear the TOF flag.

5.
To your program from Part 4, add a Real Time Interrupt to implement a turn signal on Port B. (Your TOF interrupt should still be active.) Set the RTI interrupt period to 65.536 ms. Verify that the turn signal works properly. Also, verify that the up-counter on Port A is still operating properly.

You will need to add vector.c to your cc.bat so it will be compiled to a vector.o object file. The first line of cc.bat should look like:

    cx6812 -vl -ax +debug crts.s %1.c vector.c
Here is an example lab07.lkf file for linking in the vector.o file at the right address
    #       link command file for test program
    #
    +seg .text -b 0x0800 -n .text   # program start address
    +seg .const -a .text            # constants follow code
    +seg .data -b 0x0900            # data start address
    crts.o                          # startup routine
    lab07.o                         # application program
    +seg .const -b 0x0b10           # vectors start address
    vector.o                        # interrupt vectors
    +def __stack=0x0a00             # stack pointer initial value


Bill Rison, <rison@ee.nmt.edu >
Wed Feb 24 1999

© 1999, New Mexico Tech