对于定时器的实现,也是很容易,HAL直接提供了该延时函数
/**
* [url=home.php?mod=space&uid=247401]@brief[/url] This function provides accurate delay (in milliseconds) based
* on variable incremented.
* [url=home.php?mod=space&uid=536309]@NOTE[/url] In the default implementation , SysTick timer is the source of time base.
* It is used to generate interrupts at regular time intervals where uwTick
* is incremented.
* @note This function is declared as __weak to be overwritten in case of other
* implementations in user file.
* @param Delay: specifies the delay time length, in milliseconds.
* @retval None
*/
__weak void HAL_Delay(__IO uint32_t Delay)
{
uint32_t tickstart = 0U;
tickstart = HAL_GetTick();
while((HAL_GetTick() - tickstart) < Delay)
{
}
}
参数是微秒级。对于一般的应用足够了
而实现翻转,就是调用了HAL库函数里的翻转指令
void HAL_GPIO_TogglePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
{
/* Check the parameters */
assert_param(IS_GPIO_PIN(GPIO_Pin));
GPIOx->ODR ^= GPIO_Pin;
}
位操作运算,异或。
|