#include "main.h"
volatile uint8_t current_bit = 0;
const uint16_t LED_PINS[8] = {
GPIO_PIN_7,
GPIO_PIN_6,
GPIO_PIN_5,
GPIO_PIN_4,
GPIO_PIN_3,
GPIO_PIN_2,
GPIO_PIN_1,
GPIO_PIN_0
};
volatile uint32_t last_interrupt_time = 0;
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
for (int i = 0; i < 8; i++) {
HAL_GPIO_WritePin(GPIOA, LED_PINS[i], GPIO_PIN_RESET);
}
HAL_GPIO_WritePin(GPIOA, LED_PINS[current_bit], GPIO_PIN_SET);
while (1)
{
}
}
void SystemClock_Config(void)
{
}
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3
| GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_14 | GPIO_PIN_15;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 2, 0);
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
}
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
uint32_t current_time = HAL_GetTick();
if ((current_time - last_interrupt_time) < 150) {
return;
}
last_interrupt_time = current_time;
HAL_GPIO_WritePin(GPIOA, LED_PINS[current_bit], GPIO_PIN_RESET);
if (GPIO_Pin == GPIO_PIN_14)
{
if (current_bit == 7) {
current_bit = 0;
} else {
current_bit++;
}
}
else if (GPIO_Pin == GPIO_PIN_15)
{
if (current_bit == 0) {
current_bit = 7;
} else {
current_bit--;
}
}
HAL_GPIO_WritePin(GPIOA, LED_PINS[current_bit], GPIO_PIN_SET);
}
void Error_Handler(void)
{
__disable_irq();
while (1)
{
}
}