欢迎来到天天文库
浏览记录
ID:47915354
大小:15.79 KB
页数:2页
时间:2019-10-25
《STM32F4外部中断EXTI》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
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);}//中断函数voidEXTI15_10_IRQHandler(void){if(EXTI_GetITStatus(EXTI_Line13)!=RESET){EXTI_ClearITPendingBit(EXTI_Line13);//清中断}}
此文档下载收益归作者所有