新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 我的ARM編程技巧---積累

我的ARM編程技巧---積累

作者: 時間:2016-11-26 來源:網(wǎng)絡(luò) 收藏

********************************************************************
**************系統(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)
{
}
}
*****************//初始化獨(dú)立看門狗******************************
********************************************************************
********************************************************************
********************************************************************
void IWDG_Configuration(void)
{


//是能或者失能對寄存器IWDG_PR和IWDG_RLR
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);


//選定工作頻率
IWDG_SetPrescaler(IWDG_Prescaler_32);


//設(shè)置重裝載值
IWDG_SetReload(230);


//按照重裝載器的值重裝載IWDG計數(shù)器的值-----------此動作相當(dāng)于“喂狗”
IWDG_ReloadCounter();


//使能IWDG
IWDG_Enable();
}
/ *******************
/
TIM_DeInit(TIM1);//將外設(shè)TIMx寄存器重設(shè)為缺省值
//2、基礎(chǔ)設(shè)置

TIM1_TimeBaseStructure.TIM_Prescaler = 0x0; //預(yù)分頻,此值+1為分頻的除數(shù)得到計數(shù)周期;
TIM1_TimeBaseStructure.TIM_Period = 0xFFFF;//計數(shù)周期(即當(dāng)計數(shù)值達(dá)到“計數(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、輸出通道設(shè)置

TIM1_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
//TIM_OCMode_Timing輸出比較時間模式(輸出引腳凍結(jié)無效)
//TIM_OCMode_Active 輸出比較主動模式(匹配時設(shè)置輸出引腳為有效電平,當(dāng)計數(shù)值為比較/捕獲寄存器值相同時,強(qiáng)制輸出為高平)TIM_OCMode_Inactive; 輸出比較非主動模式 (匹配時設(shè)置輸出引腳為無效電平,當(dāng)計數(shù)值為比較/捕獲寄存器值相同時,強(qiáng)制輸出為低電平)
//TIM_OCMode_Toggle 輸出比較觸發(fā)模式(翻轉(zhuǎn)。當(dāng)計數(shù)值與比較/捕獲寄存器值相同時,翻轉(zhuǎn)輸出引腳的電平)
//TIM_OCMode_PWM1向上計數(shù)時,當(dāng)TIMx_CNT < TIMx_CCR*時,輸出電平有效,否則為無效,
//向下計數(shù)時,當(dāng)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);


上一頁 1 2 下一頁

關(guān)鍵詞: ARM編程技

評論


技術(shù)專區(qū)

關(guān)閉