找回密码
 立即注册

QQ登录

只需一步,快速开始

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

STM32 CUBEMX-usart+led程序 学习的步伐继续

[复制链接]
跳转到指定楼层
楼主
ID:481399 发表于 2019-5-14 15:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
之前因为事情拉下了一段时间现在继续跟上
使用软件:stm32cubemx+mdk5
硬件平台:stm32f407
接上一个帖子
见证自己一步步学习的步伐



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

  5. /* USER CODE BEGIN Includes */

  6. /* USER CODE END Includes */

  7. /* Private variables ---------------------------------------------------------*/

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

  10. /* USER CODE END PV */

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

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

  15. /* USER CODE END PFP */

  16. /* USER CODE BEGIN 0 */

  17. /* USER CODE END 0 */

  18. int main(void)
  19. {

  20.   /* USER CODE BEGIN 1 */
  21. uint8_t  tx_buf[]="USART TEST\r\n";
  22.   /* USER CODE END 1 */

  23.   /* MCU Configuration----------------------------------------------------------*/

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

  26.   /* Configure the system clock */
  27.   SystemClock_Config();

  28.   /* Initialize all configured peripherals */
  29.   MX_GPIO_Init();
  30.   MX_USART1_UART_Init();

  31.   /* USER CODE BEGIN 2 */

  32.   /* USER CODE END 2 */

  33.   /* Infinite loop */
  34.   /* USER CODE BEGIN WHILE */
  35.   while (1)
  36.   {
  37.   /* USER CODE END WHILE */

  38.   /* USER CODE BEGIN 3 */
  39.         HAL_UART_Transmit(&huart1,"Hello!\r\n",8,10);
  40.                 HAL_Delay(1000);
  41.                         HAL_UART_Transmit(&huart1,tx_buf,12,10);
  42.                 HAL_Delay(1000);
  43.                
  44.   }
  45.   /* USER CODE END 3 */

  46. }

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

  51.   RCC_OscInitTypeDef RCC_OscInitStruct;
  52.   RCC_ClkInitTypeDef RCC_ClkInitStruct;

  53.   __HAL_RCC_PWR_CLK_ENABLE();

  54.   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

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

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

  67.   HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

  68.   HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

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

  72. /* USER CODE BEGIN 4 */

  73. /* USER CODE END 4 */

  74. #ifdef USE_FULL_ASSERT

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

  88. }

  89. #endif

  90. /**
  91.   * @}
  92.   */

  93. /**
  94.   * @}
  95. */

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

所有资料51hei提供下载:
USART.7z (287.45 KB, 下载次数: 12)


评分

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

查看全部评分

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

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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