本帖最后由 ARF1939261764 于 2017-7-19 18:38 编辑
为什么我清除标志位的语句放在位置一可以运行,而在位置二就不可以了,定时周期为1s,
这是定时器初始化代码
附全部代码:
[mw_shl_code=c,true]#include "stm32f10x.h"
#include "delay.h"
#include "sys.h"
void LED_GPIO_Init(void)
{
RCC->APB2ENR|=1<<6;
GPIOE->CRL&=0xFF0FFFFF;
GPIOE->CRL|=0x00300000;//ͨÓÃÍÆÍìÊä³ö
GPIOE->ODR|=1<<5;
RCC->APB2ENR|=1<<3;
GPIOB->CRL&=0xFF0FFFFF;
GPIOB->CRL|=0x00300000;//ͨÓÃÍÆÍìÊä³ö
GPIOB->ODR|=1<<3;
}
void Timer_Init(void)
{
NVIC_InitTypeDef NVIC_InitStruct;
RCC->APB1ENR|=0x01;
TIM2->CR1|=1<<7;//TIMx_ARR¼Ä´æÆ÷±»×°È뻺³åÆ÷
TIM2->CR1&=~(u32)(0x03<<5);//±ßÑضÔÆäģʽ
TIM2->CR1&=~(u32)(1<<4);//ÏòÉϼÆÊý
TIM2->CR1&=~(u32)(1<<3);//Á¬Ðø¼¼Êý
TIM2->CR1&=~(u32)(1<<2);
TIM2->CR1&=~(u32)(1<<1);
TIM2->DIER|=1<<0;
TIM2->PSC=7200;
TIM2->ARR=10000;
NVIC_InitStruct.NVIC_IRQChannel=TIM2_IRQn;
NVIC_InitStruct.NVIC_IRQChannelCmd=ENABLE;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority=1;
NVIC_InitStruct.NVIC_IRQChannelSubPriority=1;
NVIC_Init(&NVIC_InitStruct);
TIM2->CR1|=1<<0;
}
int main(void)
{
delay_init();
LED_GPIO_Init();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
Timer_Init();
while(1)
{
GPIOB->ODR|=1<<5;
delay_ms(500);
GPIOB->ODR&=~(1<<5);
delay_ms(500);
}
}
void TIM2_IRQHandler(void)
{
TIM2->SR&=0xFFFE;//位置一
PEout(5)=~PEin(5);
//TIM2->SR&=0xFFFE;//位置二
}[/mw_shl_code]
一周热门 更多>