找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 4916|回复: 1
打印 上一主题 下一主题
收起左侧

STM32跑马灯Proteus仿真实验

[复制链接]
跳转到指定楼层
楼主
这是一个经典的实验,功能基本根据正点原子的STM32F407板相关实验,由于Proteus8.9只支持stm32F401这里就采用stm32F401VE, test1_horeseLamp.7z (6.75 MB, 下载次数: 62)



单片机源程序如下:
  1. /* USER CODE BEGIN Header */
  2. /* USER CODE END Header */

  3. /* Includes ------------------------------------------------------------------*/
  4. #include "main.h"

  5. /* Private includes ----------------------------------------------------------*/
  6. /* USER CODE BEGIN Includes */

  7. /* USER CODE END Includes */

  8. /* Private typedef -----------------------------------------------------------*/
  9. /* USER CODE BEGIN PTD */

  10. /* USER CODE END PTD */

  11. /* Private define ------------------------------------------------------------*/
  12. /* USER CODE BEGIN PD */

  13. /* USER CODE END PD */

  14. /* Private macro -------------------------------------------------------------*/
  15. /* USER CODE BEGIN PM */

  16. /* USER CODE END PM */

  17. /* Private variables ---------------------------------------------------------*/

  18. /* USER CODE BEGIN PV */

  19. /* USER CODE END PV */

  20. /* Private function prototypes -----------------------------------------------*/
  21. void SystemClock_Config(void);
  22. static void MX_GPIO_Init(void);
  23. /* USER CODE BEGIN PFP */

  24. /* USER CODE END PFP */

  25. /* Private user code ---------------------------------------------------------*/
  26. /* USER CODE BEGIN 0 */

  27. /* USER CODE END 0 */

  28. /**
  29.   * @brief  The application entry point.
  30.   * @retval int
  31.   */
  32. int main(void)
  33. {
  34.   /* USER CODE BEGIN 1 */

  35.   /* USER CODE END 1 */
  36.   

  37.   /* MCU Configuration--------------------------------------------------------*/

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

  40.   /* USER CODE BEGIN Init */

  41.   /* USER CODE END Init */

  42.   /* Configure the system clock */
  43.   SystemClock_Config();

  44.   /* USER CODE BEGIN SysInit */

  45.   /* USER CODE END SysInit */

  46.   /* Initialize all configured peripherals */
  47.   MX_GPIO_Init();
  48.   /* USER CODE BEGIN 2 */

  49.   /* USER CODE END 2 */

  50.   /* Infinite loop */
  51.   /* USER CODE BEGIN WHILE */
  52.   while (1)
  53.   {
  54.     /* USER CODE END WHILE */
  55.                 /*HAL_GPIO_TogglePin(LED0_GPIO_Port,LED0_Pin);
  56.                 HAL_GPIO_TogglePin(LED1_GPIO_Port,LED1_Pin);
  57.                 HAL_Delay(500);*/
  58.                 HAL_GPIO_WritePin(LED0_GPIO_Port,LED0_Pin,GPIO_PIN_RESET);
  59.                 HAL_GPIO_WritePin(LED1_GPIO_Port,LED1_Pin,GPIO_PIN_RESET);
  60.                 HAL_Delay(500);
  61.                 HAL_GPIO_WritePin(LED0_GPIO_Port,LED0_Pin,GPIO_PIN_SET);
  62.                 HAL_GPIO_WritePin(LED1_GPIO_Port,LED1_Pin,GPIO_PIN_SET);
  63.                 HAL_Delay(500);
  64.     /* USER CODE BEGIN 3 */
  65.   }
  66.   /* USER CODE END 3 */
  67. }

  68. /**
  69.   * @brief System Clock Configuration
  70.   * @retval None
  71.   */
  72. void SystemClock_Config(void)
  73. {
  74.   RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  75.   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  76.   /** Configure the main internal regulator output voltage
  77.   */
  78.   __HAL_RCC_PWR_CLK_ENABLE();
  79.   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
  80.   /** Initializes the CPU, AHB and APB busses clocks
  81.   */
  82.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  83.   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  84.   RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  85.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  86.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  87.   RCC_OscInitStruct.PLL.PLLM = 8;
  88.   RCC_OscInitStruct.PLL.PLLN = 84;
  89.   RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  90.   RCC_OscInitStruct.PLL.PLLQ = 4;
  91.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  92.   {
  93.     Error_Handler();
  94.   }
  95.   /** Initializes the CPU, AHB and APB busses clocks
  96.   */
  97.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  98.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  99.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  100.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV2;
  101.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  102.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  103.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
  104.   {
  105.     Error_Handler();
  106.   }
  107. }

  108. /**
  109.   * @brief GPIO Initialization Function
  110.   * @param None
  111.   * @retval None
  112.   */
  113. static void MX_GPIO_Init(void)
  114. {
  115.   GPIO_InitTypeDef GPIO_InitStruct = {0};

  116.   /* GPIO Ports Clock Enable */
  117.   __HAL_RCC_GPIOE_CLK_ENABLE();
  118.   __HAL_RCC_GPIOH_CLK_ENABLE();
  119.   __HAL_RCC_GPIOA_CLK_ENABLE();

  120.   /*Configure GPIO pin Output Level */
  121.   HAL_GPIO_WritePin(GPIOE, LED0_Pin|LED1_Pin, GPIO_PIN_SET);

  122.   /*Configure GPIO pins : LED0_Pin LED1_Pin */
  123.   GPIO_InitStruct.Pin = LED0_Pin|LED1_Pin;
  124.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  125.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  126.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
  127.   HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

  128. }

  129. /* USER CODE BEGIN 4 */

  130. /* USER CODE END 4 */

  131. /**
  132.   * @brief  This function is executed in case of error occurrence.
  133.   * @retval None
  134.   */
  135. void Error_Handler(void)
  136. {
  137.   /* USER CODE BEGIN Error_Handler_Debug */
  138.   /* User can add his own implementation to report the HAL error return state */

  139.   /* USER CODE END Error_Handler_Debug */
  140. }

  141. #ifdef  USE_FULL_ASSERT
  142. /**
  143.   * @brief  Reports the name of the source file and the source line number
  144.   *         where the assert_param error has occurred.
  145.   * @param  file: pointer to the source file name
  146.   * @param  line: assert_param error line source number
  147.   * @retval None
  148.   */
  149. void assert_failed(uint8_t *file, uint32_t line)
  150. {
  151.   /* USER CODE BEGIN 6 */
  152.   /* User can add his own implementation to report the file name and line number,
  153.      tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  154.   /* USER CODE END 6 */
  155. }
  156. #endif /* USE_FULL_ASSERT */

  157. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
复制代码



分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:800382 发表于 2021-2-11 12:04 | 只看该作者
谢谢分享,空了学习一下
回复

使用道具 举报

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

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

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