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

📄 keypad.c

📁 < OSEKVDX汽车电子嵌入式软件编程技术>>配套光盘,搞汽车电子的赶快下:).
💻 C
字号:
/************************************************
*
*	$Copyright    2001 Joseph J. Lemieux  ALL RIGHTS RESERVED. $
*
*	$Filename: C:\OSEKBook\src\CH04\src\keypad.c $
*
*	Description: Keypad Sample and Control Routines	
*
************************************************/
#ifndef KEYPADC
#define KEYPADC

/************************************************
*
*	Include files
*
************************************************/

#include "typedefs.h"
#include "os.h"
#include "keypad.h"
#include "hw.h"

DeclareTask(ProcessKeyPress);

/************************************************
*
*	Local macros
*
************************************************/

/************************************************
*
*	Local type definitions
*
************************************************/

/************************************************
*
*	Local Function Prototypes
*
************************************************/

/************************************************
*
*	Local Variables
*
************************************************/

/************************************************
*
*	Global Variables
*
************************************************/
/***
*
* Value of Last Key Pressed and debounce timer
*
***/
char keyValue;
UINT8 keyCount=0;
char lastKey = 0;

/************************************************
*
*	Local Constants
*
************************************************/

/************************************************
*
*	Functions
*
************************************************/
/************************************************
*
*   Task:         IOSampleKeypad
*
*   Description:  Samples the keypad and debounces
*                 any keypresses.
*
************************************************/
TASK(IOSampleKeypad)
{
UINT32 delayTimer;
BOOLEAN keyState = FALSE;
char tempKey;

   while(1)
   {
      tempKey = HWGetValue(&KEYPAD);
      if(tempKey == lastKey)
      {
         if(keyCount++ == KEY_DEBOUNCE_TIME)
         {
            --keyCount;
            keyValue = tempKey;
         }
      }
      else
      {
         keyCount = 0;
         lastKey = tempKey;
      }
   	if(keyState==FALSE)
      {
         if(keyValue != 0)
         {
            keyState = TRUE;
            ActivateTask(ProcessKeyPress);
         }
      }
      else
      {
         if(keyValue == 0)
         {
            keyState = FALSE;
         }
      }
      for(delayTimer = 1000;delayTimer>0;delayTimer--)
      {
         Schedule();
      }
   }
}
#endif /* KEYPADC */

⌨️ 快捷键说明

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