按键点亮LED灯(中断)

匿名 (未验证) 提交于 2019-12-03 00:21:02
#include <sys.h> #include <EXTI.h> #include <led.h> int main(void) { 	NVIC_Configuration(); 	Led_init(); 	EXTI_KEY_init(); 	 	while(1) 	{ 	 	} } void EXTI15_10_IRQHandler(void)  { 	if(EXTI_GetFlagStatus(EXTI_Line10)==1) 	{ 		LED=0; 	  EXTI_ClearFlag(EXTI_Line10); 	} 	if(EXTI_GetFlagStatus(EXTI_Line11)==1) 	{ 		LED=1; 	  EXTI_ClearFlag(EXTI_Line11); 	}  } 
#include <EXTI.h>  void EXTI_KEY_init(void) { 	GPIO_InitTypeDef GPIO_InitStructure; 	EXTI_InitTypeDef EXTI_InitStructure; 	NVIC_InitTypeDef NVIC_InitStructure; //配置PB11、PB11为下降沿触发	 	 //配置管脚时钟和复用时钟	 	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO,ENABLE); //配置GPIO口为上拉输入 	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_10; 	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; 	GPIO_Init(GPIOB, &GPIO_InitStructure); 	 //配置GPIO口为	外部中断模式 	GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource11); 	GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource10); 	 //配置EXTI中断触发模式	 	 	EXTI_InitStructure.EXTI_Line = EXTI_Line11; 	EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; 	EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; 	EXTI_InitStructure.EXTI_LineCmd = ENABLE; 	EXTI_Init(&EXTI_InitStructure); 	 	EXTI_InitStructure.EXTI_Line = EXTI_Line10; 	EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; 	EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; 	EXTI_InitStructure.EXTI_LineCmd = ENABLE; 	EXTI_Init(&EXTI_InitStructure); //配置EXTI的中断优先级 	NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; 	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; 	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; 	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; 	NVIC_Init(&NVIC_InitStructure);  } 

#include <led.h> //PC13  void Led_init(void) { 	GPIO_InitTypeDef GPIO_InitStructure; 	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE); 	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; 	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 	GPIO_Init(GPIOC, &GPIO_InitStructure); } 



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!