嵌入式系統按鍵實現(按下按鈕,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--);
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM