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

QQ登錄

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

搜索
查看: 2232|回復(fù): 0
收起左側(cè)

STM32 cubemx配置工程-LED代碼

[復(fù)制鏈接]
ID:481399 發(fā)表于 2019-4-23 12:49 | 顯示全部樓層 |閱讀模式
自己剛比賽完發(fā)現(xiàn)了很多不會(huì)的東西
現(xiàn)在好多東西都需要重新學(xué)習(xí)一下

因此上傳寫(xiě)基礎(chǔ)的代碼代表自己學(xué)習(xí)的進(jìn)度

0.png

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

所有資料51hei提供下載:
LED1.7z (277.07 KB, 下載次數(shù): 5)


評(píng)分

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

查看全部評(píng)分

回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

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

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