#include "stm32c0xx.h"
void delay_ms(uint32_t ms) {
for (uint32_t i = 0; i < ms * 4000; i++) {
__NOP();
}
}
void GPIO_Init(void) {
RCC->IOPENR |= RCC_IOPENR_GPIOAEN;
GPIOA->MODER &= ~(0x3F);
GPIOA->MODER |= (0x15);
}
void setLights(int green, int orange, int red) {
if (green) GPIOA->BSRR = (1 << 0);
else GPIOA->BRR = (1 << 0);
if (orange) GPIOA->BSRR = (1 << 1);
else GPIOA->BRR = (1 << 1);
if (red) GPIOA->BSRR = (1 << 2);
else GPIOA->BRR = (1 << 2);
}
int main(void) {
GPIO_Init();
while (1) {
// GREEN
setLights(1, 0, 0);
delay_ms(3000);
// ORANGE
setLights(0, 1, 0);
delay_ms(2000);
// RED
setLights(0, 0, 1);
delay_ms(4000);
}
}