初中生
最后登录1970-1-1
在线时间 小时
注册时间2018-1-26
|
这是F429EXTI的程序,写完后烧进去,绿灯和红灯都亮,但是只有KEY1能够进行外部中断,KEY2没反应,求帮忙看看哪里写错了。
/****按键配置****/
void GPIO_KEY_config(void)
{
GPIO_InitTypeDef GPIO_initstruct;
/**配置GPIOA的时钟**/
RCC_AHB1PeriphClockCmd(KEY1_GPIO_CLK,ENABLE);
RCC_AHB1PeriphClockCmd(KEY2_GPIO_CLK,ENABLE);
/**设置GPIO的模式**/
GPIO_initstruct.GPIO_Mode = GPIO_Mode_IN;
GPIO_initstruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
/**配置要的引脚**/
GPIO_initstruct.GPIO_Pin = KEY1_GPIO ;
/**把所需要的配置写入GPIOA的相应位**/
GPIO_Init(KEY1_GPIO_PORT , &GPIO_initstruct);
GPIO_initstruct.GPIO_Pin = KEY2_GPIO ;
GPIO_Init(KEY2_GPIO_PORT , &GPIO_initstruct);
}
/*******led配置*****/
void GPIO_LED_config(void)
{
GPIO_InitTypeDef GPIO_initstruct;
/**配置GPIOH的时钟**/
RCC_AHB1PeriphClockCmd(LED_CLK,ENABLE);
/**设置GPIO的输出模式**/
GPIO_initstruct.GPIO_Mode = GPIO_Mode_OUT;
GPIO_initstruct.GPIO_Speed = GPIO_Fast_Speed;
GPIO_initstruct.GPIO_OType = GPIO_OType_PP;
GPIO_initstruct.GPIO_PuPd = GPIO_PuPd_UP;
/**配置要点亮的引脚**/
GPIO_initstruct.GPIO_Pin = LED_R ;
/**把所需要的配置写入GPIOH的相应位**/
GPIO_Init(LED_R_PORT, &GPIO_initstruct);
GPIO_initstruct.GPIO_Pin = LED_G ;
GPIO_Init(LED_G_PORT, &GPIO_initstruct);
//
// GPIO_initstruct.GPIO_Pin = LED_B ;
// GPIO_Init(LED_B_PORT, &GPIO_initstruct);
}
/******外部中断配置*****/
void EXTI_config(void)
{
EXTI_InitTypeDef EXTI_typestruct;
NVIC_InitTypeDef NVIC_typesstruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG,ENABLE);
NVIC_PriorityGroupConfig( NVIC_PriorityGroup_0);
NVIC_typesstruct.NVIC_IRQChannel=EXTI0_IRQn;
NVIC_typesstruct.NVIC_IRQChannelPreemptionPriority=0;
NVIC_typesstruct.NVIC_IRQChannelSubPriority=1;
NVIC_typesstruct.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_typesstruct);
NVIC_typesstruct.NVIC_IRQChannel=EXTI15_10_IRQn;
NVIC_typesstruct.NVIC_IRQChannelPreemptionPriority=0;
NVIC_typesstruct.NVIC_IRQChannelSubPriority=2;
NVIC_typesstruct.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_typesstruct);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);
EXTI_typestruct.EXTI_Line=EXTI_Line0;
EXTI_typestruct.EXTI_Mode=EXTI_Mode_Interrupt;
EXTI_typestruct.EXTI_Trigger=EXTI_Trigger_Rising;
EXTI_typestruct.EXTI_LineCmd=ENABLE;
EXTI_Init(&EXTI_typestruct);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC, EXTI_PinSource13);
EXTI_typestruct.EXTI_Line=EXTI_Line13;
EXTI_typestruct.EXTI_Mode=EXTI_Mode_Interrupt;
EXTI_typestruct.EXTI_Trigger=EXTI_Trigger_Rising;
EXTI_typestruct.EXTI_LineCmd=ENABLE;
EXTI_Init(&EXTI_typestruct);
}
/******主函数*****/
int main(void)
{
GPIO_LED_config();
GPIO_KEY_config();
EXTI_config();
while(1);
}
/********中断函数*******/
void EXTI0_IRQHandler (void)
{
if(EXTI_GetITStatus(EXTI_Line0!=RESET))
{
GPIO_LEDR_TOOGLE;
}
EXTI_ClearITPendingBit(EXTI_Line0);
}
void EXTI15_10_IRQHandler (void)
{
if(EXTI_GetITStatus(EXTI_Line13!=RESET))
{
GPIO_LEDG_TOOGLE;
}
EXTI_ClearITPendingBit(EXTI_Line13);
}
PS:软件编译没有报错。。。。。。
|
|