zoukankan      html  css  js  c++  java
  • 嵌入式系统按键实现(按下按钮,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--);
    }

  • 相关阅读:
    收藏随笔
    Jquery根据元素ID判断该元素是否存在
    DIV+CSS布局中IE与FF浏览器之间重要的兼容性差异
    css3 boxsizing属性
    常见CSS属性及值
    Pycharm学习记录注释
    python之reload用法
    python之sorted用法
    android studio目录结构浅析
    纪念开通博客
  • 原文地址:https://www.cnblogs.com/lls1350767625/p/8007445.html
Copyright © 2011-2022 走看看