Keyboard is connected similarly to ZX-Spectrum - 8 bits from address bus ( other bits by the way ; ) trough diodes goes to key matrix and come back through data bus (if address space is 0x8000...0x9FFF):
data bus bits ======> | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
bit 0 from address bus | [S] | [F] | ENTER | + | - | Home | End | RESET |
bit 1 from address bus | O ; | P , | . | 3 | 6 | 9 | * | (reserved) |
bit 2 from address bus | L | ANS | 2 | 5 | 8 | / | PgUp | PgDn |
bit 3 from address bus | = | EE | 0 | 1 | 4 | 7 | AC | (reserved) |
bit 4 from address bus | STOP | INS | DEL | MODE | Up | Down | Left | Right |
bit 5 from address bus | Q ! | W " | E # | R $ | T ( | Y ) | U ? | I : |
bit 6 from address bus | A | S | D | F | G | H | J | K |
bit 7 from address bus | Z | X | C | V | B | N | M | SPACE |
Scanning is done by reading from memory range 0x8000...0x9FFF and "0" in any address bits 0...7 will be retranslated into data bus if any key in that row is pressed. Recommended way to read from keyboard is reading from 8 address locations - 0x9FFE (bit 0 is zero), 0x9FFD (but 1 is zero), 0x9FFB (bit 2 is zero), 0x9FF7 (bit 3 is zero), 0x9FEF (bit 4 is zero), 0x9FDF (bit 5 is zero), 0x9FBF (bit 6 is zero) and 0x9F7F (bit 7 is zero). If nothing is pressed byte FF will be read. Otherwise proper bit will be reset to indicate which particular key was pressed. For example:
LDA 9F7F ; read 7th row (bit 7 is zero) to A
ANI 80H ; mask 7th bit in response
JZ SPACE ; jump if zero - SPACE pressed
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.
Why dedicate such a large memory range ? I thought 256 addresses would be enough...
Add a 74LS138 for extension and this is reduced to 8 addresses :-)
Are you sure? yes | no
May be I'll add more keys and then it will require 9th zero (+8 keys) and even 10th zero (+16 keys) - then it will take 1K ;)
Also I don't have kilobytes of software to fill all memory, so current memory map is more than sufficient :)
Are you sure? yes | no
Nice trick to know :-)
Are you sure? yes | no
The circuit successfully detects a single keypress and 2 simultaneous keypresses, but starting with 3 it may have a "phantom" 4th keypress wrongly detected if 3rd key is in one row or one column with first two...
Are you sure? yes | no