Connect one of your debounced switches to Input Capture 2 (Port T, Bit 2), as shown below:
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.
PB2:0 | Duty Cycle | PCB:0 | Duty Cycle |
000 | 20% | 100 | 60% |
001 | 30% | 101 | 70% |
010 | 40% | 110 | 80% |
011 | 50% | 111 | 90% |
Show that your program works by displaying the output of the OC1 pin on the logic analyzer. While the 500 Hz signal is being generated, you should be able to measure your push-button time.