9/24 今天大概只会学习个半天 然后就下午看论文去了
说说 定时中断的编码逻辑
- RCC 开启时钟使能
 
- 选择时基单元的时钟源
 
- 配置时基单元(结构体)
- 预分频器
 
- 自动重装器
 
- 计数模式
 
 
- 配置输出中断控制
 
- 配置NVIC 打开定时中断的通道 并分配优先级
- nvic 优先级分组
 
- nvic结构体设置
 
- 启动定时器
 
 
大概的代码
这个代码是外部时钟源 来驱动电路
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
   | #include "stm32f10x.h"                  
 
  void Timer_Init(void) {      	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); 	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); 	GPIO_InitTypeDef gpioA_initStruct; 	gpioA_initStruct.GPIO_Mode = GPIO_Mode_IPU; 	gpioA_initStruct.GPIO_Pin = GPIO_Pin_0; 	gpioA_initStruct.GPIO_Speed = GPIO_Speed_50MHz;  	GPIO_Init(GPIOA, &gpioA_initStruct);      	TIM_ETRClockMode2Config(TIM2, TIM_ExtTRGPSC_OFF, TIM_ExtTRGPolarity_NonInverted, 0x00); 	 	TIM_TimeBaseInitTypeDef TIM_InitStruct; 	           	TIM_InitStruct.TIM_ClockDivision = TIM_CKD_DIV1; 	TIM_InitStruct.TIM_CounterMode = TIM_CounterMode_Up; 	 	TIM_InitStruct.TIM_Period = 10 - 1 ; 	 	TIM_InitStruct.TIM_Prescaler = 1 - 1; 	 	TIM_InitStruct.TIM_RepetitionCounter = 0x0000; 	TIM_TimeBaseInit(TIM2, &TIM_InitStruct); 	 	 	 	 	TIM_ClearFlag(TIM2, TIM_FLAG_Update); 	 	TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE); 	 	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); 	NVIC_InitTypeDef nvic_InitStruct; 	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); 	 	TIM_Cmd(TIM2,ENABLE);
  }
 
 
   |