码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-12-09 00:01:27      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:struct   mod   UI   on()   led灯   for   mode   delay   else   

#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灯熄灭)

标签:struct   mod   UI   on()   led灯   for   mode   delay   else   

原文地址:http://www.cnblogs.com/lls1350767625/p/8007445.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!