一、Pinout
二、Clock Configuration
三、Configuration
定时器溢出时间
Tout=((arr+1)∗(psc+1))/TclkTout=((arr+1)∗(psc+1))/Tclk
四、Generate Code
代码
定时器溢出时间为500ms,500ms翻转一次LED状态
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration----------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_TIM3_Init();
/* USER CODE BEGIN 2 */
HAL_TIM_Base_Start_IT(&htim3);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
static unsigned char ledState = 0;
if (htim == (&htim3))
{
if (ledState == 0)
HAL_GPIO_WritePin(GPIOF,GPIO_PIN_9,GPIO_PIN_RESET);
else
HAL_GPIO_WritePin(GPIOF,GPIO_PIN_9,GPIO_PIN_SET);
ledState = !ledState;
}
}
上一篇:STM32 HAL库学习系列第8篇---回调函数总结
下一篇:stm32 ucos LED灯延时闪烁+按键闪烁+串口输出
推荐阅读最新更新时间:2024-03-16 16:05