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

📄 keypad.c

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

//****************************************************************************
//
// UserButtonRead reads the User Button array and sets each
// entry of the pcButtonsPressed array based on whether or not the corresponding
// User button is currently pressed.
//
//****************************************************************************
void
KPRead(char *pcButtonsPressed)
{
    unsigned char * volatile pucPtr = (unsigned char *)HwBaseAddress;
    unsigned long * volatile pulHwControl;
    int iX;
    unsigned char ucRowData;

    //
    // Get a pointer to the SysCon 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;

    //
    // Wait just a tiny bit to make sure that the columns go completely low
    //
    for(iX = 0; iX < 32 * 8; iX++)
    {
    }

    //
    // Drive column 5 of the keyboard.
    //
    *pulHwControl = (*pulHwControl & ~HwControlColumnDrive) |
                        (HwControlColumn0High + 5);

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

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

    //
    // Look at bits 0-5.
    //
    for(iX = 0; iX < 6; iX++)
    {
        //
        // See if this Button was pushed.
        //
        if(ucRowData & (1 << iX))
        {
            //
            // This button was pushed, so set the array location to 1.
            //
            pcButtonsPressed[iX] = 1;
        }
        else
        {
            //
            // This button was not pushed, so set the array location to 0.
            //
            pcButtonsPressed[iX] = 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;
}

//****************************************************************************
//
// KPGetUserButton waits until a User Button is pressed on the keypad and 
// returns the number of that User Button.
//
//****************************************************************************
char
KPGetUserButton(void)
{
    char cBuffer[6], cIdx;

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

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

//****************************************************************************
//
// KPNoButton waits until none of the User Button are pressed on the keypad.
//
//****************************************************************************
void
KPNoButton(void)
{
    char cBuffer[6], cIdx;

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

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

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

⌨️ 快捷键说明

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