嵌入式系统按键实现(按下按钮,LED灯熄灭)

Posted 随心佩

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了嵌入式系统按键实现(按下按钮,LED灯熄灭)相关的知识,希望对你有一定的参考价值。

#include"stm32f10x.h"
#include<stdio.h>
#include<string.h>

void GPIO_Cofiguration(void);
void Delay(uint32_t nCount);

int main(void)
{
 uint8_t Key;
 GPIO_Cofiguration();
 
 while(1){
  if(!(GPIOG->IDR&0x0040)){
   GPIO_ResetBits(GPIOF,GPIO_Pin_6);
   GPIO_ResetBits(GPIOF,GPIO_Pin_7);
   GPIO_ResetBits(GPIOF,GPIO_Pin_8);
   GPIO_ResetBits(GPIOF,GPIO_Pin_9);
   Delay(0x1fffff);
  }
  else{
   GPIO_SetBits(GPIOF,GPIO_Pin_6);
   GPIO_SetBits(GPIOF,GPIO_Pin_7);
   GPIO_SetBits(GPIOF,GPIO_Pin_8);
   GPIO_SetBits(GPIOF,GPIO_Pin_9);
   Delay(0x1fffff); 
  }
 }
}
void GPIO_Cofiguration(void){
 GPIO_InitTypeDef GPIO_InitStructure;
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOF|RCC_APB2Periph_GPIOG,ENABLE);
 GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9;
 GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
 GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
 GPIO_Init(GPIOF,&GPIO_InitStructure);
 
  GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6;
 GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
 GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;
 GPIO_Init(GPIOG,&GPIO_InitStructure);
}
void Delay(uint32_t nCount){
 for(;nCount !=0;nCount--);
}

以上是关于嵌入式系统按键实现(按下按钮,LED灯熄灭)的主要内容,如果未能解决你的问题,请参考以下文章

嵌入式流水灯程序

arduino按钮控制灯

arduinoled灯按一下显示应该花样代码

arduino蓝牙控制呼吸灯无法熄灭的问题

嵌入式GPIO初始化

ESP327.按键实验(中断)