TIM_OCMode_Timing模式

2019-10-14 20:49发布

keil MDK4.12能否进行定时器TIM_OCMode_Timing模式仿真????我写了程序,连续检查了4天,看了一些网上程序,包括stm32自带的程序,论坛中的程序也看了,就是不能进入捕获比较中断,跪求解释!!

#include "stm32f10x_lib.h"   //包含了所有的头文件
void RCC_Configuration(void);
void NVIC_Configuration(void);
void GPIO_Configuration(void);
void TIM_Configuration(void); int main(void)
{  #ifdef DEBUG
   debug();
 #endif    RCC_Configuration();    //使能外设时钟
   GPIO_Configuration();   //初始化GPIO管脚
  NVIC_Configuration();  //中断优先级设置
  TIM_Configuration() 
 while(1);
} //--------Tim2设置---------------------------
void TIM_Configuration(void)
{
 
 TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
 TIM_OCInitTypeDef    TIM_OCInitStructure;  TIM_DeInit(TIM2);
 TIM_TimeBaseStructure.TIM_Period = 400;     
 TIM_TimeBaseStructure.TIM_Prescaler = 35999; 
 TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;   //设置时钟分割系数
 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //向上计数
 TIM_TimeBaseInit(TIM2,&TIM_TimeBaseStructure);   TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;         
  TIM_OCInitStructure.TIM_Channel = TIM_Channel_1;         
  TIM_OCInitStructure.TIM_Pulse = 200; 
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
  TIM_OC1Init(TIM2, &TIM_OCInitStructure);

 TIM_ITConfig(TIM2, TIM_IT_CC1, ENABLE );  //使能中断
  TIM_InternalClockConfig(TIM2);  //配置 TIM 的内部时钟
  TIM_Cmd(TIM2,ENABLE);//使能TIM2
} //----------GPIO设置--------------------------
void GPIO_Configuration(void) 
{
 GPIO_InitTypeDef GPIO_InitStructure;
 GPIO_DeInit(GPIOA);    //初始化
 
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;  
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;    // 推挽输出
 GPIO_Init(GPIOA,&GPIO_InitStructure);
}
//-------------设置时钟72mhz------------------------------
void RCC_Configuration(void)
{
 RCC_DeInit();    //初始化
 RCC_HSEConfig(RCC_HSE_ON);   //时钟使能
 while (RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET);  //等待高速时钟就绪
 FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); 
 FLASH_SetLatency(FLASH_Latency_2);      
 RCC_HCLKConfig(RCC_SYSCLK_Div1);   
 RCC_PCLK2Config(RCC_HCLK_Div1);   
 RCC_PCLK1Config(RCC_HCLK_Div2);     
 RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); ////使用锁相环输出72Mhz
 RCC_PLLCmd(ENABLE);        // Enable PLL
 while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);  // Wait till PLL is ready
 RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);    
 while(RCC_GetSYSCLKSource() != 0x08); RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);//开启定时器2时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOA, ENABLE); // 使能外设时钟
} ----------------------------------------------
void NVIC_Configuration(void)
{
 NVIC_InitTypeDef NVIC_InitStructure;
 NVIC_DeInit();
 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);   
 NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQChannel;  
 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 7;
 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE ;
 NVIC_Init(&NVIC_InitStructure);
}
-------------中断函数---------------------------
char a=0x00;
void TIM2_IRQHandler(void)
{
   a=~a;
 GPIOA->ODR=(a&0x01);
    TIM_ClearITPendingBit(TIM2, TIM_IT_CC1); // 清除中断标志位
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
5条回答
XINSHOU0
2019-10-15 02:55

哦,对不起原子哥,打错了,库函数中如下: 

/* TIM Output Compare and PWM modes -----------------------------------------*/
 
#define TIM_OCMode_Timing                  ((u16)0x0000)    // TIM输出比较时间模式
#define TIM_OCMode_Active                  ((u16)0x0010)   
#define TIM_OCMode_Inactive                ((u16)0x0020)  
#define TIM_OCMode_Toggle                  ((u16)0x0030)  
#define TIM_OCMode_PWM1                    ((u16)0x0060)  
#define TIM_OCMode_PWM2                    ((u16)0x0070)  


求原子哥、大神们指点,万分感谢!

一周热门 更多>