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

📄 kbd.c

📁 Cirrus Logic EP7312处理器部分控制程序。
💻 C
字号:
//****************************************************************************
//
// KBD.C - Routines for reading the keys of the keyboard
//
// Copyright (c) 1998-1999 Cirrus Logic, Inc.
//
//****************************************************************************
#include "ep7312.h"
#include "lib7312.h"

//****************************************************************************
//
// KbdRead reads the entire keyboard array (of up to 64 keys) and sets each
// entry of the pcKeysPressed array based on whether or not the corresponding
// keyboard button is currently pressed.
//
//****************************************************************************
void
KbdRead(char *pcKeysPressed)
{
    unsigned char * volatile pucPtr = (unsigned char *)HwBaseAddress;
    unsigned char * volatile pucExtPtr =
        (unsigned char *)HwKeyboardExRowAddress;
    unsigned long * volatile pulHwControl;
    int iX, iY;
    unsigned char ucRowData, ucExtData;

    //
    // Get a pointer to the HwControl register, which contains the flags
    // controlling the column drive of the keyboard.
    //
    pulHwControl = (unsigned long *)(pucPtr + HwControl);

    //
    // In preparation for reading the keyboard array, stop driving the columns.
    //
    *pulHwControl = (*pulHwControl & ~HwControlColumnDrive) |
                    HwControlColumnAllLow;

    //
    // Loop through all 8 column of the keyboard.
    //
    for(iY = 0; iY < 8; iY++)
    {
        //
        // Drive column iY of the keyboard.
        //
        *pulHwControl = (*pulHwControl & ~HwControlColumnDrive) |
                        (HwControlColumn0High + iY);

        //
        // Read the keyboard row.
        //
        ucRowData = pucPtr[HwPortA];
        ucExtData = *pucExtPtr;

        //
        // Stop driving column iY.
        //
        *pulHwControl = (*pulHwControl & ~HwControlColumnDrive) |
                        HwControlColumnAllTriState;

        //
        // Look at each bit of the row which was read.
        //
        for(iX = 0; iX < 8; iX++)
        {
            //
            // See if this row is active.
            //
            if(ucRowData & (1 << iX))
            {
                //
                // This row is active, so the button corresponding to row iX
                // and column iY is currently pressed.
                //
                pcKeysPressed[(iY * 16) + iX] = 1;
            }
            else
            {
                //
                // This row is not active, so the button corresponding to row
                // iX and column iY is not currently pressed.
                //
                pcKeysPressed[(iY * 16) + iX] = 0;
            }

            //
            // See if this extended row is active.
            //
            if(ucExtData & (1 << iX))
            {
                //
                // This row is active, so the button corresponding to row iX
                // and column iY is currently pressed.
                //
                pcKeysPressed[(iY * 16) + iX + 8] = 1;
            }
            else
            {
                //
                // This row is not active, so the button corresponding to row
                // iX and column iY is not currently pressed.
                //
                pcKeysPressed[(iY * 16) + iX + 8] = 0;
            }
        }

        //
        // Wait just a tiny bit to make sure that the column drive has gone
        // completely low.
        //
        for(iX = 0; iX < 32 * 8; iX++)
        {
        }
    }

    //
    // Now that we're done reading the keyboard array, drive all 8 columns so
    // that future key presses will produce a keyboard interrupt (if so
    // configured).
    //
    *pulHwControl = (*pulHwControl & ~HwControlColumnDrive) |
                    HwControlColumnAllHigh;
}

//****************************************************************************
//
// KbdGetButton waits until a key is pressed on the keyboard and returns the
// key number of that key.
//
//****************************************************************************
char
KbdGetButton(void)
{
    char cBuffer[128], cIdx;

    //
    // Loop until a button has been pressed.
    //
    while(1)
    {
        //
        // Read the keyboard array.
        //
        KbdRead(cBuffer);

        //
        // See if any of the buttons are pressed.
        //
        for(cIdx = 0; cIdx < 128; cIdx++)
        {
            if(cBuffer[cIdx])
            {
                //
                // Return the button that is pressed.
                //
                return(cIdx);
            }
        }
    }
}

//****************************************************************************
//
// KbdNoButton waits until none of the keys are pressed on the keyboard.
//
//****************************************************************************
void
KbdNoButton(void)
{
    char cBuffer[128], cIdx;

    //
    // Loop until no button has been pressed.
    //
    while(1)
    {
        //
        // Read the keyboard array.
        //
        KbdRead(cBuffer);

        //
        // See if any of the buttons are pressed.
        //
        for(cIdx = 0; cIdx < 128; cIdx++)
        {
            if(cBuffer[cIdx])
            {
                //
                // A button is pressed, so stop looking for pressed buttons.
                //
                break;
            }
        }

        //
        // If no button is pressed, return.
        //
        if(cIdx == 128)
        {
            return;
        }
    }
}

⌨️ 快捷键说明

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