/**6 ***************************************************************************
ID: 3540095 • Letter: #
Question
/**6
*****************************************************************************
**
**
*****************************************************************************
*/
/*Includes*/
#include "stm32f10x.h"
/*Defines*/
#define GPIO_CNF_INPUT_ANALOG 0
#define GPIO_CNF_INPUT_FLOATING 1
#define GPIO_CNF_INPUT_PULLUPDOWN 2
#define GPIO_CNF_OUTPUT_PUSHPULL 0
#define GPIO_CNF_OUTPUT_OPENDRAIN 1
#define GPIO_CNF_AFIO_PUSHPULL 2
#define GPIO_CNF_AFIO_OPENDRAIN 3
#define GPIO_MODE_INPUT 0
#define GPIO_MODE_OUTPUT10MHz 1
#define GPIO_MODE_OUTPUT2MHz 2
#define GPIO_MODE_OUTPUT50MHz 3
#define GPIOCONF(mode, cnf) ((cnf << 2) | (mode))
#define GPIOPINCONFL(pin, conf) (conf << (pin * 4))
#define GPIOPINCONFH(pin, conf) (conf << ((pin - 8) * 4))
#define CONFMASKL(pin) ((u32)~(15 << (pin * 4)))
#define CONFMASKH(pin) ((u32)~(15 << ((pin - 8) * 4)))
/*User Pushbutton on Pin A0*/
#define SW_USER_GPIO GPIOA
#define SW_USER_PIN 0
/*USART TX Line Pin A9 */
#define USART_TX_GPIO GPIOA
#define USART_TX_PIN 9
/*USART RX Line Pin A10 */
#define USART_RX_GPIO GPIOA
#define USART_RX_PIN 10
/*Blue LED on Pin C8 */
#define LED_BLUE_GPIO GPIOC
#define LED_BLUE_PIN 8
/*Green LED on Pin C9 */
#define LED_GREEN_GPIO GPIOC
#define LED_GREEN_PIN 9
/*
*
*
*
*/
int main(void)
{
RCC->APB2ENR |= RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPCEN;
LED_BLUE_GPIO->CRH = (LED_BLUE_GPIO->CRH & CONFMASKH(LED_BLUE_PIN)) | GPIOPINCONFH(LED_BLUE_PIN, GPIOCONF(GPIO_MODE_OUTPUT2MHz, GPIO_CNF_OUTPUT_PUSHPULL));
SW_USER_GPIO->CRH = (SW_USER_GPIO->CRH & CONFMASKH(SW_USER_PIN)) | GPIOPINCONFH(SW_USER_PIN, GPIOCONF(GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOATING));
while (1)
{
if(SW_USER_GPIO->IDR & (1 << SW_USER_PIN))
LED_BLUE_GPIO->BSRR = (1 << LED_BLUE_PIN);
else
LED_BLUE_GPIO->BRR = (1 << LED_BLUE_PIN);
}
}
Provide any comments you have about the code above after compiling and running this code.
Explanation / Answer
may i help you ??
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.