6502 breadboard computer – part 5 hex keypad

Having made a very simple proto-monitor work that allows me just to read the contents of memory on the LCD display, I decided to get a hex keypad working as a next step. Eventually I’ll use the hex keypad to enter machine code instructions I can run on the computer.

The video above shows it working and explains more, but here’s a quick explanation.

As I discovered with my micro:bit hex keypad projects, a 4×4 keypad needs at least 8 wires to connect it direct to a microcontroller. Because the LCD display is using 11 I/O pins on the 6522 VIA (versatile interface adaptor), I’m going to need some kind of encoding chip. Several other folk have used an obsolete chip called the 74C922. I got a couple off ebay for not much money. You connect it up to power, ground, a couple of different capacitors and all the rows and columns on your keypad. These membrane keypads are very inexpensive and even come with self-adhesive backs. Fablon-tastic! You press a key and it squirts data out on 5 pins.

The DA (data available) pin goes high whenever you press a key. Use this to trigger an interrupt request in your program to then figure out what button you pressed and what to do next.

Here’s a very rough schematic of my Ben Eater-style computer with a bit more detail on the keypad:

breadboard computer schematic

The 4 pins A-D send out 16 different patterns of signals, in effect a binary number encoded in a 4-bit nibble, each binary number representing a different key.

My test program literally just types the characters on the LCD display using a neat trick from another breadboard computer enthusiast Robin Harris. Robin’s taken a slightly different approach to Ben Eater to save pins, and his project is well worth a look. Having read this 4-bit value sent from the key encoder chip to port A on the VIA, you use this to offset or slice a string containing all the possible characters.

table of keycodes

Because of the way my keypad is wired up, I need to use the string ’174*396#2850ACBD’ rather than something more logical, but it works just fine and I thought it was easier to change one line of code than do lots of re-wiring.

Now this is great but it leaves me with a problem: to make a working computer I need at least 4 more keys, maybe more. I’ll need to be able to scroll backwards and forwards through memory, enter data, run the code and stop it so I can drop back into the monitor program without pulling the power and losing all my hard work typing the program in.

There are a few options here. I could re-wire and recode so that the LCD works in 4-bit mode. This would be a pig to program, but would free up 4 more precious I/O pins on the VIA. Or I could try and add a shift key or even another 4×4 keypad – the video shows how this is possible with the 74C922 encoder and a bit of logic. Both those last two solutions require one more free pin. In the video you’ll see me realise that I actually do have one spare, as I think PA4 is currently unused.

Watch this space!

Source code: https://github.com/blogmywiki/6502

Posts in this series
Part 6
Part 4
Part 3
Part 2
Part 1

This entry was posted in computers and tagged , . Bookmark the permalink.

Leave a Reply