附上程序,
求指点!!!!!!!!!!!!!
#include "breath.h"
uint8_t Index_Wave[]={1,1,2,2,3,4,6,8,10,14,19,25,33,44,59,
80,107,143,191,143,107,80,59,44,33,25,19,14,10,8,6,4,3,2,2,1,1};
static void TIM3_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);
GPIO_PinRemapConfig(GPIO_FullRemap_TIM3,ENABLE);
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_6;//|GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed =GPIO_Speed_50MHz;
GPIO_Init(GPIOC,&GPIO_InitStructure);
}
static void TIM3_Mode_Init(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_TimeBaseStructure.TIM_ClockDivision =TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode =TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Period =255;
TIM_TimeBaseStructure.TIM_Prescaler =1999;
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseStructure);
TIM_OCInitStructure.TIM_OCMode =TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OCPolarity =TIM_OCPolarity_Low;
TIM_OCInitStructure.TIM_OutputState =TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse =0;
TIM_OC1Init(TIM3,&TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM1,ENABLE);
// TIM_OCInitStructure.TIM_OutputState =TIM_OutputState_Enable;
// TIM_OCInitStructure.TIM_Pulse =0;
// TIM_OC2Init(TIM3,&TIM_OCInitStructure);
// TIM_OC2PreloadConfig(TIM1,ENABLE);
TIM_ARRPreloadConfig(TIM3,ENABLE);
TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE);
TIM_Cmd(TIM3,ENABLE);
}
static void TIM3_NVIC_Init(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel =TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelCmd =ENABLE;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority =0;
NVIC_Init(&NVIC_InitStructure);
}
void TIM3_Breath_Init(void)
{
TIM3_GPIO_Init();
TIM3_Mode_Init();
TIM3_NVIC_Init();
}
此帖出自
小平头技术问答
一周热门 更多>