Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

After unzipping Example4.zip to the desktop, run CodeWarrior IDE by double clicking on Project.mcp inside the Example4 folder (that is the easiest way to open

After unzipping Example4.zip to the desktop, run CodeWarrior IDE by double clicking on Project.mcp inside the Example4 folder (that is the easiest way to open a project).

From the directory on the left of the screen double click on main.c (under Sources) to see the default program shown below:

// Example 4 // Flash an LED at the rate determined by a potentiometer

#include // common defines and macros

#include // derivative information

#pragma LINK_INFO DERIVATIVE "mc9s12xet256"

void MSDelay(unsigned int itime);

void main(void) {

int delay;

DDRH = 0b00000001; // enable LED

DDRP = 0b11111111; // enable potentiometer (knob)

for(;;) {

delay = PTP;

if (delay < 1) { // delays of zero are BAD!

delay = 1;

}

PTH = 1;

MSDelay(delay);

PTH = 0;

MSDelay(delay);

} /* loop forever */

}

void MSDelay(unsigned int itime){

unsigned int i; unsigned int j;

for(i=0;i

for(j=0;j<4000;j++);

}

Start the program by selecting Project|Debug from the top menu (or just press F5). This will compile your program, and start the debugger. In order to see what your program is doing, select Component|Open|Visualizationtool from the menu strip at the top of the debug window and click OK:

This opens a blank Visualization Tool window.

Since we will be using an endless loop in our program, we will need to adjust the cycle time for our simulation. Right-click your mouse anywhere in the Visualization Tool window and select Properties. Set the Refresh Mode to Periodical, and set the Refresh Time to 1.

Right-click your mouse inside the Visualization Tool window, select Add New Instrument|LED, and click anywhere on the display to pin it down.

To connect this control to your program, you need to assign the control to Port H (hex memory address $0260). Double click on the LED control to bring up the property sheet, add 0x0260 to the port address, set the Height and Width to 50, and press return.

Do the same thing for the Knob control and assign the control to Port P (hex memory address $0258). Double click on the Knob control to bring up the property sheet, add 0x0258 to the port address, and press return.

You can save yourself some work in the future by selecting File|Save Configuration from the menu bar in the Debug window.) To see the program run, select Run|Restart from the menu bar in the Debug window. (You also may need to toggle the Visualization screen from Edit Mode to Display Mode.)

Now its your turn. Modify the existing code by replacing the LED with an Analog Dial control. Set it up so that the value of the Potentiometer (Knob) control is displayed on the Dial (Analog) control. No delays are required for this modification.

When you have completed your modifications copy and paste your program (main.c) into the submission area inside this assignment folder or paste it into a Word document for submission. I only need to see your C program.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Computer Aided Database Design

Authors: Antonio Albano, Valeria De Antonellis, A. Di Leva

1st Edition

0444877355, 978-0444877352

More Books

Students also viewed these Databases questions