|
本帖最后由 enterpriseZ 于 2012-5-4 22:49 编辑
刚刚接触stm32f107不久,今天在学习它的外部中断模块时遇到一点问题,就是设置好中断之后,主程序在死循环里面等待,可是中断程序就是进不去啊!这到底是为什么啊?对着书上看了很久也看不明白啊,求帮助啊!……
PS:程序如下
#include "stm32f10x.h"
void Dis_Init ( void ) //显示LED的初始化,接在PD2上的
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd ( RCC_APB2Periph_GPIOD, ENABLE );
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init ( GPIOD, &GPIO_InitStructure );
}
void Interrupt_Init ( void )
{
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd ( RCC_APB2Periph_GPIOC, ENABLE ); //也试过其他的引脚,结果一样
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //浮空输入
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init ( GPIOC, &GPIO_InitStructure );
GPIO_EXTILineConfig ( GPIO_PortSourceGPIOC, GPIO_PinSource13 ); //选取PC13口作为中断的输入口
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 );
NVIC_PriorityGroupConfig ( NVIC_PriorityGroup_1 ); //分组方式选择第一组
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; //使能EXTI通道
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //先占优先级为0,即抢占优先级为0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //从优先级为0,即响应优先级为0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能
NVIC_Init ( &NVIC_InitStructure ); //初始化
}
void delay ( u32 count )
{
for ( ; count != 0; count -- );
}
int main ( void )
{
Dis_Init ();
Interrupt_Init ();
while (1)
{
//死循环
}
}
void EXTI15_10_IRQHandler ( void ) //中断处理函数
{
if ( EXTI_GetITStatus ( EXTI_Line13 ) != RESET )
{
EXTI_ClearFlag ( EXTI_Line13 );
EXTI_ClearITPendingBit ( EXTI_Line13 );
GPIO_SetBits ( GPIOD, GPIO_Pin_2 );
delay ( 0xeffffff );
GPIO_ResetBits ( GPIOD, GPIO_Pin_2 );
delay ( 0xeffffff );
}
}
|
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|