You are on page 1of 4

MSDII Lab 12

EENG EGTE3288 Lab 12 LBE RTI Based


Display
Total Points = 30

Team Member Names: ___Hamad Altuwaitan, _Dana Alsafran_____________________________

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);

unsigned short ticks, ticks0; // RTI interrupt counts

// RTI Interrupt Service Routine

void interrupt 7 handler()


{
ticks++;
clear_RTI_flag();
}

void main (void)


{
PLL_init(); // set system clock frequency to 24 MHz
seg7_enable(); // enable 7-segment displays
led_disable(); // disable LEDs
RTI_init();
while (1) {
seg7dec(8,3); // display 8 on 7seg display #3
half_sec_delay();
seg7s_off(); // turn off 7seg display
half_sec_delay();
}
}

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.

The function “half_sec_delay()” can be customized to a “ms_10_delay()” function as follows:


void ms_10_delay(void)
{
// delay for 10.24 milliseconds
ticks0 = ticks;
while((ticks-ticks0)<1) {
}
}

Include snips of your debugger window:

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.

Paste the C Program here:

4/23/2022 GHSCSE-Mondal 3
MSDII Lab 12

Paste snip of Debug window here:

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

You might also like