void main(void)
{
SCLK_Config();
GPIO_DeInit(GPIOC);
GPIO_Init(GPIOC, GPIO_PIN_5, GPIO_MODE_OUT_PP_HIGH_SLOW);
//TIM4_init1();
TIM2_init();
__enable_interrupt();
while(1);
}
void TIM4_init1()
{
TIM4_DeInit();
TIM4_TimeBaseInit(TIM4_PRESCALER_16, 999);
TIM4_PrescalerConfig(TIM4_PRESCALER_1, TIM4_PSCRELOADMODE_IMMEDIATE);
TIM4_ARRPreloadConfig(ENABLE);
TIM4_ITConfig(TIM4_IT_UPDATE, ENABLE);
TIM4_Cmd(ENABLE);
}
void TIM2_init()
{
TIM2_DeInit();
TIM2_TimeBaseInit(TIM2_PRESCALER_16, 2999);
TIM2_PrescalerConfig(TIM2_PRESCALER_1, TIM2_PSCRELOADMODE_IMMEDIATE);
TIM2_ARRPreloadConfig(ENABLE);
TIM2_ITConfig(TIM2_IT_UPDATE, ENABLE);
TIM2_Cmd(ENABLE);
}
void SCLK_Config(void)
{
CLK_DeInit(); //寄存器复位
CLK_HSICmd(ENABLE); //内部高速时钟使能
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1); //内部1分频16M
//CLK->PCKENR1 = 0xff;
}
#pragma vector=0xF
__interrupt void TIM2_UPD_OVF_BRK_IRQHandler(void)
#endif
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
if(COUNTER<10000)
{
COUNTER++;
//
}
else
{
if(GPIO_ReadInputData(GPIOC)&0x20)
{
GPIO_WriteLow(GPIOC, GPIO_PIN_5);
}
else
{
GPIO_WriteHigh(GPIOC, GPIO_PIN_5);
}
COUNTER=0;
}
TIM2_ClearITPendingBit(TIM2_IT_UPDATE);
}
新手刚接触STM8!!!!!!!!!
原本的初始化是定时器2的例子,改成定时器4就可以产生中断,用定时器2就不行。好像进不了中断,求大侠帮忙,都搞了一个多星期了。 |