Files
New_STC32G_All_Board/Source/delay.c
2025-08-31 21:37:24 +08:00

52 lines
1.9 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "delay.h"
static vuint16 delay_ms_a = 0;
static vuint16 delay_us_a = 0;
//-------------------------------------------------------------------------------------------------------------------
// @brief 软件延时函数初始化
// @param NULL
// @return void
// Sample usage: 无需用户调用用户请使用h文件中的宏定义
//-------------------------------------------------------------------------------------------------------------------
void delay_init(void)
{
delay_ms_a = sys_clk / 6000;
delay_us_a = sys_clk / 7000000;
if(sys_clk <= 12000000) delay_us_a++;
}
//-------------------------------------------------------------------------------------------------------------------
// @brief 软件延时函数
// @param x 需要延时的时间ms
// @return void
// Sample usage: 无需用户调用用户请使用h文件中的宏定义
//-------------------------------------------------------------------------------------------------------------------
void delay_ms(uint16 ms)
{
uint16 i;
do {
i = delay_ms_a;
//i = sys_clk/6000;//参数: ms,要延时的ms数, 这里只支持1~255ms. 自动适应主时钟.
while(--i);
}while(--ms);
}
//-------------------------------------------------------------------------------------------------------------------
// @brief 软件延时函数(这是一个不准确的延时)
// @param x 需要延时的时间us
// @return void
// Sample usage: 无需用户调用用户请使用h文件中的宏定义
//-------------------------------------------------------------------------------------------------------------------
void delay_us(uint32 us)
{
uint16 i;
do {
i = delay_us_a;
//i = sys_clk/6000;//参数: ms,要延时的ms数, 这里只支持1~255ms. 自动适应主时钟.
while(--i);
}while(--us);
}