找回密码
 注册

QQ登录

只需一步,快速开始

搜索

stm32F103点亮LED 源码和proteus仿真

[复制链接]
wufeng624 发表于 2022-11-21 20:45:06 | 显示全部楼层 |阅读模式
proteus仿真点亮LED,并闪烁
完整代码和仿真文件: led20221115.zip (895.14 KB, 售价: 1 E币)
QQ图片20221121204139.png
部分源码:
  1. /* USER CODE BEGIN Header */
  2. /**
  3.   ******************************************************************************
  4.   * @file           : main.c
  5.   * @brief          : Main program body
  6.   ******************************************************************************
  7.   * @attention
  8.   *
  9.   * Copyright (c) 2022 STMicroelectronics.
  10.   * All rights reserved.
  11.   *
  12.   * This software is licensed under terms that can be found in the LICENSE file
  13.   * in the root directory of this software component.
  14.   * If no LICENSE file comes with this software, it is provided AS-IS.
  15.   *
  16.   ******************************************************************************
  17.   */
  18. /* USER CODE END Header */
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "main.h"
  21. #include "gpio.h"

  22. /* Private includes ----------------------------------------------------------*/
  23. /* USER CODE BEGIN Includes */

  24. /* USER CODE END Includes */

  25. /* Private typedef -----------------------------------------------------------*/
  26. /* USER CODE BEGIN PTD */

  27. /* USER CODE END PTD */

  28. /* Private define ------------------------------------------------------------*/
  29. /* USER CODE BEGIN PD */
  30. /* USER CODE END PD */

  31. /* Private macro -------------------------------------------------------------*/
  32. /* USER CODE BEGIN PM */

  33. /* USER CODE END PM */

  34. /* Private variables ---------------------------------------------------------*/

  35. /* USER CODE BEGIN PV */

  36. /* USER CODE END PV */

  37. /* Private function prototypes -----------------------------------------------*/
  38. void SystemClock_Config(void);
  39. /* USER CODE BEGIN PFP */

  40. /* USER CODE END PFP */

  41. /* Private user code ---------------------------------------------------------*/
  42. /* USER CODE BEGIN 0 */

  43. /* USER CODE END 0 */

  44. /**
  45.   * @brief  The application entry point.
  46.   * @retval int
  47.   */
  48. int main(void)
  49. {
  50.   /* USER CODE BEGIN 1 */

  51.   /* USER CODE END 1 */

  52.   /* MCU Configuration--------------------------------------------------------*/

  53.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  54.   HAL_Init();

  55.   /* USER CODE BEGIN Init */

  56.   /* USER CODE END Init */

  57.   /* Configure the system clock */
  58.   SystemClock_Config();

  59.   /* USER CODE BEGIN SysInit */

  60.   /* USER CODE END SysInit */

  61.   /* Initialize all configured peripherals */
  62.   MX_GPIO_Init();
  63.   /* USER CODE BEGIN 2 */

  64.   /* USER CODE END 2 */

  65.   /* Infinite loop */
  66.   /* USER CODE BEGIN WHILE */
  67.   while (1)
  68.   {
  69.     /* USER CODE END WHILE */
  70.                 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_8|GPIO_PIN_9,GPIO_PIN_RESET);
  71.                 HAL_Delay(500);
  72.                 HAL_GPIO_WritePin(GPIOB,GPIO_PIN_8|GPIO_PIN_9,GPIO_PIN_SET);
  73.                 HAL_Delay(500);
  74.     /* USER CODE BEGIN 3 */
  75.   }
  76.   /* USER CODE END 3 */
  77. }

  78. /**
  79.   * @brief System Clock Configuration
  80.   * @retval None
  81.   */
  82. void SystemClock_Config(void)
  83. {
  84.   RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  85.   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  86.   /** Initializes the RCC Oscillators according to the specified parameters
  87.   * in the RCC_OscInitTypeDef structure.
  88.   */
  89.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  90.   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  91.   RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  92.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  93.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI_DIV2;
  94.   RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16;
  95.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  96.   {
  97.     Error_Handler();
  98.   }

  99.   /** Initializes the CPU, AHB and APB buses clocks
  100.   */
  101.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  102.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  103.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  104.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  105.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  106.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  107.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  108.   {
  109.     Error_Handler();
  110.   }
  111. }
复制代码

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|ELEOK |网站地图

GMT+8, 2024-12-22 00:08

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表