Professional Documents
Culture Documents
Date: ___04/28/2022______________________________________________
(A) Make and run the following Example 14 code from LBE in HCS12 Serial Monitor mode. Enter
CodeWarrior using “Load Example Project”. It should be displaying numeral “8” on 7seg display #3
(DSP4) for half a second followed by nothing displayed for another half a second by using “void
half_sec_delay(void)” that is based upon RTI. Overall, the display on the board will be “blinking” @ 1 Hz,
since the ON period of the numeral “8” is 500 ms followed by an OFF period of 500 ms. That leads to the
blinking period = 500 ms + 500 ms = 1000 ms. Thus, the “blinking frequency” is 1000/1000 = 1 Hz.
// Example 14: Real-time interrupt
#include <hidef.h> /* common defines and macros */
#include <mc9s12dg256.h> /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg256b"
#include "main_asm.h" /* interface to the assembly module */
void half_sec_delay(void);
4/23/2022 GHSCSE-Mondal 1
MSDII Lab 12
void half_sec_delay(void)
{
// delay for 0.5 seconds
ticks0 = ticks;
while((ticks-ticks0)<49) {
}
}
NOTE above that the “half_sec_delay()” function includes a “while()” loop that runs 49 times
corresponding to incrementing “ticks” value from “ticks0” to “ticks0+49”. The “ticks” gets incremented
every 10.24 ms when an RTI interrupt (vector number 7) happens. Thus, the “while” loop within the
“half_sec_delay()” function runs for 49 x 10.24 ms = 501.76 ms ~ 500 ms = 0.5 s.
4/23/2022 GHSCSE-Mondal 2
MSDII Lab 12
(B) Modify the code in part (A) to display the numeral “4” on 7seg display #2 (DSP3) for half a second
followed by numeral “8” displayed on 7seg display #3 (DSP4) for another half a second. Again, you must
enter CodeWarrior via “Load Example Project” route. Download the compiled code onto Dragon 12 in
HCS12 Serial Monitor mode.
4/23/2022 GHSCSE-Mondal 3
MSDII Lab 12
What mode of display of the numerals you expect on the board – steady or blinking? Explain your
answer by calculating the “blinking frequency”.
What do you need to modify in your code to make it change the mode?
HINT: You may use the idea of customized delay functions to answer these questions.
4/23/2022 GHSCSE-Mondal 4