#include "stm32l031xx.h"
#define GPIOBEN (1U<<1) // ENABLES GPIOB SHIFT 1 to POSITION 1`
#define PIN3 (1U<<3) // ENABLES PIN3
#define LED_PIN PIN3 // USER_LED_PIN is connected to PB3
#define GPIOAEN (1U<<0) // ENABLES GPIOA SHIFT 1 to POSITION 0
#define PIN11 (1U<<11) // ENABLES PIN11
#define USER_BUTTON PIN11 // USER_BUTTON is connected to PA11
int main()
{
RCC->IOPENR |= GPIOAEN; /* 1.1 : ENABLES CLK access to GPIOA from I/o peripheral address */
RCC->IOPENR |= GPIOBEN; /* 1.2 : ENABLES CLK access to GPIOB from I/o peripheral address */
/*MODER 01 FOR OUTPUT */
GPIOB->MODER |= (1U<<6); /* 2.1 : SET GPIOB as O/P using MODER register 6 PIN 1 */
GPIOB->MODER &= ~(1U<<7); /* 2.2 : SET GPIOB as O/P using MODER register 7 PIN 0 */
/*MODER 00 FOR INPUT */
GPIOA->MODER &= ~(1U<<23); /* 2.3 : SET GPIOB as I/P using MODER register 23 PIN 0 */
GPIOA->MODER &= ~(1U<<22); /* 2.4 : SET GPIOB as I/P using MODER register 22 PIN 0 */
/*PUPDR 01 FOR PULLUP */
GPIOA->PUPDR &= ~(1U<<23); /* 2.5 : SET GPIOB as I/P using PUPDR register 23 PIN 0 */
GPIOA->PUPDR |= (1U<<22); /* 2.6 : SET GPIOB as I/P using PUPDR register 22 PIN 1 */
while(2){
/*Check if BUTTON is pressed */
if (GPIOA->IDR & USER_BUTTON){
GPIOB->BSRR |= (1U<<19); // RESET PIN3 i.e enable reset pin 19 or turn ON LED
}
else {
GPIOB->BSRR |= (1U<<3); // SET PIN3 i.e enable set pin 3 or turn OFF LED
}
}
}
Loading
st-nucleo-l031k6
st-nucleo-l031k6