帮我看一下程序
include "time.h"
#include "led.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
uint16_t TimerPeriod = 0;
uint16_t Channel1Pulse = 0, Channel2Pulse = 0, Channel3Pulse = 0, Channel4Pulse = 0;
void TIM_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM14, ENABLE);
RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;// | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource1, GPIO_AF_0);
void TIM_PWM_Config(void)
{
TimerPeriod = (SystemCoreClock/2000000) -1 ;
Channel1Pulse = (uint16_t) (((uint32_t) 5 * ( TimerPeriod - 1)) / 10);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM14 , ENABLE);
TIM_TimeBaseStructure.TIM_Prescaler =0 ;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; /* Time ¶¨Ê±ÉèÖÃΪÉÏÉýÑؼÆËãģʽ*/
TIM_TimeBaseStructure.TIM_Period = 0;//TimerPeriod;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM14, &TIM_TimeBaseStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;
TIM_OCInitStructure.TIM_Pulse = Channel1Pulse;//ʹÄÜƵµÀ1ÅäÖÃ
TIM_OC1Init(TIM14, &TIM_OCInitStructure);
TIM_Cmd(TIM14, ENABLE);
// /* TIM1 Ö÷Êä³öʹÄÜ */
TIM_CtrlPWMOutputs(TIM14, ENABLE);
// TIM_ITConfig(TIM3,TIM_IT_CC1,ENABLE);
//// .NVIC_IRQChannel=TIM3_IRQN;
//// NVIC_Init
}
|