|
#include
#include
#include
#include
void RCC_Cofiguration(void);
void GPIO_Configuration(void);
void TIM_Configuration(void);
void NVIC_Configuration(void);
void TIM7_IRQHandler(void);
int main()
{
GPIO_Configuration();
RCC_Cofiguration();
TIM_Configuration();
NVIC_Configuration();
while(1)
{
GPIO_SetBits(GPIOA,GPIO_Pin_8);
TIM7_IRQHandler();
}
}
void GPIO_Configuration()
{
GPIO_DeInit(GPIOA);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_8 ;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed= GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void RCC_Cofiguration(void)
{
SystemInit();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM7,ENABLE);
}
void TIM_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
TIM_TimeBaseInitStruct.TIM_ClockDivision=0;
TIM_TimeBaseInitStruct.TIM_CounterMode=TIM_CounterMode_Up; //向上计数模式
TIM_TimeBaseInitStruct.TIM_Period=1000; //预装载值 从零计数到1000产生一个溢出标志位
TIM_TimeBaseInitStruct.TIM_Prescaler=36000-1; //定义预分频数值 定时器7输入时钟频率=APB1时钟/(预分频系数+1)=72MHZ/36000=2000HZ
TIM_TimeBaseInit(TIM7,&TIM_TimeBaseInitStruct);
TIM_UpdateRequestConfig(TIM7, TIM_UpdateSource_Regular);
TIM_Cmd(TIM7,ENABLE);
TIM_ITConfig(TIM7,TIM_IT_Update,ENABLE);
}
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStruct;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStruct.NVIC_IRQChannel=TIM7_IRQn;
NVIC_InitStruct.NVIC_IRQChannelCmd=ENABLE;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority=0;
NVIC_InitStruct.NVIC_IRQChannelSubPriority=0;
NVIC_Init(&NVIC_InitStruct);
}
void TIM7_IRQHandler(void)
{
if(TIM_GetITStatus(TIM7,TIM_IT_Update)==SET)
{
GPIOB->ODR^=GPIO_Pin_5;
TIM_ClearITPendingBit(TIM7,TIM_FLAG_Update);
}
}
/*******************************************************************************************************************/
下面是报错
/*******************************************************************************************************************/
main.c(27): error: #268: declaration may not appear after executable statement in block
GPIO_InitTypeDef GPIO_InitStructure;
不知道为什么 求大神解释
|
|