[开发板] CW32F030CxTx--按键

[复制链接]
497|2
 楼主| 51xlf 发表于 2022-8-26 13:14 | 显示全部楼层 |阅读模式
板子上自带的按键是PA1和PA2
初始化按键为输入
  1.     GPIO_InitStruct.Pins = GPIO_PIN_1 | GPIO_PIN_2;
  2.     GPIO_InitStruct.Mode = GPIO_MODE_INPUT_PULLUP;
  3.     GPIO_InitStruct.IT   = GPIO_IT_NONE;
  4.     GPIO_Init( CW_GPIOA , &GPIO_InitStruct);
同时初始化PB8和PB9为输出
  1. #define LED_GPIO_PORT CW_GPIOB
  2. __RCC_GPIOB_CLK_ENABLE();

  3.     GPIO_InitStruct.IT = GPIO_IT_NONE;
  4.     GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  5.     GPIO_InitStruct.Pins = LED_GPIO_PINS;
  6.     GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;

  7.     GPIO_Init(LED_GPIO_PORT, &GPIO_InitStruct);
以下调用函数法读写PIN
  1.      if( GPIO_ReadPin(CW_GPIOA , GPIO_PIN_1 ) )

操作代码
  1.   if( GPIO_ReadPin(CW_GPIOA , GPIO_PIN_1 ) )
  2.         {Delay(0xFF);
  3.             GPIO_WritePin( CW_GPIOB, GPIO_PIN_8|GPIO_PIN_9 , GPIO_Pin_SET );
  4.         }
  5.         else
  6.         {Delay(0xFF);
  7.             GPIO_WritePin( CW_GPIOB, GPIO_PIN_8|GPIO_PIN_9 , GPIO_Pin_RESET );
  8.         }
  9.         




您需要登录后才可以回帖 登录 | 注册

本版积分规则

551

主题

9967

帖子

24

粉丝
快速回复 在线客服 返回列表 返回顶部