在线时间0 小时
UID418028
ST金币0
蝴蝶豆0
注册时间2007-8-18
新手上路
- 最后登录
- 1970-1-1
|
a0a.1 0b0c
#include "stm32f10x.h"
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
void LED_Init(void)
{
/* GPIOD Periph clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
/* Configure PD6 and PD13 in output pushpull mode */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_13;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/*GPIOC Periph clock enable*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7; //choose gpio pin
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; //set gpio speed
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //set gpio mode
GPIO_Init(GPIOC, &GPIO_InitStructure); //initial gpio port
}
void GPIO_EXTIConfigration(void)
{
//GPIOE Periph clock enable
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
//set pe2 pe3 pe4 pe5 input mode
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5;
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOE, &GPIO_InitStructure); //initial gpio port
/* ENABLE AFIO CLOCK */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
/* connect gpio to exti */
GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource2);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource3);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource4);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource5);
// config EXTI initial
EXTI_InitStructure.EXTI_Line = EXTI_Line2|EXTI_Line3|EXTI_Line4|EXTI_Line5;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
}
void NVIC_Configration(void)
{
NVIC_SetVectorTable(NVIC_VectTab_FLASH,0x0); //system default NVIC VECTTAB TO FLASH, so needn't
NVIC_InitStructure.NVIC_IRQChannel = EXTI2_IRQn|EXTI3_IRQn|EXTI4_IRQn|EXTI9_5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0f ;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0f;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void main()
{
LED_Init();
GPIO_EXTIConfigration();
NVIC_Configration();
while(1)
{
;
}
}
中断子程序:
/*
*
*
*
*
*/
void EXTI2_IRQHandler(void)
{
if( (EXTI_GetITStatus(EXTI_Line2))!=0 )
{
GPIOD->BSRR = 0x00000040;
EXTI_ClearITPendingBit(EXTI_Line2);
}
}
/*
*
*
*
*
*/
void EXTI3_IRQHandler(void)
{
if( (EXTI_GetITStatus(EXTI_Line3))!=0 )
{
GPIOD->BSRR = 0x00002000;
EXTI_ClearITPendingBit(EXTI_Line3);
}
}
/*
*
*
*
*
*/
void EXTI4_IRQHandler(void)
{
if( (EXTI_GetITStatus(EXTI_Line4))!=0 )
{
GPIOC->BSRR = 0x00000080;
EXTI_ClearITPendingBit(EXTI_Line4);
}
}
/*
*
*
*
*
*/
void EXTI9_5_IRQHandler(void)
{
if( (EXTI_GetITStatus(EXTI_Line5))!=0 )
{
GPIOC->BSRR = 0x00000040;
EXTI_ClearITPendingBit(EXTI_Line5);
}
}
利用开发板仿真的时候可以看到对应的peng = 1,却进不了中断程序,请前辈帮忙指点
|
|