#include "stm32c0xx.h"
void delay(void)
{
for (volatile uint32_t i = 0; i < 500000; i++)
{
}
}
int main(void)
{
// 1. Enable GPIOB clock
RCC->IOPENR |= (1U << 1);
// 2. Configure PB3 as output
GPIOB->MODER &= ~(3U << 6);
GPIOB->MODER |= (1U << 6);
//3. Configure PB5 as input
GPIOB->MODER &=~(3U << 10);
//4. PB5 internal ull up
GPIOB->PUPDR &=~(3U<<10);
GPIOB->PUPDR |=(1U<<10);
while (1)
{
if (!(GPIOB->IDR & (1U << 5)))// check if pin 5 is high
{
GPIOB->BSRR = (1U << 3); //LED ON
}
else // 4. LED OFF
{
GPIOB->BSRR = (1U << 19);
}
}
}