#include<stm32f10x_lib.h>
#include "delay.h"
#include "sys.h"
void TIM1_IRQHandler(){
GPIOE->ODR|=0x00000001;
TIM1->SR&=~(1<<1);//清除捕获/比较1事件中断标志位
}
void Timerx_Init(u16 arr,u16 psc){//输入捕获
RCC->APB2ENR|=1<<(2+0);
GPIOA->CRL&=0xFFFFFFF0;
GPIOA->CRL|=0x00000008;
GPIOA->ODR|=0x00000001;
RCC->APB2ENR|=1<<11;//TIM1定时器时钟开启
TIM1->ARR=arr;
TIM1->SC=psc;
TIM1->CCMR1&=0xFFFC;
TIM1->CCMR1|=0x0001;//CC1通道配置为输入,IC1映射到IT1上
TIM1->CCMR1&=0xFF0F;
TIM1->CCMR1|=0x0030;//fsampling=fck_int,N=8
TIM1->CCER&=~(1<<1);//上升沿有效
TIM1->CCMR1&=0xFFF3;//无预分频器,上升沿时产生捕获
TIM1->CCER|=1<<0;//捕获使能
TIM1->DIER|=1<<1;// 使能中断
TIM1->CR1|=1<<0;//计数器使能
}
void GPIO_Config(){
RCC->APB2ENR|=1<<(2+4);
GPIOE->CRL&=0xFFFFFFF0;
GPIOE->CRL|=0x00000003;
GPIOE->ODR&=0x00000000;
}
int main(){
Stm32_Clock_Init(9);
delay_init(72);
GPIO_Config();
Timerx_Init(65535,65535);
while(1);
} |