⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 key.c

📁 基于ST750的串口程序-MDK,基于ST750的串口程序-MDK!
💻 C
字号:
#include "Key.h"
#include "75x_lib.h"
void Key_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  /* GPIO Configuration --------------------------------------------------------*/
  /* Configure P1.07,P1.08,P1.09  as input push-up */
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;
  GPIO_Init(GPIO1, &GPIO_InitStructure);

  /* Configure P2.06,P2.08 as input push-up */
  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_6 | GPIO_Pin_8;
  GPIO_Init(GPIO2, &GPIO_InitStructure);

}

u8 Key_GetAll(void)
{
  u8 temp = 0;

  if(!GPIO_ReadBit(GPIO1, GPIO_Pin_9))
  {
    temp |= K3;
  }
  if(!GPIO_ReadBit(GPIO2, GPIO_Pin_8))
  {
    temp |= K4;
  }
  if(!GPIO_ReadBit(GPIO2, GPIO_Pin_6))
  {
    temp |= K5;
  }
  if(!GPIO_ReadBit(GPIO1, GPIO_Pin_8))
  {
    temp |= K6;
  }
  if(!GPIO_ReadBit(GPIO1, GPIO_Pin_7))
  {
    temp |= K7;
  }
  return temp;
}


/*******************************************************************************
* Function Name  : ReadKey
* Description    : Reads key from demoboard.
* Input          : None
* Output         : None
* Return         : Return K3, K4, K5, K6, K7 or NOKEY
*******************************************************************************/
u8 ReadKey(void)
{
  /* "K3" key is pressed,P1.09 */
  if(!GPIO_ReadBit(GPIO1, GPIO_Pin_9))
  {
    while(GPIO_ReadBit(GPIO1,GPIO_Pin_9) == Bit_RESET);
    return K3;
  }
  /* "K4" key is pressed,P2.08 */
  if(!GPIO_ReadBit(GPIO2, GPIO_Pin_8))
  {
    while(GPIO_ReadBit(GPIO2, GPIO_Pin_8) == Bit_RESET);
    return K4;
  }
  /* "K5" key is pressed,P2.06 */
  if(!GPIO_ReadBit(GPIO2, GPIO_Pin_6))
  {
    while(GPIO_ReadBit(GPIO2, GPIO_Pin_6) == Bit_RESET);
    return K5;
  }
  /* "K6" key is pressed,P1.08 */
  if(!GPIO_ReadBit(GPIO1, GPIO_Pin_8))
  {
    while(GPIO_ReadBit(GPIO1, GPIO_Pin_8) == Bit_RESET);
    return K6;
  }
  /* "K7" key is pressed,1.07 */
  if(!GPIO_ReadBit(GPIO1, GPIO_Pin_7))
  {
    while(GPIO_ReadBit(GPIO1, GPIO_Pin_7) == Bit_RESET);
    return K7;
  }
  /* No key is pressed */
  else
  {
    return NOKEY;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -