//Azmi Abdurrahman Kautsar_1103223211_TK-46-06
#include "stm32f1xx.h"
#define LED_PIN 7
#define BUTTON_PIN 11
int main(void) {
RCC->APB2ENR |= RCC_APB2ENR_IOPAEN;
// configure button
GPIOA->CRH &= ~(GPIO_CRH_MODE11 | GPIO_CRH_CNF11);
GPIOA->CRH |= GPIO_CRH_CNF11_1;
GPIOA->ODR |= (1 << BUTTON_PIN);
// configure led
GPIOA->CRL &= ~(GPIO_CRL_MODE7 | GPIO_CRL_CNF7);
GPIOA->CRL |= GPIO_CRL_MODE7_0;
while (1) {
if (!(GPIOA->IDR & (1 << BUTTON_PIN))) {
GPIOA->BSRR = (1 << LED_PIN);
} else {
GPIOA->BSRR = (1 << (LED_PIN + 16));
}
}
}
Loading
stm32-bluepill
stm32-bluepill