?? keypad.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 + -