Question: Lab3_4.c : Modify Lab3_3.c code such that the four lights will continuously toggle until the USER button is pressed. The four lights will start toggling
Lab3_4.c
: Modify Lab3_3.c code such that the four lights will continuously toggle until the USER
button is pressed. The four lights will start toggling again once the USER button is pressed again. This behavior should repeat all the time.
Lab3_3.c code:
#define GREEN_LED 12
#define ORANGE_LED 13
#define RED_LED 14
#define BLUE_LED 15
#define PUSH_BUTTON 0
#include "stm32f4xx.h"
int main(void)
{
RCC -> AHB1ENR |= (1<<3 | 1<<0);
int i;
int j;
for (i= GREEN_LED; i <= BLUE_LED; i++)
{
GPIOD -> MODER |= (1<<(2*i));
GPIOD -> MODER &=~ (1<<(2*i+1));
GPIOD -> PUPDR &=~ (1<<(2*i) | 1<<(2*i+1));
GPIOD -> OTYPER &=~ (1<
}
GPIOA -> MODER &=~(1<<(2*PUSH_BUTTON)| 1<<(2*PUSH_BUTTON+1));
i =0;
while(i<1)
{
while (((GPIOA -> IDR)&(1< { } if (((GPIOA -> IDR)&(1< { GPIOD -> ODR |= (1< GPIOD -> ODR |= (1< GPIOD -> ODR |= (1< GPIOD -> ODR |= (1< } else { GPIOD -> ODR &=~ (1< GPIOD -> ODR &=~ (1< GPIOD -> ODR &=~ (1< GPIOD -> ODR &=~ (1< } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
