#include "
timer.h"
#include "
STM32f10x.h"
extern u16 ccr1;
void TIM3_IRQHandler(void) //TIM3ÖжÏ
{
if (TIM_GetITStatus(TIM3, TIM_IT_CC1) != RESET) //¼ì²éÖ¸¶¨µÄTIMÖжϷ¢ÉúÓë·ñ:TIM ÖжÏÔ´
{
TIM_ClearITPendingBit(TIM3, TIM_IT_CC1 ); //Çå³ýTIMxµÄÖжϴý´¦Àíλ:TIM ÖжÏÔ´
if(ccr1<5000)
{
ccr1=ccr1+500;
}
else ccr1=999;
TIM_SetCompare1(TIM3,ccr1);
}
}
void TIM13_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1 , ENABLE);
/* TIM3 and TIM4 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
TIM_TimeBaseStructure.TIM_Period = 5559;
TIM_TimeBaseStructure.TIM_Prescaler =0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
GPIO_PinRemapConfig(GPIO_FullRemap_TIM3, ENABLE);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_Pulse = 499;
TIM_ClearFlag(TIM3, TIM_FLAG_CC1);
TIM_ITConfig(TIM3,TIM_IT_CC1,ENABLE);//ÖжÏʹÄÜ
TIM_OC1Init(TIM3, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Disable);
/* Slave Mode selection: TIM3 */
TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Trigger);
TIM_SelectInputTrigger(TIM3, TIM_TS_ITR0);
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Period = 255;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_RepetitionCounter = 4;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
/* Channel 1 Configuration in PWM mode */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
TIM_OCInitStructure.TIM_Pulse = 127;
TIM_OC1Init(TIM1, &TIM_OCInitStructure);
GPIO_PinRemapConfig(GPIO_FullRemap_TIM1, ENABLE);
TIM_SelectOutputTrigger(TIM1, TIM_TRGOSource_Update);
/* Select the Master Slave Mode */
TIM_SelectMasterSlaveMode(TIM1, TIM_MasterSlaveMode_Enable);
/* TIM1 counter enable */
TIM_Cmd(TIM1, ENABLE);
/* TIM enable counter */
TIM_Cmd(TIM3, ENABLE);
/* Main Output Enable */
TIM_CtrlPWMOutputs(TIM1, ENABLE);
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOE |RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel=TIM3_IRQn;//ʹÄÜÖжÏ
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
TIM_ITConfig(TIM1, TIM_IT_CC1,ENABLE);//使能或者失能指定的TIM中断
这个没打开吧?
一周热门 更多>