#include "key.h"
#include "led.h"
u8 led_stuta = 0;
void KEY_GPIO_init(void)//3õê¼»ˉ1ü½Å
{
/*********¶¨òåò»¸öGPIO_InitTypeDef ààDíμĽá11ìå**********/
GPIO_InitTypeDef GPIO_InitStructure;
/*********Ñ¡Ôñòa¿ØÖÆμÄGPIOxμÄòy½Å**********/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
/*********éèÖÃòy½ÅËùÂêÎa50MHZ**********/
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
/*********éèÖÃòy½ÅÄ£ê½Îaí¨óÃíÆíêêä3ö**********/
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
/*′ò¿aLEDê1óÃμÄGPIOμÄê±Öóê1Äü*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO,ENABLE);
/*3õê¼»ˉÏàó|μÄGPIO*/
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
void EXTI_init(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource6);
EXTI_InitStructure.EXTI_Line = EXTI_Line6;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
}
void NVIC_init(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void EXTI9_5_IRQHandler(void)
{
if(EXTI_GetFlagStatus(EXTI_Line6)!=RESET)
{
GPIO_SetBits(GPIOB, GPIO_Pin_8);
GPIO_SetBits(GPIOB, GPIO_Pin_9);
}
else
{
GPIO_ResetBits(GPIOB, GPIO_Pin_8);
GPIO_ResetBits(GPIOB, GPIO_Pin_9);
}
EXTI_ClearITPendingBit(EXTI_Line6);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>