From 5d54be33f95f6ba2a6984cf29898c619e5482db7 Mon Sep 17 00:00:00 2001 From: xengineering Date: Sun, 20 Sep 2020 12:06:38 +0200 Subject: Implement gpio_blink --- gpio_blink/main.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 gpio_blink/main.c (limited to 'gpio_blink/main.c') diff --git a/gpio_blink/main.c b/gpio_blink/main.c new file mode 100644 index 0000000..7a5290f --- /dev/null +++ b/gpio_blink/main.c @@ -0,0 +1,47 @@ + + +#include +#include + + +#define DELAY 1000000 + + +void clock_init(void); +void gpio_init(void); +void delay(void); + + +int main(void) +{ + clock_init(); + gpio_init(); + + while(1){ + gpio_toggle(GPIOC, GPIO13); + delay(); + } + + return 0; +} + + +void clock_init(void) +{ + rcc_periph_clock_enable(RCC_GPIOC); // for PC13 blinking +} + + +void gpio_init(void) +{ + gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO13); + gpio_set(GPIOC, GPIO13); +} + + +void delay(void) +{ + for (int i = 0; i < DELAY; i++) { + __asm__("nop"); + } +} -- cgit v1.2.3-70-g09d2