想用一个定时器做一个倒计时,可是总是失败,觉是配置的问题,可是根据中文开发手册找不出问题,请大神指点一下。u8 count=0;
u8 closetime=0;
void GPIO_Init()
{
RCC->APB2ENR|=1<<2; //ʹÄÜPORTAʱÖÓ
GPIOA->CRL&=0X0FFFFFFF; //PA7ÉèÖóÉÊäÈ룬ĬÈÏÏÂÀ
GPIOA->CRL|=0X80000000;
GPIOA->ODR|=1<<7; //ÉèÖÃΪÉÏÀÊäÈë
}
void TIM3_Int_Init(u16 arr,u16 psc)
{
RCC->APB1ENR|=1<<1; //TIM3ʱÖÓʹÄÜ
TIM3->ARR=arr; //É趨¼ÆÊýÆ÷×Ô¶¯ÖØ×°Öµ//¸ÕºÃ1ms
TIM3->PSC=psc; //Ô¤·ÖƵÆ÷7200,µÃµ½10KhzµÄ¼ÆÊýʱÖÓ
TIM3->CR1&=0<<4; //¼ÆÊýÆ÷ÏòÉϼÆÊý
TIM3->CCMR1&=0<<12; //ͨµÀ2²»ÉèÖò¶»ñÂ˲¨Æ÷
TIM3->CCMR1|=1<<8; //Ñ¡ÔñÊäÈ벶»ñÔ´£¬CC2ͨµÀ±»ÅäÖÃΪÊäÈ룬IC2Ó³ÉäÔÚTI2ÉÏ£»
TIM3->CCER|=1<<5; //È·¶¨¼«ÐÔ
TIM3->SMCR|=6<<0; //ÅäÖö¨Ê±Æ÷Ϊ´¥·¢Ä£Ê½
TIM3->SMCR|=6<<4; //ÅäÖÃÑ¡ÔñTI2×÷ΪÊäÈëÔ´¡£µ±TI2³öÏÖÒ»¸öÉÏÉýÑØʱ£¬¼ÆÊýÆ÷¿ªÊ¼ÔÚÄÚ²¿Ê±ÖÓÇý¶¯Ï¼ÆÊý£¬Í¬Ê±ÉèÖÃTIF±ê־루´¥·¢±ê־룩£»
TIM3->DIER|=1<<6; // ÔÊÐí´¥·¢ÖжÏ
//TIM3->DIER|=1<<0; //ÔÊÐí¸üÐÂÖжÏ
TIM3->CR1|=0x01; //ʹÄܶ¨Ê±Æ÷3
MY_NVIC_Init(1,3,TIM3_IRQn,2);//ÇÀÕ¼1£¬×ÓÓÅÏȼ¶3£¬×é2
}
//¶¨Ê±Æ÷3ÖжϷþÎñ³ÌÐò
void TIM3_IRQHandler(void)
{
if(TIM3->SR&0X0020)//´¥·¢ÖжÏ
{
closetime=1;
LED1=!LED1;
TIM3->DIER|=1<<0; //ÔÊÐí¸üÐÂÖжÏ
if(TIM3->SR&0x0001)
{
TIM3->SR&=~(1<<0);
count=count+1;
if(count==30)
{
closetime=0; //Çл»½çÃæ±êÖ¾
TIM3->SR=0;
}
}
}
}
|