-------------------------------------------------------------主程序--------------------------------------------------------------------------------------------------------
#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "led.h"
#include "key.h"
#include "timer.h"
int main(void)
{
Stm32_Clock_Init(9);
KEY_Init();
LED_Init();
delay_init(72);
uart_init(72,9600);
TIM3_Int_Init(5000,7199);
while(1)
{
KEY_Scan(1);
if(KEY0==0)
{
delay_ms(10);
if(KEY0==0)
{
TIM3->CR1|=0x01;
TIM3->DIER|=1<<0;
while(!KEY0);
}
}
}
}
-------------------------------------------------------------定时器3-------------------------------------------------------------------
#include "timer.h"
#include "led.h"
#include "delay.h"
#include "usart.h"
u16 times=0;
void TIM3_IRQHandler(void)
{
if(TIM3->SR&0x0001)
times++;
if(times==4)LED1=0;
if(times==9)
{
LED0=0;
LED1=1;
}
if(times%1==0)
printf("\r\n %d秒\r\n",times);
delay_ms(1000);
TIM3->SR&=0x0000;
}
void TIM3_Int_Init(u16 arr,u16 psc)
{
RCC->APB1ENR|=1<<1;
TIM3->ARR=arr;
TIM3->  SC=psc;
TIM3->CR1|=0x00;
TIM3->DIER|=0<<0;
MY_NVIC_Init(1,3,TIM3_IRQn,2);
}
有劳各位大神帮小弟看一下是怎么了 为什么我松手了 定时器还是不断会计数
我明明在初始化里面关闭计时使能了啊
|