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

📄 key_ht.c

📁 此为按键部分的,读取按键值是否有按键判断部分函数
💻 C
字号:


#include "INCLUDES.H"

/*
*********************************************************************************************************
*                                            GLOBAL VARIABLES
*********************************************************************************************************
*/
INT8U     KeyBuf[KEY_BUF_SIZE];     //键盘缓冲区
INT8U     KeyBufInIx;               //按键放入位置
INT8U     KeyBufOutIx;              //按键输出位置
//INT8U     KeyDownTmr;             //按键按下时间
INT8U     KeyNRead;                 //缓冲区中有按键的个数
INT8U     KeyScanState;             //按键状态函数
INT8U     KeyRptStartDlyCtr;        //累加延时时间
INT8U     KeyRptDlyCtr;
INT8U     ccode;
#if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
    OS_CPU_SR  cpu_sr;
#endif
/*
*********************************************************************************************************
*                                         FLUSH KEYBOARD BUFFER
*
* Description : This function clears the keyboard buffer
* Arguments   : none
* Returns     : none
*********************************************************************************************************
*/
void  KeyFlush (void)                 //清空按键
{
    while (KeyHit()) {                           /* While there are keys in the buffer...              */
        KeyGetKey();                            /* ... extract the next key from the buffer           */
    }
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                                 GET KEY
*
* Description : Get a keyboard scan code from the keyboard driver.
* Arguments   : 'to'     is the amount of time KeyGetKey() will wait (in number of ticks) for a key to be
*                        pressed.  A timeout of '0' means that the caller is willing to wait forever for
*                        a key to be pressed.
* Returns     : != 0xFF  is the key scan code of the key pressed
*               == 0xFF  indicates that there is no key in the buffer within the specified timeout
*********************************************************************************************************
*/
INT8U  KeyGetKey (void)                        //取按键函数
{
    INT8U ccode;
  	OS_ENTER_CRITICAL();                         /* Start of critical section of code, disable ints    */
    if (KeyNRead > 0) {                          //判断是否有按键
        KeyNRead--;                              //按键个数减1
        ccode = KeyBuf[KeyBufOutIx];             //取出1个按键
        KeyBufOutIx++;                           //输出按键位置加1 
        if (KeyBufOutIx >= KEY_BUF_SIZE) {       //判断指针是否到头 到头则返回
            KeyBufOutIx = 0;
        }
        OS_EXIT_CRITICAL();                      /* End of critical section of code                    */
        return (ccode);                          //返回按键值
    } else {
        OS_EXIT_CRITICAL();                      /* End of critical section of code                    */
        return (0xFF);                           //如果没有按键返回全高
    }
}
/*$PAGE*/
/*
*********************************************************************************************************
*                                        SEE IF ANY KEY IN BUFFER
*
* Description : This function checks to see if a key was pressed
* Arguments   : none
* Returns     : TRUE   if a key has been pressed
*               FALSE  if no key pressed
*********************************************************************************************************
*/
BOOLEAN  KeyHit (void)                             //有无按键判断函数
{
    BOOLEAN hit;
#if OS_CRITICAL_METHOD == 3                                /* Allocate storage for CPU status register */
    OS_CPU_SR  cpu_sr;
#endif

    OS_ENTER_CRITICAL();
    hit = (BOOLEAN)(KeyNRead > 0) ? TRUE : FALSE;
    OS_EXIT_CRITICAL();
    return (hit);
}
/*
*********************************************************************************************************
*                                       KEYBOARD INITIALIZATION
*
* Description: Keyboard initialization function.  KeyInit() must be called before calling any other of
*              the user accessible functions.
* Arguments  : none
* Returns    : none
*********************************************************************************************************
*/
void  KeyInit (void)                               //按键初始化
{
   
    KeyScanState = KEY_STATE_UP;                 /* Keyboard should not have a key pressed             */
    KeyNRead     = 0;                            /* Clear the number of keys read                      */
    //KeyDownTmr   = 0;
    KeyBufInIx   = 0;                            /* Key codes inserted at  the beginning of the buffer */
    KeyBufOutIx  = 0;                            /* Key codes removed from the beginning of the buffer */
  
}

/*
*********************************************************************************************************
*                                              READ COLUMNS
*
* Description : This function is called to read the column port.
* Arguments   : none
* Returns     : the complement of the column port thus, ones are keys pressed
*********************************************************************************************************
*/

⌨️ 快捷键说明

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