马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
我的代码是照着书上敲的,为什么没有出现相对应的波形呀(stm32)
#include "stm32f10x.h"
#include <stdio.h>
void LED0_Config(void);
void LED0_On(void);
void LED0_Off(void);
void TIM2_Delay500ms(void);
int main()
{
unsigned int CountOfToggle=0;
LED0_Config();
while(1)
{
LED0_On();
TIM2_Delay500ms();
LED0_Off();
TIM2_Delay500ms();
CountOfToggle++;
//printf("The Count of Toggle is %d\n",CountOfToggle);
}
}
void LED0_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;//普通推挽;pp-->push-pull
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_8;
GPIO_Init(GPIOA,&GPIO_InitStructure);
}
void LED0_On(void)
{
GPIO_ResetBits(GPIOA,GPIO_Pin_8);
}
void LED0_Off(void)
{
GPIO_SetBits(GPIOA,GPIO_Pin_8);
}
void TIM2_Delay500ms(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Prescaler=36000-1;
TIM_TimeBaseStructure.TIM_Period=1000-1;
TIM_TimeBaseInit(TIM2,&TIM_TimeBaseStructure);
TIM_ClearFlag(TIM2,TIM_FLAG_Update);
TIM_Cmd(TIM2,ENABLE);
while(TIM_GetFlagStatus(TIM2,TIM_FLAG_Update)==RESET);
}
|