?? keybd.c
字號:
/*
* $Id: keybd.c,v 1.2 2003/08/29 03:13:16 casic Exp $
*
* keybd.c : keyboard driver
*
* Copyright (C) 2003 ynding ( haoanian@263.net )
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "ep7312.h"
#include "keybd.h"
#include "wait.h"
/* define the meaning of each key on the keyboard */
static char key[ROW][COL] = {
{'1','2','3','a'},
{'4','5','6','b'},
{'7','8','9','c'},
{'*','0','#','d'}
};
/* initialize keyboard */
void init_keybd(void)
{
rPADDR |= 0x00;
rSYSCON2 |= 0x00000008;
rSYSCON1 |= 0x00000008;
return;
}
/*
* keyboard scan, capture key pressed
* block : block or non-block
*/
char keyscan()
{
unsigned long pa_value; /* store the value read from the PA port */
unsigned long column = 0x000000008; /* write the value of column to SYSCON1,
the initial value 0x8 will cause the
voltage of col0 to high */
char keyvalue = 'x'; /* while keyvalue == 'x', means that no key is pressed */
int col = 0;
/* will loop until there is a key pressed */
/* initial the variables before each loop of keyboard scan */
keyvalue = 'x';
column = 0x00000008;
/* this for loop execute a single loop for keyboard scanning,
from col0 to col3:
firstly, set col0 to high, others to low ,
then, set col1 to high, others to low, and so on */
for ( col=0;col<4;++col ) {
int row = 0;
rSYSCON1 &= ~0x0000000f;
rSYSCON1 |= column;
wait(20);
rPADDR |= 0x00; /* set PA port as input */
pa_value = rPADR;/* read data from PA port */
pa_value &= 0xf;/* take out the value useful to us */
if ( pa_value != 0 ){wait(50);
}
pa_value = rPADR;/* read data from PA port */
pa_value &= 0xf;/* take out the value useful to us */
if ( pa_value != 0 ) { /* means there is a key pressed */
/* this for loop determines which key is pressed */
for ( row=0;row<4;++row ) {
if ( (pa_value >> row) & 0x1 ) {
keyvalue = key[row][col];
break;
}
}
}
if ( keyvalue != 'x' )
break;
++column;
}
wait(100);
return keyvalue;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -