Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Modify 340_lab1_1 to multiply the input code by 3 before outputting it. Here is

ID: 3631655 • Letter: M

Question

Modify 340_lab1_1 to multiply the input code by 3 before outputting it.
Here is the code. I am using codewarrior to comple it, and a HCS12 Serial Monitor for output.

// 340_lab1_1 - Part A - tested 6-6-2009 kj
// Wytec evb-plus demo board - 24 MHz; Codewarrior 5.9.0
// Inputs DIP-switch states (Port H) and outputs to LEDs (Port B)
// Must set all DIP-switches in "UP" (ungrounded input) position...
// ...before activating hardware RESET to avoid shorted-port alarm

#include <hidef.h> /* common defines and macros */
#include <mc9s12dg256.h> /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg256b"


void main(void){
char c;
DDRB = 0xff; // Ports B = output
DDRH = 0x00; // Ports H = input

DDRJ = 2; // In order to use Wytec LEDs set PJ1 = output...
PTJ = 0; // ... and reset PJ1 to 0

while(1){ // while(1) creates an endless program loop.
c = PTH; // read DIP switches
PORTB = c; // output to LEDs
}

}

Explanation / Answer

#include /* common defines and macros */
#include /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg256b"


void main(void) {
char c;

DDRB = 0xff; // Ports B = output
DDRH = 0x00; // Ports H = input
DDRJ = 2; // In order to use Wytec LEDs set PJ1 = output...

PTJ = 0; // ... and reset PJ1 to 0

while(1) { // while(1) creates an endless program loop.
    c = PTH; // read DIP switches

    c *= 3; // Will do it, but you'll lose information if c > 81

    PORTB = c; // output to LEDs
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote