您的位置 首页 新能源

【STM32 Cotex-M3处理器系列编程】外部按键中止

includestm32f10xhunsignedintTimingDelay;voidDelay(unsignedintx){TimingDelay=x;while(TimingDelay–);}

#include “stm32f10x.h”

unsigned int TimingDelay;
void Delay(unsigned int x)
{
TimingDelay=x;
while(TimingDelay–);
}
void EXTI9_5_IRQHandler(void) //中止处理函数
{
unsigned int tt;
tt=6553500;
if(EXTI_GetITStatus(EXTI_Line5)!=RESET)
{
GPIO_SetBits(GPIOC, GPIO_Pin_7);
while(tt–);
GPIO_ResetBits(GPIOC, GPIO_Pin_7);
while(tt–);
EXTI_ClearFlag(EXTI_Line5);//铲除中止标志
EXTI_ClearITPendingBit(EXTI_Line5);//铲除EXTI线路挂起位
}
}
int main(void)
{
//装备IO口
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE,ENABLE);//IO口使能设置
GPIO_InitTypeDef GPIO_InitStructure; //界说结构体
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //设置为上拉输入
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOE, &GPIO_InitStructure);
//装备外部中止控制器
EXTI_InitTypeDef EXTI_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);//使能时钟
EXTI_InitStructure.EXTI_Line = EXTI_Line5; //运用IO口5作为中止口
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //设置EXTI线路为中止请求
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //下降沿触发
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOE,GPIO_PinSource5);//将PE5挂接到EXTI9_5_IRQn中止源上
//装备中止控制器
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); //挑选中止组0
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; //指定中止源,0-4管脚归于EXTI0_IRQn~EXTI4_IRQn,5-9管脚归于EXTI9_5_IRQn,10-15管脚归于EXTI15_10_IRQn
//NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;//无先占优先级,从优先级为1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
while(1);
}
//以下是报错函数
#ifdef USE_FULL_ASSERT
void assert_failed(uint8_t* file, uint32_t line)
{
while (1)
{
}
}
#endif

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/qiche/xinnengyuan/257089.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部