其中主函数如下:
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_TIM2_Init();
/* USER CODE BEGIN 2 */
HAL_TIM_PWM_Start(&htim2,TIM_CHANNEL_1);
HAL_Delay(500);
__HAL_TIM_SET_AUTORELOAD(&htim2, 199); //可以改变arr以改变频率
__HAL_TIM_SetCompare(&htim2, TIM_CHANNEL_1, 80); //修改占空比比较值,一直保持占空比50%
/* USER CODE END 2 */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
|