Site Map

Recently Updated

Skip to end of metadata
Go to start of metadata

The Keyboard

Ok, from memory, here is how the keyboard works (sorry if I'm telling
you what you already know):

As you know, the Alpha, Shift and ON keys have their own I/O pins.
Thus they are easy to read directly.

The rest of the keys are on their own matrix, which is the pretty
standard way to do things. They are hooked up to port G (which has 16
pins). The matrix is configured wo there is a 'row' part, and a
'column' part. Pressing a key joins the corrosponding row line to the
column line.

The upper 8 port G pins control the column select, and the lower pins
control the row data. The row data pins are configured as inputs, with
pull-up resistors enabled. The idea is that if nothing is connected to
the input, it will read '1'.

By default, all row select lines are all grounded. This basically
means that if no key is pressed, the row data pins will read

1111 1111

In this case, If a key is pressed, the column line (which is
grounded) is connected to the row line. Hence the row reads 0.

The following data shows what is read from port G when a key is
pressed, starting from the HIST row and working downwards:

FD - 1111 1101 - '
FB - 1111 1011 - SIN
F7 - 1111 0111 - X
EF - 1110 1111 - 8
DF - 1101 1111 - 5
BF - 1011 1111 - 2
7F - 0111 1111 - .

So this method works fine for detecting what row a key is on. But, you
also need to know the column. So what you do is make all the column
select pins inputs (so they are effectivly disconnected), except you
ground the column select pin for the column you wish to test.

Suppose you ground column select pin 2, and leave the rest floating
(AKA inputs).

No key pressed:

1111 1111 %3c-- row data all ones, as they are unless connected to ground

key pressed on column 3, row 0

1111 1111 %3c- row data all 1's, since column 3 is connected to row 0,
and column 3 is floating (you grounded column 2, remember)

key pressed on column 2, row 4

1110 1111 %3c-- row data all 1's except for row 4 - since column 2 is
connected to row 4. Column 2 is grounded, dragging row 4 to 0

Now, let look at the is[Main:KeyPressed]() function

int keyb_is[Main:KeyPressed](unsigned char col, unsigned char row)
{//returns 1 if the key at logical column 'col', logical row 'row', is pressed//0 otherwise.
unsigned int volatile * GPGDAT = (int*) 0x7A00064; //dataunsigned int volatile * GPGCON = (int*) 0x7A00060; //controlint volatile i=0;int keyPress = 0;
if (!keyb_isAnyKeyPressed())

Unknown macro: {return 0; //bail out right away if no key is pressed}

unsigned int control = 1%3c%3c((col+8)*2); //set the correct col pin tooutput, others inputscontrol = control | 0xAAA9; //fix up the lower bits*GPGCON = control; // write the new control value.
//wait a little while to take effect. Delay valid for slow modefor (i=0;i%3c100;i++){}

keyPress = !( ( (*GPGDAT) >> (row+1) ) &1);

*GPGCON = 0x5555AAA9; //restore default
//wait a little while to take effect.
for (i=0;i%3c100;i++)
{}

return keyPress;
}

Labels:
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.