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
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.