wklejamy.pl website for sale. You are interested in. Please contact. wklejamy@gmail.com
Click to buy coffe
Untitled
Guest 32 15th Mar, 2023
#include "stm32f4xx.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#define SLOW_BLINK_FREQ 500 // Częstotliwość miganie diody w trybie wolnym
#define FAST_BLINK_FREQ 1000 // Częstotliwość miganie diody w trybie szybkim
int main(void)
{
// Inicjalizacja portów
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_Init(GPIOC, &GPIO_InitStructure);
while(1)
{
if(GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_13) == Bit_RESET) // Przycisk nie jest wciśnięty
{
GPIO_ToggleBits(GPIOA, GPIO_Pin_5); // Odwrócenie stanu diody
delay(SLOW_BLINK_FREQ); // Pauza pomiędzy zmianami stanu diody
}
else // Przycisk jest wciśnięty
{
GPIO_ToggleBits(GPIOA, GPIO_Pin_5); // Odwrócenie stanu diody
delay(FAST_BLINK_FREQ); // Pauza pomiędzy zmianami stanu diody
}
}
}
void delay(uint32_t ms) // Funkcja opóźnienia w milisekundach
{
for (volatile uint32_t i=0; i<ms*4000; i++);
}
To share this paste please copy this url and send to your friends
RAW Paste Data