void delay(volatile uint32_t count) {
while(count--) {}
}
int main(void)
{
// Enable clock for GPIOA
RCC->IOPENR |= (1 << 0);
// Set PA0 as input (00) and PA5 as output (01)
GPIOA->MODER &= ~(3 << (0 * 2)); // Clear mode bits for PA0
GPIOA->MODER |= (0 << (0 * 2)); // Set PA0 as input
GPIOA->MODER &= ~(3 << (5 * 2)); // Clear mode bits for PA5
GPIOA->MODER |= (1 << (5 * 2)); // Set PA5 as output
while (1)
{
// Read PA0 (button)
if (GPIOA->IDR & (1 << 0)) // Check if PA0 is high
{
// Turn on PA5 (LED)
GPIOA->ODR |= (1 << 5); // Set PA5 high
}
else
{
// Turn off PA5 (LED)
GPIOA->ODR &= ~(1 << 5); // Set PA5 low
}
// Simple delay
delay(50000);
}
}
Loading
st-nucleo-c031c6
st-nucleo-c031c6