#include "stm32f10x.h"
#include "delay.h"
#define LED0_ON() GPIO_ResetBits(GPIOB,GPIO_Pin_5)
#define LED0_OFF() GPIO_SetBits(GPIOB,GPIO_Pin_5)
#define LED1_ON() GPIO_ResetBits(GPIOB,GPIO_Pin_15)
#define LED1_OFF() GPIO_SetBits(GPIOB,GPIO_Pin_15)
void GPIO_Config(void);
void NVIC_Config(void);
void EXTI_Config(void);
void EXTI2_IRQHandler(void);
void EXTI3_IRQHandler(void);
u8 i = 0;
int main(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
delay_init(72); //初始化时钟
GPIO_Config();
NVIC_Config();
EXTI_Config();
EXTI2_IRQHandler();
EXTI3_IRQHandler();
LED0_OFF();
LED1_OFF();
while(1)
{
}
}
void GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_Initstruction;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOE,ENABLE);
/* LED0 LED1*/
GPIO_Initstruction.GPIO_Pin=GPIO_Pin_5|GPIO_Pin_15;
GPIO_Initstruction.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_Initstruction.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_Initstruction);
/* KEY2 KEY3 */
GPIO_Initstruction.GPIO_Pin=GPIO_Pin_2|GPIO_Pin_3;
GPIO_Initstruction.GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_Initstruction.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOE, &GPIO_Initstruction);
}
void NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStruction;
NVIC_InitStruction.NVIC_IRQChannel=EXTI2_IRQn;
NVIC_InitStruction.NVIC_IRQChannelPreemptionPriority=0x01;
NVIC_InitStruction.NVIC_IRQChannelSubPriority=0x01;
NVIC_InitStruction.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStruction);
NVIC_InitStruction.NVIC_IRQChannel=EXTI3_IRQn;
NVIC_InitStruction.NVIC_IRQChannelPreemptionPriority=0x01;
NVIC_InitStruction.NVIC_IRQChannelSubPriority=0x03;
NVIC_InitStruction.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStruction);
}
void EXTI_Config(void)
{
EXTI_InitTypeDef EXTI_InitStruction;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource2);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource3);
EXTI_InitStruction.EXTI_Line=EXTI_Line2;
EXTI_InitStruction.EXTI_Mode=EXTI_Mode_Interrupt;
EXTI_InitStruction.EXTI_Trigger=EXTI_Trigger_Falling;
EXTI_InitStruction.EXTI_LineCmd=ENABLE;
EXTI_Init(&EXTI_InitStruction);
EXTI_InitStruction.EXTI_Line=EXTI_Line3;
EXTI_InitStruction.EXTI_Mode=EXTI_Mode_Interrupt;
EXTI_InitStruction.EXTI_Trigger=EXTI_Trigger_Falling;
EXTI_InitStruction.EXTI_LineCmd=ENABLE;
EXTI_Init(&EXTI_InitStruction);
}
void EXTI2_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line2)!= RESET)
{
for(i=0;i<10;i++)
{
LED0_ON();
delay_ms(500);
LED0_OFF();
delay_ms(500);
}
}
EXTI_ClearITPendingBit(EXTI_Line2);
}
void EXTI3_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line3)!= RESET)
{
for(i=0;i<10;i++)
{
LED1_ON();
delay_ms(1000);
LED1_OFF();
delay_ms(1000);
}
}
EXTI_ClearITPendingBit(EXTI_Line3);
}
配置没问题,是不是还缺少东西,怎么优先级就是实现不了
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>