Given the C program below, change the program to where the Blue LED toggles inst
ID: 2990545 • Letter: G
Question
Given the C program below, change the program to where the Blue LED toggles instead of the Red LED.
The Program:
#include <MKL25Z4.h>
extern void asm_main (void);
#define PORTB_CLK_MASK (1UL << 10)
#define PORTn_GPIO_MASK (1UL << 8)
#define RED_MASK (1UL << 18)
void delay (int del_val) // Step 4: Delay loop
{
while (del_val >= 0) {
del_val --;
}
}
/*---------------------------------------------------------------
MAIN function
*---------------------------------------------------------------*/
int main (void) {
// Uncomment asm_main () to use
// the assembly language program in asm_main.s
// asm_main ();
// Step 1: Turn on the clock for GPIOB
SIM->SCGC5 = SIM -> SCGC5 | PORTB_CLK_MASK;
// Step 2: Configure the red LED's pin for GPIO
PORTB->PCR [18] = PORTn_GPIO_MASK;
// Step 3: Set the direction of the GPIO pin
FPTB->PDDR = FPTB->PDDR | RED_MASk;
while (1) {
delay (5000000);
// Step 5: Toggle LED
FPTB -> PTOR = FPTB->PTOR | RED_MASK;
}
}
Explanation / Answer
#include <MKL25Z4.h>
extern void asm_main (void);
#define PORTB_CLK_MASK (1UL << 10)
#define PORTn_GPIO_MASK (1UL << 8)
#define BLUE_MASK (1UL << 18)
void delay (int del_val) // Step 4: Delay loop
{
while (del_val >= 0) {
del_val --;
}
}
/*---------------------------------------------------------------
MAIN function
*---------------------------------------------------------------*/
int main (void) {
// Uncomment asm_main () to use
// the assembly language program in asm_main.s
// asm_main ();
// Step 1: Turn on the clock for GPIOB
SIM->SCGC5 = SIM -> SCGC5 | PORTB_CLK_MASK;
// Step 2: Configure the BLUE LED's pin for GPIO
PORTB->PCR [18] = PORTn_GPIO_MASK;
// Step 3: Set the direction of the GPIO pin
FPTB->PDDR = FPTB->PDDR | BLUE_MASk;
while (1) {
delay (5000000);
// Step 5: Toggle LED
FPTB -> PTOR = FPTB->PTOR | BLUE_MASK;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.