From 784c510a0cf2a72c63dcb476fb7e49fd31a2147f Mon Sep 17 00:00:00 2001 From: chenguang Date: Sat, 21 Feb 2026 20:09:38 -0500 Subject: [PATCH] =?UTF-8?q?=E5=BB=B6=E8=BF=9F=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 3-5 GPIO_光敏传感器/System/Delay.c | 41 +++++++++++++++++++++++++++++ 3-5 GPIO_光敏传感器/System/Delay.h | 8 ++++++ 2 files changed, 49 insertions(+) create mode 100644 3-5 GPIO_光敏传感器/System/Delay.c create mode 100644 3-5 GPIO_光敏传感器/System/Delay.h diff --git a/3-5 GPIO_光敏传感器/System/Delay.c b/3-5 GPIO_光敏传感器/System/Delay.c new file mode 100644 index 0000000..20089ca --- /dev/null +++ b/3-5 GPIO_光敏传感器/System/Delay.c @@ -0,0 +1,41 @@ +#include "stm32f10x.h" + +/** + * @brief 微秒级延时 + * @param xus 延时时长,范围:0~233015 + * @retval 无 + */ +void Delay_us(uint32_t xus) +{ + SysTick->LOAD = 72 * xus; //设置定时器重装值 + SysTick->VAL = 0x00; //清空当前计数值 + SysTick->CTRL = 0x00000005; //设置时钟源为HCLK,启动定时器 + while(!(SysTick->CTRL & 0x00010000)); //等待计数到0 + SysTick->CTRL = 0x00000004; //关闭定时器 +} + +/** + * @brief 毫秒级延时 + * @param xms 延时时长,范围:0~4294967295 + * @retval 无 + */ +void Delay_ms(uint32_t xms) +{ + while(xms--) + { + Delay_us(1000); + } +} + +/** + * @brief 秒级延时 + * @param xs 延时时长,范围:0~4294967295 + * @retval 无 + */ +void Delay_s(uint32_t xs) +{ + while(xs--) + { + Delay_ms(1000); + } +} diff --git a/3-5 GPIO_光敏传感器/System/Delay.h b/3-5 GPIO_光敏传感器/System/Delay.h new file mode 100644 index 0000000..04c8ef8 --- /dev/null +++ b/3-5 GPIO_光敏传感器/System/Delay.h @@ -0,0 +1,8 @@ +#ifndef __DELAY_H +#define __DELAY_H + +void Delay_us(uint32_t us); +void Delay_ms(uint32_t ms); +void Delay_s(uint32_t s); + +#endif