You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
840 B
37 lines
840 B
2 years ago
|
#include "main.h"
|
||
|
|
||
|
/* 微秒 阻塞硬延时 */
|
||
|
|
||
|
extern void for_delay_us(uint32_t us);
|
||
|
extern void HAL_Delay_us(uint16_t us);
|
||
|
|
||
|
void for_delay_us(uint32_t us)
|
||
|
{
|
||
|
/* 阻塞 硬延时*/
|
||
|
uint32_t Delay = us * 168 ;
|
||
|
for (size_t i = 0; i < Delay; i++);
|
||
|
}
|
||
|
|
||
|
void HAL_Delay_us(uint16_t us)
|
||
|
|
||
|
{
|
||
|
// uint16_t differ = 0xffff - us - 5; // 设定定时器计数器起始值
|
||
|
// __HAL_TIM_SET_COUNTER(&htim6, differ);
|
||
|
// HAL_TIM_Base_Start(&htim6); // 启动定时器
|
||
|
// while (differ < 0xffff - 6) // 补偿,判断
|
||
|
|
||
|
// {
|
||
|
// differ = __HAL_TIM_GET_COUNTER(&htim6); // 查询计数器的计数值
|
||
|
|
||
|
// }
|
||
|
// HAL_TIM_Base_Stop(&htim6);
|
||
|
|
||
|
}
|
||
|
|
||
|
// void HAL_Delay_us(uint16_t us)
|
||
|
// {
|
||
|
// uint16_t startCnt = __HAL_TIM_GET_COUNTER(&htim6);
|
||
|
|
||
|
// while ((__HAL_TIM_GET_COUNTER(&htim6) - startCnt) <= us);
|
||
|
|
||
|
// }
|