stm32 74hc238流水灯

f103c6t6a_hex文件

c 复制代码
#include "main.h"![请添加图片描述](https://i-blog.csdnimg.cn/direct/8c0d44b121134cf08f5186df316ea07f.gif)

#include "stdlib.h"



void SystemClock_Config(void);
static void MX_GPIO_Init(void);
// 自定义abc引脚
#define A_PIN GPIO_PIN_1
#define B_PIN GPIO_PIN_2 
#define C_PIN GPIO_PIN_0 


//y0到y7输出
void segment(char c){
	if(c == 'a'){
		GPIOB->BRR = A_PIN | B_PIN | C_PIN; 
	}
	else if(c == 'b'){
		GPIOB->BSRR = A_PIN; 
		GPIOB->BRR =  B_PIN | C_PIN; 
}
		else if(c == 'c'){
		GPIOB->BSRR = B_PIN; 
		GPIOB->BRR =  A_PIN | C_PIN; 
}
			else if(c == 'd'){
		GPIOB->BSRR = A_PIN|B_PIN ; 
		GPIOB->BRR =   C_PIN; 
}
				else if(c == 'e'){
		GPIOB->BSRR = C_PIN; 
		GPIOB->BRR =  A_PIN | B_PIN; 
}
					else if(c == 'f'){
		GPIOB->BSRR = A_PIN| C_PIN; 
		GPIOB->BRR =  B_PIN ; 
}
					
		else if(c == 'g'){
		GPIOB->BSRR =B_PIN| C_PIN; 
		GPIOB->BRR = A_PIN ; 
}
		else if(c == 'p'){
		GPIOB->BSRR =A_PIN |B_PIN| C_PIN; 
}

}

char segment_list[]={'a','b','c','d','e','f','g','p'};
int main(void)
{
  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();
	
while (1)
    {
     for(int i=0;i<=7;i++){
	segment(segment_list[i]);
		HAL_Delay(500);
	}
    } 
	
	
 

}




void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  /** Initializes the CPU, AHB and APB busses clocks 
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }
  /** Initializes the CPU, AHB and APB busses clocks 
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
  {
    Error_Handler();
  }
}

/**
  * @brief GPIO Initialization Function
  * @param None
  * @retval None
  */
static void MX_GPIO_Init(void)
{
    GPIO_InitTypeDef GPIOInitStruct = {0}; // 初始化 GPIO 结构体

    // 使能 GPIO 端口时钟
    __HAL_RCC_GPIOB_CLK_ENABLE();

    // 设置 GPIO 的通用配置
    GPIOInitStruct.Mode = GPIO_MODE_OUTPUT_PP;    // 设置为推挽输出模式
    GPIOInitStruct.Pull = GPIO_NOPULL;            // 不使用上拉或下拉
    GPIOInitStruct.Speed = GPIO_SPEED_FREQ_LOW;   // 设置为低速

    // 配置 GPIOB 端口的所有引脚
    GPIOInitStruct.Pin = GPIO_PIN_All; // 指定所有引脚
    HAL_GPIO_Init(GPIOB, &GPIOInitStruct); // 初始化配置


}

void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */

  /* USER CODE END Error_Handler_Debug */
}

#ifdef  USE_FULL_ASSERT
相关推荐
湮雨塵飛3 小时前
ESP32开发之LED闪烁和呼吸的实现
vscode·嵌入式硬件·esp32·freertos·呼吸灯
iCxhust5 小时前
Deepseek给出的8255显示例程
c语言·开发语言·c++·单片机·嵌入式硬件
小智学长 | 嵌入式5 小时前
SOC-ESP32S3部分:28-BLE低功耗蓝牙
网络·单片机·esp32
RFID舜识物联网5 小时前
RFID测温芯片助力新能源产业安全与能效提升
大数据·人工智能·嵌入式硬件·物联网·安全
InJre6 小时前
STM32通过rt_hw_hard_fault_exception中的LR寄存器追溯程序问题
java·stm32·嵌入式硬件
逼子格7 小时前
硬件工程师笔记——555定时器应用Multisim电路仿真实验汇总
笔记·单片机·嵌入式硬件·multisim·电路仿真·信号发生器·555定时器
xiaobobo33307 小时前
解决vscode打开一个单片机工程文件(IAR/keil MDK)因无法找到头文件导致的结构体成员不自动补全问题。
vscode·stm32·无法找到头文件·结构体成员不补全
夜月yeyue8 小时前
高性能MCU的MPU与Cache优化详解
linux·开发语言·stm32·单片机·嵌入式硬件
Lester_110110 小时前
嵌入式学习笔记 - FreeRTOS关于vApplicationGetIdleTaskMemory
笔记·stm32·学习·freertos
Ronin-Lotus11 小时前
嵌入式硬件篇---龙芯2k1000串口
linux·网络·python·嵌入式硬件·龙芯·2k1000