📄 keypad.c
字号:
/************************************************
*
* $Copyright 2001 Joseph J. Lemieux ALL RIGHTS RESERVED. $
*
* $Filename: C:\OSEKBook\src\CH09\src\keypad.c $
*
* Description: Keypad Sample and Control Routines
*
************************************************/
#ifndef KEYPADC
#define KEYPADC
/************************************************
*
* Include files
*
************************************************/
#include "typedefs.h"
#include "os.h"
#include "register.h"
#include "mpc555.h"
#include "init.h"
#include "hw.h"
#include "keypad.h"
DeclareTask(ProcessKeyPress);
/************************************************
*
* Local macros
*
************************************************/
/************************************************
*
* Local type definitions
*
************************************************/
/************************************************
*
* Local Function Prototypes
*
************************************************/
ISR(IOReadKeypadISR);
/************************************************
*
* Local Variables
*
************************************************/
/*
* Define buffer of keys pressed
*/
char keyBuffer[KEY_BUFFER_SIZE];
char * keyBufferStart=keyBuffer;
char * keyBufferEnd=keyBuffer;
/*
* Variables used to debounce keys
*/
UINT8 keyCount=0;
char lastKey = 0;
/************************************************
*
* Global Variables
*
************************************************/
/************************************************
*
* Local Constants
*
************************************************/
/************************************************
*
* Functions
*
************************************************/
/************************************************
*
* Function: InitKeypad
*
* Inputs: type - type of initialization occurring.
*
* Outputs: none
*
* Returns: void
*
* Description: Initialize the Keypad module
*
************************************************/
void InitKeypad(InitType type)
{
Set_ExtISR((ULONG *)IOReadKeypadISR,V_IRQ4);
}
/************************************************
*
* ISR: IOReadKeypadISR
*
* Description: Handles the ISR whenever a key is
* pressed on the keypad.
*
************************************************/
ISR(IOReadKeypadISR)
{
char tempKey;
usiuReg.sipend = 0x00800000; /* Clear Interrupt Bit */
tempKey = HWGetValue(&KEYPAD);
if(tempKey != 0){
*keyBufferEnd = tempKey;
if((++keyBufferEnd) == keyBuffer + KEY_BUFFER_SIZE){
keyBufferEnd = keyBuffer;
}
SetEvent(ProcessKeyPress,KEYPRESS);
}
}
/************************************************
*
* Function: GetKeyValue
*
* Inputs: none
*
* Outputs: none
*
* Returns: Character pressed.
*
* Description: This routine pulls the oldest character from
* the buffer of key presses from the keypad.
*
************************************************/
char GetKeyValue(void)
{
char keyValue = 0;
if(keyBufferStart != keyBufferEnd){
keyValue = *keyBufferStart;
if((++keyBufferStart) == keyBuffer + KEY_BUFFER_SIZE){
keyBufferStart = keyBuffer;
}
}
return keyValue;
}
#endif /* KEYPADC */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -