首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

stm32 按键

stm32 按键

//配置时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
//GPIO配置
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_5;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//main函数配置
void main(void)
{
  u8 ReadValue;
  RCC_Configuration();
  FLASH_Configuration();
  GPIO_Configuration();
  while(1)
  {
    ReadValue = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_8);
  if(0x00 == ReadValue)
  {
    delay_ms(10);
    if (0x00 == ReadValue)
    GPIO_SetBits(GPIOA,GPIO_Pin_15);
  }
  else
    GPIO_ResetBits(GPIOA,GPIO_Pin_15);
  }
}
返回列表