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

Modify the following code to multiply the input code by 3 before outputting it.

ID: 3870293 • Letter: M

Question

Modify the following code to multiply the input code by 3 before outputting it.


#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

void main(void){

   char c;

   DDRB = 0xff; // Ports B = output

   DDRH = 0x00; // Ports H = input

DDRB=DDRH*3;

   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

   }

}

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