久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

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

QQ登錄

只需一步,快速開始

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

STM32L151 PWM輸出程序

[復(fù)制鏈接]
ID:680450 發(fā)表于 2020-1-3 15:42 | 顯示全部樓層 |閱讀模式
  1. /* USER CODE BEGIN Header */
  2. /* USER CODE END Header */

  3. /* Includes ------------------------------------------------------------------*/
  4. #include "main.h"
  5. #include "tim.h"
  6. #include "usart.h"
  7. #include "gpio.h"

  8. /* Private includes ----------------------------------------------------------*/
  9. /* USER CODE BEGIN Includes */
  10. #include "stdio.h"
  11. /* USER CODE END Includes */

  12. /* Private typedef -----------------------------------------------------------*/
  13. /* USER CODE BEGIN PTD */

  14. /* USER CODE END PTD */

  15. /* Private define ------------------------------------------------------------*/
  16. /* USER CODE BEGIN PD */

  17. /* USER CODE END PD */

  18. /* Private macro -------------------------------------------------------------*/
  19. /* USER CODE BEGIN PM */

  20. /* USER CODE END PM */

  21. /* Private variables ---------------------------------------------------------*/

  22. /* USER CODE BEGIN PV */

  23. /* USER CODE END PV */

  24. /* Private function prototypes -----------------------------------------------*/
  25. void SystemClock_Config(void);
  26. /* USER CODE BEGIN PFP */

  27. /* USER CODE END PFP */

  28. /* Private user code ---------------------------------------------------------*/
  29. /* USER CODE BEGIN 0 */

  30. /* USER CODE END 0 */

  31. /**
  32.   * @brief  The application entry point.
  33.   * @retval int
  34.   */
  35. int main(void)
  36. {
  37.   /* USER CODE BEGIN 1 */
  38.         uint16_t dutyCycle = 0;
  39.   /* USER CODE END 1 */
  40.   

  41.   /* MCU Configuration--------------------------------------------------------*/

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

  44.   /* USER CODE BEGIN Init */

  45.   /* USER CODE END Init */

  46.   /* Configure the system clock */
  47.   SystemClock_Config();

  48.   /* USER CODE BEGIN SysInit */

  49.   /* USER CODE END SysInit */

  50.   /* Initialize all configured peripherals */
  51.   MX_GPIO_Init();
  52.   MX_TIM3_Init();
  53.   MX_USART1_UART_Init();
  54.   MX_TIM2_Init();
  55.   /* USER CODE BEGIN 2 */
  56. //        HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2);
  57.         HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_2);
  58.         printf("test\r\n");
  59.   /* USER CODE END 2 */

  60.   /* Infinite loop */
  61.   /* USER CODE BEGIN WHILE */
  62.   while (1)
  63.   {
  64.     /* USER CODE END WHILE */

  65.     /* USER CODE BEGIN 3 */
  66. //                while(dutyCycle < 1000)
  67. //                {
  68. //                        dutyCycle++;
  69. //                        __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, dutyCycle);
  70. //                        HAL_Delay(1);
  71. //                }
  72. //                while(dutyCycle)
  73. //                {
  74. //                        dutyCycle--;
  75. //                        __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, dutyCycle);
  76. //                        HAL_Delay(1);
  77. //                }
  78.                
  79.                 while(dutyCycle < 1000)
  80.                 {
  81.                         dutyCycle++;
  82.                         __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_2, dutyCycle);
  83.                         HAL_Delay(1);
  84.                 }
  85.                 while(dutyCycle)
  86.                 {
  87.                         dutyCycle--;
  88.                         __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_2, dutyCycle);
  89.                         HAL_Delay(1);
  90.                 }
  91.   }
  92.   /* USER CODE END 3 */
  93. }

  94. /**
  95.   * @brief System Clock Configuration
  96.   * @retval None
  97.   */
  98. void SystemClock_Config(void)
  99. {
  100.   RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  101.   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  102.   /** Configure the main internal regulator output voltage
  103.   */
  104.   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  105.   /** Initializes the CPU, AHB and APB busses clocks
  106.   */
  107.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;
  108.   RCC_OscInitStruct.MSIState = RCC_MSI_ON;
  109.   RCC_OscInitStruct.MSICalibrationValue = 0;
  110.   RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_5;
  111.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  112.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  113.   {
  114.     Error_Handler();
  115.   }
  116.   /** Initializes the CPU, AHB and APB busses clocks
  117.   */
  118.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  119.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  120.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI;
  121.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  122.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  123.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  124.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
  125.   {
  126.     Error_Handler();
  127.   }
  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****/
復(fù)制代碼
全部資料51hei下載地址:
stm32l151_pwm.7z (248.05 KB, 下載次數(shù): 26)
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

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

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 日韩在线免费 | 日本三级电影在线免费观看 | 一区二区三区视频在线观看 | 欧美一区二区三区久久精品 | 欧美男人天堂 | 女人牲交视频一级毛片 | 国产视频福利一区 | 一区二区国产在线 | 91中文视频| 国产精品一区二区免费看 | av日韩在线播放 | 国产在线1 | 久久久久久久一区二区三区 | 国产精品欧美精品 | 日日爱av | 久久99蜜桃综合影院免费观看 | 日韩男人天堂 | 欧美一区二区在线播放 | 成人欧美一区二区三区视频xxx | 精品久久精品 | 久久综合欧美 | 日本一区二区三区在线观看 | 国产精品久久久久av | 久草免费在线视频 | 亚洲综合色自拍一区 | 欧美精品中文字幕久久二区 | 91国内在线观看 | 欧美性猛交一区二区三区精品 | 狠狠操狠狠干 | 久久久久久久综合 | 精品国产免费一区二区三区五区 | 国产精品美女一区二区三区 | 国产91综合一区在线观看 | 久久久久久国产精品免费免费男同 | 欧美在线一区二区三区 | 欧美一区二区三区在线看 | 欧美成视频在线观看 | 午夜精品久久久久久不卡欧美一级 | 欧美在线天堂 | 久久精品小视频 | 91久久精品国产91久久 |