/* p10_1.c Relay control * * This program turns the relay connected to PA5 on and off every second. * * This program was tested with Keil uVision v5.23 with DFP v2.0.0. */ #include "stm32f0xx.h" void delayMs(int n); int main(void) { RCC->AHBENR |= 0x00020000; /* enable GPIOA clock */ GPIOA->MODER &= ~0x00000C00; /* clear pin mode */ GPIOA->MODER |= 0x00000400; /* set pin to output mode */ while(1) { GPIOA->BSRR = 0x00000020; /* turn on output */ delayMs(500); GPIOA->BSRR = 0x00200000; /* turn off output */ delayMs(500); } } /* 8 MHz SYSCLK */ void delayMs(int n) { int i; for (; n > 0; n--) for (i = 0; i < 1142; i++) ; }