Final version for 2001
HC12 Timer Interrupts
You should write the program for Part 7 (which
includes the program for Parts 4 and 5). You should also answer the
questions for Part 4 (a) and (b).
#include <hc12.h> #define TRUE 1 main() { DDRA = 0xff; /* Make all bits of Port A output */ PORTA = 0x00; while (TRUE) { _asm("wai"); } }
Add a Timer Overflow Interrupt service routine to increment Port A. Do this with the prescaler set to 0, so the overflow rate is 8 ms. Answer the following questions:
The right part of Figure 1 is what the signal to IC2 will look like if you push the pushbutton twice.
It is inconvenient to have to stop the HC12 and look at a memory location to determine what your result was. D-Bug12 has built in routines to write information to the terminal. This is documented in the application note Using the Callable Routines in D-Bug12 included with your HC12 board. In your program, TR should be a sixteen-bit unsigned number. D-Bug12 provides a C-like printf() function you can use to print information to the screen. The information below shows some examples of how to do this.
To use the D-Bug12 routines you will have to include the header file DBug12.h. This can be downloaded from the EE 308 homepage.
Here is a program to print hello, world to the terminal:
#include "DBug12.h" main() { DBug12FNP->printf("hello, world\n\r"); }
Here is a program to print an unsigned number to the screen in both hexadecimal and decimal:
#include "DBug12.h" main() { unsigned int x; x = 0xf000; DBug12FNP->printf("Hex: %x, Decimal: %u\n\r",x,x); }
Add to your program a printf() function to print out the result - the number of timer ticks between pushes of the button. (Do not try to calculate the actual time as a floating point number. When you use floating point numbers the programs will be too large to load into the HC12 without using expanded memory.) You should write your program as an infinite loop so that after pressing the button twice your program will print out the result, the go wait for the next two presses.
cx6812 -vl -ax +debug crts.s %1.c vector.c clnk -o %1.h12 -m %1.map %1.lkf chex -o %1.s19 %1.h12 clabs %1.h12
The interrupt vectors for DBug-12 start at address 0x0b10. To tell the linker to put the interrupt vector file at the right place, change your lkf file to look like this:
# 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 lab06.o # application program +seg .const -b 0x0b10 # interrupt vectors start here vector.o # file of interrupt vectors +def __stack=0x0A00 # stack pointer initial value