資源描述:
《STM32F4外部中斷EXTI》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、STM32F4外部中斷EXTI#include"stm32f4xx.h"#include"stm32f4xx_exti.h"#include"stm32f4xx_rcc.h"#include"stm32f4xx_gpio.h"#include"stm32f4xx_syscfg.h"voidmain(void){config();//初始化while(1);}voidconfig(void){//中斷IO口初始化RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,ENABLE);//RCC_APB2PeriphClockCmd(RCC
2、_APB2Periph_SYSCFG,ENABLE);GPIO_InitStructure.GPIO_Pin=GPIO_Pin_13;GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN;GPIO_InitStructure.GPIO_Speed=GPIO_Speed_100MHz;//GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_NOPULL;GPIO_Init(GPIOD,&GPIO_InitStructure);/
3、/中斷初始化EXTI_InitTypeDefEXTI_InitStructure;SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOD,EXTI_PinSource13);EXTI_ClearITPendingBit(EXTI_Line13);EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt;EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Rising_Falling;EXTI_InitStructure.EXTI_Line=EXTI_Line13
4、;EXTI_InitStructure.EXTI_LineCmd=ENABLE;EXTI_Init(&EXTI_InitStructure);//中斷配置初始化/*Configuresthenestedvectoredinterruptcontroller.*/NVIC_InitTypeDefNVIC_InitStructure;/*EnabletheUSARTxInterrupt*/NVIC_InitStructure.NVIC_IRQChannel=EXTI15_10_IRQn;NVIC_InitStructure.NVIC_IRQChannelPreemptio
5、nPriority=0;NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;NVIC_Init(&NVIC_InitStructure);}//中斷函數(shù)voidEXTI15_10_IRQHandler(void){if(EXTI_GetITStatus(EXTI_Line13)!=RESET){EXTI_ClearITPendingBit(EXTI_Line13);//清中斷}}