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.

73 lines
1.6 KiB

3 weeks ago
/*
* Timer.c
*
* Created on: Feb 28, 2025
* Author: bihon
*/
#include "Timer.h"
uint16_t Timer_Value; //用于存储计时时间
static uint16_t Time;//静态变量,用于实际计时
volatile uint8_t Timer_Stop_Permission;//计时中断允许标志
volatile uint8_t Timer_Stop_Mark; //计时器停止标志
/**
* @brief
* @param set_time ms
* @param stop_perm 0 1
* @return 1 0
* @note 2ms set_time / 2
*/
uint8_t Timer_Set(uint16_t set_time, uint8_t stop_perm)
{
if(set_time >= 2)
{
Timer_Value = set_time / 2;
Time = Timer_Value;//为定时器赋计数值
Timer_Stop_Permission = stop_perm;//为定时器允许中断标志赋值
Timer_Stop_Mark = 0;//定时器停止标志恢复默认值
return 1;//设置成功
}else
{
return 0;//参数错误,设置失败
}
}
/**
* @brief
* @return 1 02
*/
uint8_t Timer_Start_Count()
{
//定时器周期为2ms,实际计时数据为设定时间除2
if(!Timer_Stop_Mark)
{
if(Time >= 0)
{
if(Time == 0)
{
return 1;//计时结束
}
Time--;
return 0;//仍在计时
}
}else
{
Time = 0;//计数器清零
return 2;//停止计时
}
}
/**
* @brief
*/
void Timer_Stop_Count()
{
if(Timer_Stop_Permission == 1)
{
Timer_Stop_Mark = 1;
}
}