中级会员
 
- 积分
- 335
- 金钱
- 335
- 注册时间
- 2015-12-18
- 在线时间
- 73 小时
|
5金钱
int main(void)
{
Hardware_Configuration();
SPI_Configuration();
LCD_Init();
LCD_Show(1,3,Buf1);
LCD_Show(2,0,Buf2);
GPIO_SetBits(GPIOC,LED1);
GPIO_SetBits(GPIOC,LED2);
TIM1_PWM_Init();
Tim3_Init();
while(1)
{
ADC_Read();
TIM_SetAutoreload(TIM1,100);
TIM_SetCompare1(TIM1,50);
TIM_SetCompare2(TIM1,90);
if(key_val!=0)
{
Buz(500);
key_val=0;
}
}
}
void TIM1_PWM_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure2;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_BDTRInitTypeDef TIM_BDTRInitStructure;
TIM_DeInit(TIM1);//??????T1?????÷
//?????????????±??
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1|RCC_APB2Periph_GPIOE|RCC_APB2Periph_AFIO,ENABLE);
GPIO_PinRemapConfig(GPIO_FullRemap_TIM1, ENABLE);//Timer1?ê???????? TIM1_CH1-> E9
//????????????GOIO??
GPIO_InitStructure2.GPIO_Pin=GPIO_Pin_8|GPIO_Pin_11|GPIO_Pin_9|GPIO_Pin_12;//?¨??????PWM??????????PE????8??9??11?©
GPIO_InitStructure2.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure2.GPIO_Mode=GPIO_Mode_AF_PP;//?è????????????????
GPIO_Init(GPIOE,&GPIO_InitStructure2);
//?????????¨?±?÷?ù±?????
TIM_TimeBaseStructure.TIM_Period=999;// ×?????×°???????÷????
TIM_TimeBaseStructure.TIM_Prescaler=71;// ?±???¤·??????¨·??????è?????????ò?????????±???ò?á×????????©
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;// ???ù·???
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;//?ò??????
TIM_TimeBaseStructure.TIM_RepetitionCounter=0;//?????????÷??????×????ü??pwm????±?
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
//??????pwm????????
TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_PWM2;//?è????pwm1????????
TIM_OCInitStructure.TIM_Pulse=500; //?è??????±??±??
TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_Low;//?è??????????
TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;//???????¨??????
//???????????????????¨?±?÷???á???????¨???¨?±?÷????????
TIM_OCInitStructure.TIM_OCNPolarity=TIM_OCNPolarity_Low;//?è????????????????
TIM_OCInitStructure.TIM_OutputNState=TIM_OutputNState_Enable;//??????????????
TIM_OCInitStructure.TIM_OCIdleState=TIM_OCIdleState_Reset;//?????ó????×???
TIM_OCInitStructure.TIM_OCNIdleState=TIM_OCNIdleState_Reset;//?????ó??????????×???
TIM_OC1Init(TIM1,&TIM_OCInitStructure); //°??????¨??????????
TIM_OC2Init(TIM1,&TIM_OCInitStructure);
//?????????????????????????????????¨?±?÷?????????¨???¨?±?÷????????
TIM_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Disable;//??????????????
TIM_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Disable;//??????????????????
TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_OFF; //???¨?è??
TIM_BDTRInitStructure.TIM_DeadTime = 0x90; //?????±???è??
TIM_BDTRInitStructure.TIM_Break = TIM_Break_Disable; //????????????
TIM_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_High;//????????????
TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable;//×???????????
TIM_BDTRConfig(TIM1,&TIM_BDTRInitStructure);
//???ù?????????????ò??
TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Enable);//????TIMx??CCR1?????¤×°???????÷?¨?????·?¨????±??©
TIM_ARRPreloadConfig(TIM1, ENABLE);//????TIMx??ARR?????¤×°???????÷?¨?????·?¨???????????©
TIM_Cmd(TIM1,ENABLE);//?ò??TIM1
//???????????????¨?±?÷????????????pwm±????ò??
TIM_CtrlPWMOutputs(TIM1, ENABLE);//pwm?????????????¨???????ò??
}
|
|