中等容量使用定时器TIM3

This commit is contained in:
Stone 2016-06-04 04:11:19 +00:00
parent a04264683c
commit ec75ca6910
3 changed files with 14 additions and 8 deletions

View File

@ -1,4 +1,5 @@
#include "Time.h"
#include "Timer.h"
#include "Platform\stm32.h"
@ -28,7 +29,10 @@ TTime::TTime()
Index = 13;
#else
Div = 0;
Index = 5;
if(Sys.FlashSize > 0x80)
Index = 5;
else
Index = 3;
#endif
BaseSeconds = 0;
@ -60,11 +64,12 @@ void TTime::Init()
//Interrupt.Disable(SysTick_IRQn);
TIM_TypeDef* tim = g_Timers[Index];
#if defined(STM32F0) || defined(GD32F150)
/*#if defined(STM32F0) || defined(GD32F150)
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM14, ENABLE);
#else
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);
#endif
#endif*/
Timer::ClockCmd(Index, true);
// 获取当前频率
#if defined(STM32F0) || defined(GD32F150)

View File

@ -117,7 +117,7 @@ void Timer::Open()
#endif
// 打开时钟
ClockCmd(true);
ClockCmd(_index, true);
// 关闭。不再需要跟上面ClockCmd的效果一样
//TIM_DeInit((TIM_TypeDef*)_Timer);
@ -143,15 +143,15 @@ void Timer::Close()
TIM_Cmd(ti, DISABLE);
TIM_ITConfig(ti, TIM_IT_Update, DISABLE);
TIM_ClearITPendingBit(ti, TIM_IT_Update); // 仅清除中断标志位 关闭不可靠
ClockCmd(false); // 关闭定时器时钟
ClockCmd(_index, false); // 关闭定时器时钟
Opened = false;
}
void Timer::ClockCmd(bool state)
void Timer::ClockCmd(int idx, bool state)
{
FunctionalState st = state ? ENABLE : DISABLE;
switch(_index + 1)
switch(idx + 1)
{
case 1: RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, st); break;
case 2: RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, st); break;

View File

@ -9,7 +9,6 @@ class Timer
protected:
byte _index; // 第几个定时器从0开始
void ClockCmd(bool state);
void SetHandler(bool set);
public:
void* _Timer;
@ -32,6 +31,8 @@ public:
void Register(EventHandler handler, void* param = nullptr);
static void ClockCmd(int idx, bool state);
private:
static void OnHandler(ushort num, void* param);
EventHandler _Handler;