this code is in (.c) and I need help with what is in the image I have already done most of it I just need help troubleshooting this is arm based board below is what I have so far /*KL25Z_LED_Blinky.c*/ #include /* provides fixed width integer types. For example, uint32_t) */ #include "derivative.h" /* KL25Z info */ #include "mcg.h" /* main clock generator */ #include "systick.h" /* SysTick timer */ #include "KL25Z_gpio.h" /* GPIO routines */ #include "KL25Z_port.h" /* PORT routines */ #include "delays.h" /* software based delays */ /* Macro definitions */ #define RED_LED_PIN 18 /* GPIO and PORT module "pins", not the device pins */ #define GREEN_LED_PIN 19 #define BLUE_LED_PIN 1 #define LED_OFF 1 #define LED_ON 0 /* Globals */ volatile uint32_t sysTicks; /* required for SysTick support. Do not delete. */ int main(void) { /* Set of the main clock to run at 48 MHz and turn on SysTick * * The student should not make changes here unless instructed to do so. */ pll_init(8000000,0,1,4,24,1); // In mcg.c sets the main clock for 48 MHz sysTicks = 0; // clear SysTick counter variable. Increments every millisecond. initSysTicks(); // turns on SysTick interrupts and the count variable /* Initialize the tri-color LED outputs in the PORT and GPIO peripherals * */ /* turn on the PORT and GPIO module clocks */ enable_port_clock(PORTB_PERIPHERAL); enable_port_clock(PORTD_PERIPHERAL); /* set signal multiplexing for GPIOs to the LEDs */ set_port_mux(PORTB_PERIPHERAL, RED_LED_PIN, ALT1); set_port_mux(PORTB_PERIPHERAL, GREEN_LED_PIN, ALT1); set_port_mux(PORTD_PERIPHERAL, BLUE_LED_PIN, ALT1); /* setup pin circuits. There are no pulldown resistors on a KL25Z */ disable_port_pin_high_drive(PORTB_PERIPHERAL, RED_LED_PIN); disable_port_pin_filter(PORTB_PERIPHERAL, RED_LED_PIN); select_port_pin_slow_slew(PORTB_PERIPHERAL, RED_LED_PIN); disable_port_pin_pull_resistor(PORTB_PERIPHERAL, RED_LED_PIN); disable_port_pin_high_drive(PORTB_PERIPHERAL, GREEN_LED_PIN); disable_port_pin_filter(PORTB_PERIPHERAL, GREEN_LED_PIN); select_port_pin_slow_slew(PORTB_PERIPHERAL, GREEN_LED_PIN); disable_port_pin_pull_resistor(PORTB_PERIPHERAL, GREEN_LED_PIN); disable_port_pin_high_drive(PORTD_PERIPHERAL, BLUE_LED_PIN); disable_port_pin_filter(PORTD_PERIPHERAL, BLUE_LED_PIN); select_port_pin_slow_slew(PORTD_PERIPHERAL, BLUE_LED_PIN); disable_port_pin_pull_resistor(PORTD_PERIPHERAL, BLUE_LED_PIN); /* setup the GPIO */ init_gpio_pin(GPIOB_PERIPHERAL, RED_LED_PIN, GPIO_OUT); init_gpio_pin(GPIOB_PERIPHERAL, GREEN_LED_PIN, GPIO_OUT); init_gpio_pin(GPIOD_PERIPHERAL, BLUE_LED_PIN, GPIO_OUT); set_gpio_pin_level(GPIOB_PERIPHERAL, RED_LED_PIN, LED_OFF); set_gpio_pin_level(GPIOB_PERIPHERAL, GREEN_LED_PIN, LED_OFF); set_gpio_pin_level(GPIOD_PERIPHERAL, BLUE_LED_PIN, LED_OFF); /* Main loop * */ for(;;) { /* loop forever */ /* turn on and off the FRDM tri-color leds with GPIO function calls. */ set_gpio_pin_level(GPIOB_PERIPHERAL, RED_LED_PIN, LED_ON); delay_sec(3); set_gpio_pin_level(GPIOB_PERIPHERAL, RED_LED_PIN, LED_OFF); delay_sec(1); set_gpio_pin_level(GPIOB_PERIPHERAL, GREEN_LED_PIN, LED_ON); delay_sec(3); set_gpio_pin_level(GPIOB_PERIPHERAL, GREEN_LED_PIN, LED_OFF); delay_sec(1); set_gpio_pin_level(GPIOB_PERIPHERAL, BLUE_LED_PIN, LED_ON); delay_sec(3); set_gpio_pin_level(GPIOB_PERIPHERAL, BLUE_LED_PIN, LED_OFF); delay_sec(1); set_gpio_pin_level(GPIOB_PERIPHERAL, RED_LED_PIN, LED_ON); set_gpio_pin_level(GPIOB_PERIPHERAL, GREEN_LED_PIN, LED_ON); set_gpio_pin_level(GPIOD_PERIPHERAL, BLUE_LED_PIN, LED_ON); delay_sec(3); set_gpio_pin_level(GPIOB_PERIPHERAL, RED_LED_PIN, LED_OFF); set_gpio_pin_level(GPIOB_PERIPHERAL, GREEN_LED_PIN, LED_OFF); set_gpio_pin_level(GPIOD_PERIPHERAL, BLUE_LED_PIN, LED_OFF); delay_sec(1); } return 0; }
this code is in (.c) and I need help with what is in the image I have already done most of it I just need help troubleshooting this is arm based board
below is what I have so far
/*KL25Z_LED_Blinky.c*/
#include <stdint.h> /* provides fixed width integer types. For example, uint32_t) */
#include "derivative.h" /* KL25Z info */
#include "mcg.h" /* main clock generator */
#include "systick.h" /* SysTick timer */
#include "KL25Z_gpio.h" /* GPIO routines */
#include "KL25Z_port.h" /* PORT routines */
#include "delays.h" /* software based delays */
/* Macro definitions */
#define RED_LED_PIN 18 /* GPIO and PORT module "pins", not the device pins */
#define GREEN_LED_PIN 19
#define BLUE_LED_PIN 1
#define LED_OFF 1
#define LED_ON 0
/* Globals */
volatile uint32_t sysTicks; /* required for SysTick support. Do not delete. */
int main(void) {
/* Set of the main clock to run at 48 MHz and turn on SysTick
*
* The student should not make changes here unless instructed to do so.
*/
pll_init(8000000,0,1,4,24,1); // In mcg.c sets the main clock for 48 MHz
sysTicks = 0; // clear SysTick counter variable. Increments every millisecond.
initSysTicks(); // turns on SysTick interrupts and the count variable
/* Initialize the tri-color LED outputs in the PORT and GPIO peripherals
*
*/
/* turn on the PORT and GPIO module clocks */
enable_port_clock(PORTB_PERIPHERAL);
enable_port_clock(PORTD_PERIPHERAL);
/* set signal multiplexing for GPIOs to the LEDs */
set_port_mux(PORTB_PERIPHERAL, RED_LED_PIN, ALT1);
set_port_mux(PORTB_PERIPHERAL, GREEN_LED_PIN, ALT1);
set_port_mux(PORTD_PERIPHERAL, BLUE_LED_PIN, ALT1);
/* setup pin circuits. There are no pulldown resistors on a KL25Z */
disable_port_pin_high_drive(PORTB_PERIPHERAL, RED_LED_PIN);
disable_port_pin_filter(PORTB_PERIPHERAL, RED_LED_PIN);
select_port_pin_slow_slew(PORTB_PERIPHERAL, RED_LED_PIN);
disable_port_pin_pull_resistor(PORTB_PERIPHERAL, RED_LED_PIN);
disable_port_pin_high_drive(PORTB_PERIPHERAL, GREEN_LED_PIN);
disable_port_pin_filter(PORTB_PERIPHERAL, GREEN_LED_PIN);
select_port_pin_slow_slew(PORTB_PERIPHERAL, GREEN_LED_PIN);
disable_port_pin_pull_resistor(PORTB_PERIPHERAL, GREEN_LED_PIN);
disable_port_pin_high_drive(PORTD_PERIPHERAL, BLUE_LED_PIN);
disable_port_pin_filter(PORTD_PERIPHERAL, BLUE_LED_PIN);
select_port_pin_slow_slew(PORTD_PERIPHERAL, BLUE_LED_PIN);
disable_port_pin_pull_resistor(PORTD_PERIPHERAL, BLUE_LED_PIN);
/* setup the GPIO */
init_gpio_pin(GPIOB_PERIPHERAL, RED_LED_PIN, GPIO_OUT);
init_gpio_pin(GPIOB_PERIPHERAL, GREEN_LED_PIN, GPIO_OUT);
init_gpio_pin(GPIOD_PERIPHERAL, BLUE_LED_PIN, GPIO_OUT);
set_gpio_pin_level(GPIOB_PERIPHERAL, RED_LED_PIN, LED_OFF);
set_gpio_pin_level(GPIOB_PERIPHERAL, GREEN_LED_PIN, LED_OFF);
set_gpio_pin_level(GPIOD_PERIPHERAL, BLUE_LED_PIN, LED_OFF);
/* Main loop
*
*/
for(;;) { /* loop forever */
/* turn on and off the FRDM tri-color leds with GPIO function calls.
*/
set_gpio_pin_level(GPIOB_PERIPHERAL, RED_LED_PIN, LED_ON);
delay_sec(3);
set_gpio_pin_level(GPIOB_PERIPHERAL, RED_LED_PIN, LED_OFF);
delay_sec(1);
set_gpio_pin_level(GPIOB_PERIPHERAL, GREEN_LED_PIN, LED_ON);
delay_sec(3);
set_gpio_pin_level(GPIOB_PERIPHERAL, GREEN_LED_PIN, LED_OFF);
delay_sec(1);
set_gpio_pin_level(GPIOB_PERIPHERAL, BLUE_LED_PIN, LED_ON);
delay_sec(3);
set_gpio_pin_level(GPIOB_PERIPHERAL, BLUE_LED_PIN, LED_OFF);
delay_sec(1);
set_gpio_pin_level(GPIOB_PERIPHERAL, RED_LED_PIN, LED_ON);
set_gpio_pin_level(GPIOB_PERIPHERAL, GREEN_LED_PIN, LED_ON);
set_gpio_pin_level(GPIOD_PERIPHERAL, BLUE_LED_PIN, LED_ON);
delay_sec(3);
set_gpio_pin_level(GPIOB_PERIPHERAL, RED_LED_PIN, LED_OFF);
set_gpio_pin_level(GPIOB_PERIPHERAL, GREEN_LED_PIN, LED_OFF);
set_gpio_pin_level(GPIOD_PERIPHERAL, BLUE_LED_PIN, LED_OFF);
delay_sec(1);
}
return 0;
}
Code logic that is required is:
Input k, and perform actions,
Code given in question is:
/*KL25Z_LED_Blinky.c*/
#include <stdint.h> /* provides fixed width integer types. For example, uint32_t) */
#include "derivative.h" /* KL25Z info */
#include "mcg.h" /* main clock generator */
#include "systick.h" /* SysTick timer */
#include "KL25Z_gpio.h" /* GPIO routines */
#include "KL25Z_port.h" /* PORT routines */
#include "delays.h" /* software based delays */
/* Macro definitions */
#define RED_LED_PIN 18 /* GPIO and PORT module "pins", not the device pins */
#define GREEN_LED_PIN 19
#define BLUE_LED_PIN 1
#define LED_OFF 1
#define LED_ON 0
/* Globals */
volatile uint32_t sysTicks; /* required for SysTick support. Do not delete. */
int main(void) {
/* Set of the main clock to run at 48 MHz and turn on SysTick
*
* The student should not make changes here unless instructed to do so.
*/
pll_init(8000000,0,1,4,24,1); // In mcg.c sets the main clock for 48 MHz
sysTicks = 0; // clear SysTick counter variable. Increments every millisecond.
initSysTicks(); // turns on SysTick interrupts and the count variable
/* Initialize the tri-color LED outputs in the PORT and GPIO peripherals
*
*/
/* turn on the PORT and GPIO module clocks */
enable_port_clock(PORTB_PERIPHERAL);
enable_port_clock(PORTD_PERIPHERAL);
/* set signal multiplexing for GPIOs to the LEDs */
set_port_mux(PORTB_PERIPHERAL, RED_LED_PIN, ALT1);
set_port_mux(PORTB_PERIPHERAL, GREEN_LED_PIN, ALT1);
set_port_mux(PORTD_PERIPHERAL, BLUE_LED_PIN, ALT1);
/* setup pin circuits. There are no pulldown resistors on a KL25Z */
disable_port_pin_high_drive(PORTB_PERIPHERAL, RED_LED_PIN);
disable_port_pin_filter(PORTB_PERIPHERAL, RED_LED_PIN);
select_port_pin_slow_slew(PORTB_PERIPHERAL, RED_LED_PIN);
disable_port_pin_pull_resistor(PORTB_PERIPHERAL, RED_LED_PIN);
disable_port_pin_high_drive(PORTB_PERIPHERAL, GREEN_LED_PIN);
disable_port_pin_filter(PORTB_PERIPHERAL, GREEN_LED_PIN);
select_port_pin_slow_slew(PORTB_PERIPHERAL, GREEN_LED_PIN);
disable_port_pin_pull_resistor(PORTB_PERIPHERAL, GREEN_LED_PIN);
disable_port_pin_high_drive(PORTD_PERIPHERAL, BLUE_LED_PIN);
disable_port_pin_filter(PORTD_PERIPHERAL, BLUE_LED_PIN);
select_port_pin_slow_slew(PORTD_PERIPHERAL, BLUE_LED_PIN);
disable_port_pin_pull_resistor(PORTD_PERIPHERAL, BLUE_LED_PIN);
/* setup the GPIO */
init_gpio_pin(GPIOB_PERIPHERAL, RED_LED_PIN, GPIO_OUT);
init_gpio_pin(GPIOB_PERIPHERAL, GREEN_LED_PIN, GPIO_OUT);
init_gpio_pin(GPIOD_PERIPHERAL, BLUE_LED_PIN, GPIO_OUT);
set_gpio_pin_level(GPIOB_PERIPHERAL, RED_LED_PIN, LED_OFF);
set_gpio_pin_level(GPIOB_PERIPHERAL, GREEN_LED_PIN, LED_OFF);
set_gpio_pin_level(GPIOD_PERIPHERAL, BLUE_LED_PIN, LED_OFF);
/* Main loop
*
*/
for(;;) { /* loop forever */
/* turn on and off the FRDM tri-color leds with GPIO function calls.
*/
set_gpio_pin_level(GPIOB_PERIPHERAL, RED_LED_PIN, LED_ON);
delay_sec(3);
set_gpio_pin_level(GPIOB_PERIPHERAL, RED_LED_PIN, LED_OFF);
delay_sec(1);
set_gpio_pin_level(GPIOB_PERIPHERAL, GREEN_LED_PIN, LED_ON);
delay_sec(3);
set_gpio_pin_level(GPIOB_PERIPHERAL, GREEN_LED_PIN, LED_OFF);
delay_sec(1);
set_gpio_pin_level(GPIOB_PERIPHERAL, BLUE_LED_PIN, LED_ON);
delay_sec(3);
set_gpio_pin_level(GPIOB_PERIPHERAL, BLUE_LED_PIN, LED_OFF);
delay_sec(1);
set_gpio_pin_level(GPIOB_PERIPHERAL, RED_LED_PIN, LED_ON);
set_gpio_pin_level(GPIOB_PERIPHERAL, GREEN_LED_PIN, LED_ON);
set_gpio_pin_level(GPIOD_PERIPHERAL, BLUE_LED_PIN, LED_ON);
delay_sec(3);
set_gpio_pin_level(GPIOB_PERIPHERAL, RED_LED_PIN, LED_OFF);
set_gpio_pin_level(GPIOB_PERIPHERAL, GREEN_LED_PIN, LED_OFF);
set_gpio_pin_level(GPIOD_PERIPHERAL, BLUE_LED_PIN, LED_OFF);
delay_sec(1);
}
return 0;
}
Step by step
Solved in 2 steps