#include <stdint.h>
/* Periferik baza ünvanları (RM0490) */
#define R_RCC_BASE 0x40021000UL
#define R_GPIOA_BASE 0x50000000UL
#define RCC_IOPENR (*(volatile uint32_t *)(R_RCC_BASE + 0x34))
#define GPIOA_MODER (*(volatile uint32_t *)(R_GPIOA_BASE + 0x00))
#define GPIOA_ODR (*(volatile uint32_t *)(R_GPIOA_BASE + 0x14))
#define GPIOA_BSRR (*(volatile uint32_t *)(R_GPIOA_BASE + 0x18))
#define RELAY_PIN 0U /* PA0 -> relay IN */
/* Məşğulluq gözləmə gecikməsi */
static void busy_delay(volatile uint32_t count)
{
while (count--)
{
__asm__ volatile ("nop");
}
}
void setup() {
/* 1. GPIOA saatını aktivləşdir */
RCC_IOPENR |= (1U << 0);
/* 2. PA0 = çıxış (01) */
GPIOA_MODER &= ~(3U << (RELAY_PIN * 2U));
GPIOA_MODER |= (1U << (RELAY_PIN * 2U));
/* 3. Röle enerjisiz başlasın (PA0 = 0 -> qırmızı LED) */
GPIOA_BSRR = (1U << (RELAY_PIN + 16U));
}
void loop() {
/* Röle enerjili: PA0 = 1 -> COM NO -> sarı LED */
GPIOA_BSRR = (1U << RELAY_PIN);
busy_delay(1500000U);
/* Röle enerjisiz: PA0 = 0 -> COM NC -> qırmızı LED */
GPIOA_BSRR = (1U << (RELAY_PIN + 16U));
busy_delay(1500000U);
}Loading
st-nucleo-c031c6
st-nucleo-c031c6