找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 2445|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

STM32 CUBEMX-usart+led程序 學(xué)習(xí)的步伐繼續(xù)

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:481399 發(fā)表于 2019-5-14 15:00 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
之前因?yàn)槭虑槔铝艘欢螘r(shí)間現(xiàn)在繼續(xù)跟上
使用軟件:stm32cubemx+mdk5
硬件平臺(tái):stm32f407
接上一個(gè)帖子
見(jiàn)證自己一步步學(xué)習(xí)的步伐



單片機(jī)源程序如下:
  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****/
復(fù)制代碼

所有資料51hei提供下載:
USART.7z (287.45 KB, 下載次數(shù): 12)


評(píng)分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎(jiǎng)勵(lì)!

查看全部評(píng)分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表