找回密码
 立即注册

QQ登录

只需一步,快速开始

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

STM32 cubemx配置工程-LED代码

[复制链接]
跳转到指定楼层
楼主
自己刚比赛完发现了很多不会的东西
现在好多东西都需要重新学习一下

因此上传写基础的代码代表自己学习的进度



单片机源程序如下:
  1. /* Includes ------------------------------------------------------------------*/
  2. #include "stm32f4xx_hal.h"
  3. #include "gpio.h"

  4. /* USER CODE BEGIN Includes */

  5. /* USER CODE END Includes */

  6. /* Private variables ---------------------------------------------------------*/

  7. /* USER CODE BEGIN PV */
  8. /* Private variables ---------------------------------------------------------*/

  9. /* USER CODE END PV */

  10. /* Private function prototypes -----------------------------------------------*/
  11. void SystemClock_Config(void);

  12. /* USER CODE BEGIN PFP */
  13. /* Private function prototypes -----------------------------------------------*/

  14. /* USER CODE END PFP */

  15. /* USER CODE BEGIN 0 */

  16. /* USER CODE END 0 */

  17. int main(void)
  18. {

  19.   /* USER CODE BEGIN 1 */

  20.   /* USER CODE END 1 */

  21.   /* MCU Configuration----------------------------------------------------------*/

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

  24.   /* Configure the system clock */
  25.   SystemClock_Config();

  26.   /* Initialize all configured peripherals */
  27.   MX_GPIO_Init();

  28.   /* USER CODE BEGIN 2 */

  29.   /* USER CODE END 2 */

  30.   /* Infinite loop */
  31.   /* USER CODE BEGIN WHILE */
  32.   while (1)
  33.   {
  34.   /* USER CODE END WHILE */

  35.   /* USER CODE BEGIN 3 */
  36.   HAL_GPIO_WritePin(led1_GPIO_Port, led1_Pin, GPIO_PIN_RESET);
  37.                   HAL_GPIO_WritePin(led0_GPIO_Port, led0_Pin, GPIO_PIN_SET);
  38.                 HAL_Delay(100);
  39.                  HAL_GPIO_WritePin(led0_GPIO_Port, led0_Pin, GPIO_PIN_RESET);
  40.                   HAL_GPIO_WritePin(led1_GPIO_Port, led1_Pin, GPIO_PIN_SET);
  41.                 HAL_Delay(100);
  42.                
  43.   }
  44.   /* USER CODE END 3 */

  45. }

  46. /** System Clock Configuration
  47. */
  48. void SystemClock_Config(void)
  49. {

  50.   RCC_OscInitTypeDef RCC_OscInitStruct;
  51.   RCC_ClkInitTypeDef RCC_ClkInitStruct;

  52.   __HAL_RCC_PWR_CLK_ENABLE();

  53.   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

  54.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  55.   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  56.   RCC_OscInitStruct.HSICalibrationValue = 16;
  57.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  58.   HAL_RCC_OscConfig(&RCC_OscInitStruct);

  59.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  60.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  61.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
  62.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  63.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  64.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  65.   HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0);

  66.   HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

  67.   HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

  68.   /* SysTick_IRQn interrupt configuration */
  69.   HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
  70. }

  71. /* USER CODE BEGIN 4 */

  72. /* USER CODE END 4 */

  73. #ifdef USE_FULL_ASSERT

  74. /**
  75.    * @brief Reports the name of the source file and the source line number
  76.    * where the assert_param error has occurred.
  77.    * @param file: pointer to the source file name
  78.    * @param line: assert_param error line source number
  79.    * @retval None
  80.    */
  81. void assert_failed(uint8_t* file, uint32_t line)
  82. {
  83.   /* USER CODE BEGIN 6 */
  84.   /* User can add his own implementation to report the file name and line number,
  85.     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  86.   /* USER CODE END 6 */

  87. }

  88. #endif

  89. /**
  90.   * @}
  91.   */

  92. /**
  93.   * @}
  94. */

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

所有资料51hei提供下载:
LED1.7z (277.07 KB, 下载次数: 5)


评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

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

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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