********************************************************************
**************系統(tǒng)時鐘的配置RCC_Configuration**********************
********************************************************************
********************************************************************
********************************************************************
void RCC_Configuration(void)
{
RCC_DeInit();
RCC_HSEConfig(RCC_HSE_ON);
HSEStartUpStatus = RCC_WaitForHSEStartUp();
if(HSEStartUpStatus == SUCCESS)
{
RCC_HCLKConfig(RCC_SYSCLK_Div1);
RCC_PCLK2Config(RCC_HCLK_Div1);
RCC_PCLK1Config(RCC_HCLK_Div2);
FLASH_SetLatency(FLASH_Latency_2);
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
*/
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
RCC_PLLCmd(ENABLE);
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
{
}
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
while(RCC_GetSYSCLKSource() != 0x08)
{
}
}
*****************//初始化獨立看門狗******************************
********************************************************************
********************************************************************
********************************************************************
void IWDG_Configuration(void)
{
//是能或者失能對寄存器IWDG_PR和IWDG_RLR
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
//選定工作頻率
IWDG_SetPrescaler(IWDG_Prescaler_32);
//設置重裝載值
IWDG_SetReload(230);
//按照重裝載器的值重裝載IWDG計數(shù)器的值-----------此動作相當于“喂狗”
IWDG_ReloadCounter();
//使能IWDG
IWDG_Enable();
}
/ *******************
/
TIM_DeInit(TIM1);//將外設TIMx寄存器重設為缺省值
//2、基礎設置
TIM1_TimeBaseStructure.TIM_Prescaler = 0x0; //預分頻,此值+1為分頻的除數(shù)得到計數(shù)周期;
TIM1_TimeBaseStructure.TIM_Period = 0xFFFF;//計數(shù)周期(即當計數(shù)值達到“計數(shù)值”時,剛好用時一個計數(shù)周期)
TIM1_TimeBaseStructure.TIM_ClockDivision = 0x0;//時鐘因子
TIM1_TimeBaseStructure.TIM_RepetitionCounter = 0x0;
TIM1_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //計數(shù)器模式
//TIM_CounterMode_Dowm向下計數(shù)
//TIM_CounterMode_CenterAligned1 中心對齊方式1
// TIM_CounterMode_CenterAligned2 中心對齊方式2
// TIM_CounterMode_CenterAligned3 中心對齊方式3
TIM_TimeBaseInit(TIM1,&TIM1_TimeBaseStructure);
// 3、輸出通道設置
TIM1_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
//TIM_OCMode_Timing輸出比較時間模式(輸出引腳凍結無效)
//TIM_OCMode_Active 輸出比較主動模式(匹配時設置輸出引腳為有效電平,當計數(shù)值為比較/捕獲寄存器值相同時,強制輸出為高平)TIM_OCMode_Inactive; 輸出比較非主動模式 (匹配時設置輸出引腳為無效電平,當計數(shù)值為比較/捕獲寄存器值相同時,強制輸出為低電平)
//TIM_OCMode_Toggle 輸出比較觸發(fā)模式(翻轉。當計數(shù)值與比較/捕獲寄存器值相同時,翻轉輸出引腳的電平)
//TIM_OCMode_PWM1向上計數(shù)時,當TIMx_CNT < TIMx_CCR*時,輸出電平有效,否則為無效,
//向下計數(shù)時,當TIMx_CNT > TIMx_CCR*時,輸出電平無效,否則為有效
//TIM_OCMode_PWM2 ;與PWM1模式相反
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);
TIM1_OCInitStructure.TIM_Pulse = CCR2_Val;
TIM_OC2Init(TIM1,&TIM1_OCInitStructure);
TIM1_OCInitStructure.TIM_Pulse = CCR3_Val;
TIM_OC3Init(TIM1,&TIM1_OCInitStructure);
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);
TIM_Cmd(TIM1,ENABLE);
TIM_CtrlPWMOutputs(TIM1,ENABLE);
評論