按键点亮LED灯(中断)

int main() //主程序
{
	Led_Init();//初始化
	Key_Init();
	
	while(1)
	{
		LED = 1;
		if(KEY == 0)
		{
			LED = 0;
		}
	}
}

void Led_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;//结构体声明
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);//使能APB2外设时钟
 
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;//选用管脚13
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//设置选中管脚的速率
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//设置选中管脚的工作状态推挽式输出
GPIO_Init(GPIOC, &GPIO_InitStructure);
}

void Key_Init (void)
{
GPIO_InitTypeDef GPIO_InitStructure;//结构体声明
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);//使能APB2外设时钟

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;//选用管脚9
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//设置选中管脚的速率
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;//设置选中管脚的工作状态为上拉式输入
GPIO_Init(GPIOB, &GPIO_InitStructure);
}



你可能感兴趣的:(按键点亮LED灯(中断))