以下是我的中断程序,可是为什在我没有触发中断(PA2)程序一下载时候二极管就亮了,在以后我把其他的全部注释了,只有GPIO的初始化的部分也没有给端口送数据,程序以一进去等还是亮的(都没有了中断服务程序了)。新手,请大家指教。
#include "stm32f10x.h"
#include "delay.h"
#include "sys.h"
int main()
{
GPIO_InitTypeDef GPIO_InitStruct;
EXTI_InitTypeDef EXTI_InitStruct;
NVIC_InitTypeDef NVIC_InitStruct;
delay_init(72);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
//GPIO_InitTypeDef GPIO_InitStruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_8;
GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_Init(GPIOA,&GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_2;
GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_IPD;
GPIO_Init(GPIOA,&GPIO_InitStruct);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource2);
EXTI_InitStruct.EXTI_Line=EXTI_Line2;
EXTI_InitStruct.EXTI_Mode=EXTI_Mode_Interrupt;
EXTI_InitStruct.EXTI_Trigger=EXTI_Trigger_Falling;
EXTI_InitStruct.EXTI_LineCmd=ENABLE;
EXTI_Init(&EXTI_InitStruct);
NVIC_InitStruct.NVIC_IRQChannel=EXTI2_IRQn;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority=0X02;
NVIC_InitStruct.NVIC_IRQChannelSubPriority=0X02;
NVIC_InitStruct.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStruct);
}
void EXTI2_IRQHandler(void)
{
if(!PAin(2))
{
delay_ms(5);
if(!PAin(2))
PAout(8)=0;
else
PAout(8)=1;
}
EXTI_ClearITPendingBit(EXTI_Line2);
}
|