主要问题如题目。KEIL5 V2.26搭配最新版本的pack,(因为之前用V5.18也不运行,就换了新版本)。仿真的话在RCC里面出不来,已经选中了run to main 。这是为什么呢?怀疑是少写了什么程序问题,还是??
下面是主程序;(测量引脚与PWM引脚均不对)
int main(void)
{
RCC_Configuration();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
LED_Init();
TIM2_PWM_Init(9999,143); //50Hz
TIM_SetCompare1(TIM2,5000); //50Hz
TIM_SetCompare2(TIM2,4000); //50Hz
TIM_SetCompare3(TIM2,3000); //50Hz
TIM_SetCompare4(TIM2,2000); //50Hz
while(1)
{
GPIO_SetBits(LED_PORT,LED1_BIT);
GPIO_ResetBits(LED_PORT,LED2_BIT);
delay_ms(100);
}
}
void LED_Init(void)
{
GPIO_InitTypeDef GPIO_InitStrue;
RCC_APB2PeriphClockCmd(LED_CLK,ENABLE);
GPIO_InitStrue.GPIO_Pin=LED1_BIT;
GPIO_InitStrue.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_InitStrue.GPIO_Speed=GPIO_Speed_10MHz;
GPIO_Init(LED_PORT,&GPIO_InitStrue);
}
void TIM2_PWM_Init(u16 arr,u16 psc)
{
GPIO_InitTypeDef GPIO_InitStrue;
TIM_OCInitTypeDef TIM_OCInitStrue;
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStrue;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
GPIO_InitStrue.GPIO_Pin=GPIO_Pin_0 | GPIO_Pin_1
| GPIO_Pin_2 |GPIO_Pin_3;
GPIO_InitStrue.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStrue.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStrue);
TIM_TimeBaseInitStrue.TIM_Period=arr;
TIM_TimeBaseInitStrue.TIM_Prescaler=psc;
TIM_TimeBaseInitStrue.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseInitStrue.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseInitStrue);
TIM_OCInitStrue.TIM_OCMode=TIM_OCMode_PWM1;
TIM_OCInitStrue.TIM_OCPolarity=TIM_OCPolarity_High;
TIM_OCInitStrue.TIM_OutputState=TIM_OutputState_Enable;
TIM_OCInitStrue.TIM_Pulse = arr/10;
TIM_OC1Init(TIM2,&TIM_OCInitStrue);
TIM_OC1PreloadConfig(TIM2,TIM_OCPreload_Enable);
TIM_OC2Init(TIM2,&TIM_OCInitStrue);
TIM_OC2PreloadConfig(TIM2,TIM_OCPreload_Enable);
TIM_OC3Init(TIM2,&TIM_OCInitStrue);
TIM_OC3PreloadConfig(TIM2,TIM_OCPreload_Enable);
TIM_OC4Init(TIM2,&TIM_OCInitStrue);
TIM_OC4PreloadConfig(TIM2,TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM2, ENABLE);
TIM_Cmd(TIM2,ENABLE);
} |