大学生
最后登录1970-1-1
在线时间 小时
注册时间2013-11-14
|
写了个外部中断的代码,使用的是ISO-MINI-V2的按键KEY2,接的是PC13,下载的例程倒是能用,自己参照书上写的,几乎和例程一模一样,可一摁KEY2,就想死机了一样,程序卡着不走了,先贴代码给大家看看:
#include "exti.h"
void NVIC_Configuration()
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
//PC13
void exti_init()
{
GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource13);
EXTI_InitStructure.EXTI_Line = EXTI_Line13;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
}
void EXIT15_10_IRQHandler(void)
{
delay_ms(20);
if(EXTI_GetITStatus(EXTI_Line13) != RESET)
{
delay_ms(20);
if(GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_13) == 0)
{
GPIO_WriteBit(GPIOB, GPIO_Pin_0, (BitAction)(1-GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_0)));
}
EXTI_ClearITPendingBit(EXTI_Line13);
}
}
void init()
{
delay_init(72);
led_init();
exti_init();
NVIC_Configuration();
}
int main(void)
{
init();
__set_PRIMASK(0);
while(1)
{
GPIO_SetBits(GPIOB, GPIO_Pin_0);
delay_s(1);
GPIO_ResetBits(GPIOB, GPIO_Pin_0);
delay_s(1);
}
/* add your code here ^_^. */
}
调试的时候发现根本就没进中断,本来led在闪烁的只要一按按键,立马就停了,感觉就是程序卡在一个地方不走了,望大家帮忙找下原因。
|
|