#include <stdint.h>
int count = 0;
void delay11(uint32_t time) // uint32_t time = 1680000
{
while (time--);
}
void RCC_Config()
{
RCC->IOPENR |= (1UL << 1); // GPIOB periferik cihazını aktivləşdir
RCC->IOPENR |= (1UL << 0); // GPIOA periferik cihazını aktivləşdir
RCC->CR &= ~(1 << 8); // HSI söndürülüb
RCC->CR |= (1 << 16); // HSE açıq
RCC->CR |= 1 << 19; // CSS ON
uint32_t t = 100000;
while (!(RCC->CR & (1 << 17)) && t--) {} // HSE bayrağı (limitli)
RCC->CFGR &= ~(1 << 2);
RCC->CFGR &= ~(1 << 1);
RCC->CFGR |= (1 << 0); // sistem saatı = HSE
RCC->CFGR |= (1 << 24); // MCO saat seçimi
RCC->CFGR |= (2 << 8); // AHB prescaler 2
RCC->AHBENR |= (1 << 12);
RCC->AHBENR |= (1 << 8);
}
void GPIO_Config()
{
GPIOB->MODER &= ~(1 << 4); // PB2 switch üçün giriş
GPIOB->MODER &= ~(1 << 5);
GPIOB->PUPDR &= ~(1 << 4); // switch üçün pull-down
GPIOB->PUPDR |= 1 << 5;
GPIOB->MODER |= (1 << 20); // LED üçün PB10 çıxış
GPIOB->MODER &= ~(1 << 21);
GPIOB->OTYPER &= ~(1 << 10); // push-pull
GPIOB->OTYPER &= ~(1 << 11);
GPIOB->OSPEEDR &= ~(1 << 20); // yüksək sürət
GPIOB->OSPEEDR |= (1 << 21);
}
void setup()
{
RCC_Config();
GPIO_Config();
}
void loop()
{
int value;
value = GPIOB->IDR & (0x00000004);
if (value != 0)
{
count++;
// for (int i = 0; i < 1680000; i++);
if (count % 2 == 0)
{
GPIOB->ODR = 0x00000000;
}
else
{
GPIOB->ODR = 0x00000400;
}
}
}Loading
st-nucleo-c031c6
st-nucleo-c031c6