#include "exit.h"
#include "stm32f10x.h"
#include "delay.h"
#include "led.h"
#include "beep.h"
void Exit_Init(void)
{
GPIO_InitTypeDef Keystruct;
EXTI_InitTypeDef Exitstruct;
NVIC_InitTypeDef NVICstruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
Keystruct.GPIO_Mode=GPIO_Mode_IPU;
Keystruct.GPIO_Pin=GPIO_Pin_3|GPIO_Pin_4;
Keystruct.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOE,&Keystruct);
GPIO_SetBits(GPIOE,GPIO_Pin_4|GPIO_Pin_3);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOE,GPIO_PinSource4);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOE,GPIO_PinSource3);
Exitstruct.EXTI_Line=EXTI_Line3;
Exitstruct.EXTI_Line=EXTI_Line4;
Exitstruct.EXTI_LineCmd=ENABLE;
Exitstruct.EXTI_Mode=EXTI_Mode_Interrupt;
Exitstruct.EXTI_Trigger=EXTI_Trigger_Falling;
EXTI_Init(&Exitstruct);
NVICstruct.NVIC_IRQChannel=EXTI3_IRQn;
NVICstruct.NVIC_IRQChannelCmd=ENABLE;
NVICstruct.NVIC_IRQChannelPreemptionPriority=2;
NVICstruct.NVIC_IRQChannelSubPriority=2;
NVIC_Init(&NVICstruct);
NVICstruct.NVIC_IRQChannel=EXTI4_IRQn;
NVICstruct.NVIC_IRQChannelCmd=ENABLE;
NVICstruct.NVIC_IRQChannelPreemptionPriority=2;
NVICstruct.NVIC_IRQChannelSubPriority=2;
NVIC_Init(&NVICstruct);
}
void EXTI3_IRQHandler(void)
{
delay_ms(10);
if(KEY0==0)
{
LED0=!LED0;
LED1=!LED1;
}
EXTI_ClearITPendingBit(EXTI_Line3);
}
void EXTI4_IRQHandler(void)
{
delay_ms(10);
if(KEY1==0)
{
BEEP=!BEEP;
}
EXTI_ClearITPendingBit(EXTI_Line4);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>