/* TIM1 Peripheral Configuration */
void TIM_Configuration(void)
{/* Time Base configuration */
TIM1_TimeBaseStructure.TIM_Prescaler =71;
TIM1_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM1_TimeBaseStructure.TIM_Period = 1999;
TIM1_TimeBaseStructure.TIM_ClockDivision = 0x0;
TIM1_TimeBaseStructure.TIM_RepetitionCounter = 0x0;
TIM_TimeBaseInit(TIM1,&TIM1_TimeBaseStructure);
/* Channel 1, 2,3 and 4 Configuration in PWM mode */
TIM1_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
TIM1_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM1_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
TIM1_OCInitStructure.TIM_Pulse = CCR1_Val;
TIM1_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM1_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low;
TIM1_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
TIM1_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;
TIM_OC1Init(TIM1,&TIM1_OCInitStructure);
/* Automatic Output enable, Break, dead time and lock configuration*/
TIM1_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable;
TIM1_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable;
TIM1_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_1;
TIM1_BDTRInitStructure.TIM_DeadTime = 0x75;
TIM1_BDTRInitStructure.TIM_Break = TIM_Break_Enable;
TIM1_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_High;
TIM1_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable;
TIM_BDTRConfig(TIM1,&TIM1_BDTRInitStructure);
/* TIM1 counter enable */
TIM_Cmd(TIM1,ENABLE);
/* Main Output Enable */
TIM_CtrlPWMOutputs(TIM1,DISABLE);
while(1)
{
CCR1_Val=VAL[0];
TIM1->CCR1 = CCR1_Val;
Delay(2);
CCR1_Val=VAL[1];
TIM1->CCR1 = CCR1_Val;
Delay(2);
CCR1_Val=VAL[2];
TIM1->CCR1 = CCR1_Val;
Delay(2);
CCR1_Val=VAL[3];
TIM1->CCR1 = CCR1_Val;
Delay(2);
CCR1_Val=VAL[4];
TIM1->CCR1 = CCR1_Val;
Delay(2);
}
void EXTI0_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line0) != RESET)
{
TIM_Cmd(TIM1,ENABLE);
TIM_CtrlPWMOutputs(TIM1,ENABLE);
GPIO_SetBits(GPIOC,GPIO_Pin_6);
}
EXTI_ClearITPendingBit(EXTI_Line0);
}中断
void EXTI_Configuration(void)
{
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource0);
EXTI_InitStructure.EXTI_Line = EXTI_Line0;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
EXTI_GenerateSWInterrupt(EXTI_Line0);
}
} |