我看过很多例程,精确延时貌似只是把定时器开了,并没有关断定时器,可能表达不清楚,我上代码
#include "stm8s.h"
#include "sysclock.h"
uint32_t X;
/* Private defines -----------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
void Delay(uint32_t Y)
{
X=Y;
TIM1_Cmd(ENABLE);
while(X!=0);
}
int main(void)
{
/* 设置外部24M晶振为系统时钟 */
//SystemClock_Init(HSE_Clock);
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
GPIO_Init(GPIOD, GPIO_PIN_4 ,GPIO_MODE_OUT_PP_LOW_FAST);
TIM1_TimeBaseInit(16, TIM1_COUNTERMODE_UP, 1000, 0x00);
TIM1_ITConfig(TIM1_IT_UPDATE, ENABLE);
TIM1_ARRPreloadConfig(ENABLE);
__enable_interrupt();
while (1)
{
/*放置你的代码*/
GPIO_WriteReverse(GPIOD, GPIO_PIN_4);
Delay(100);
}
}
下面是中断程序,我是这么写的,我的意思是其实每次程序都进来中断的,只不过我们利用了他计数而已
INTERRUPT_HANDLER(TIM1_UPD_OVF_TRG_BRK_IRQHandler, 11)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
if(X!=0)
{
X--;
TIM1_ClearITPendingBit(TIM1_IT_UPDATE);
}
}
大多数例程是这样的,这样是不是很浪费?
INTERRUPT_HANDLER(TIM1_UPD_OVF_TRG_BRK_IRQHandler, 11)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
if(X!=0)
{
X--;
}
TIM1_ClearITPendingBit(TIM1_IT_UPDATE);
}
由此想到了stm32的滴答计时器,貌似很多例程也是只见看不见关,但是我上面贴的stm8的代码(我自己写的那个)个人感觉不会重复进入,发帖的目的就是想知道,stm32滴答他没关断会不会重复进入中断?我感觉是会的。。。如果会,那些例程是不是不够严谨。--------菜鸟求教
|