本帖最后由 eehomer 于 2012-3-14 23:01 编辑
11# 香水城
您好,因为我没有说清楚,把您给弄糊涂了,不好意思。
是这样的,因为我没有用库,所以没有加这句if(TIM_GetITStatus(TIM2,TIM_IT_Update)==SET)
我在网上看到别人的程序有这样一句,我就用if((TIM2->SR)&(1<<0))来代替if(TIM_GetITStatus(TIM2,TIM_IT_Update)==SET)。
所以6楼的程序里没有if(TIM_GetITStatus(TIM2,TIM_IT_Update)==SET),而是
if((TIM2->SR)&(1<<0))。
在中断服务里没有if((TIM2->SR)&(1<<0)),似乎程序只能进一次中断,加了就好了。我是定时LED闪烁。
完整的程序是
void TIM2_IRQHandler(void)
{
if((TIM2->SR)&(1<<0))
{
if((GPIOC->ODR)&(0x01))
{
GPIOC->BRR |= (1<<0);
}
else
{
GPIOC->BSRR |= (1<<0);
}
}
TIM2->SR &= ~(1<<0);
}
int main(void)
{
/*使能GPIOC*/
RCC->APB2ENR |= (1<<4);
/*GPIOC推挽输出 50MHz*/
GPIOC->CRL &= ~(3<<2);
GPIOC->CRL |= (3<<0);
/*使能GPIOA*/
RCC->APB2ENR |= (1<<2);
/*GPIOC推挽输出 50MHz*/
GPIOA->CRH &= ~(3<<2);
GPIOA->CRH |= (3<<0);
//hc595_init();
//send_2byte_hc595(0x65,0x65);
NVIC_Config();
timer2_init();
while(1)
{
}
}
void timer2_init(void)
{
RCC->APB1ENR |= (1<<0); //TIM2 timer clock enable
TIM2->PSC = 0x7F;
TIM2->ARR = 0xFFFF;
TIM2->CR1 |= (1<<7); //Auto-reload preload enable
TIM2->CR1 &= ~(3<<5); //Edge-aligned mode
TIM2->CR1 &= ~(1<<4); //Counter used as upcounter
TIM2->CR1 |= (1<<2); //Only counter overflow/underflow generates an update interrupt or DMA request if enable
TIM2->CR1 &= ~(1<<1);
TIM2->CR1 |= (1<<0);
TIM2->DIER |= (1<<0); //Update interrupt enable
//TIM2->DIER |= (1<<6);
}
void NVIC_Config(void)
{
//SCB->VTOR = ((uint32_t)0x08000000);
NVIC->ISER[28>>0x05] = 1<<28;
}
|