Apple IIe Keyboard Interfacing

Talk about your replica, what you have done and what you use it for

Apple IIe Keyboard Interfacing

Postby J. Calhoun » Nov Wed 29, 2006 1:33 am

I picked up an Apple IIe keyboard off eBay (IIe's themselves can still be had for a reasonable sum — unlike the II's and II+'s).

After spending an enjoyable evening decoding its pinout I discovered Vince had submitted the schematic for the IIe to AppleFritter (http://www.applefritter.com/node/7257?res=640x480). That might have saved me some time....

In any event, my thoughts are to interface this with the Replica I with some sort of microcontroller scanning the keys on the IIe keyboard and outputting ASCII (and strobe) for the Replica I.

As the schematic clearly shows (and I discovered) Apple used an unfortunate 10 x 8 matrix to map the keys (I see now that it is the optional numeric keypad that causes this).

I say unfortunate because if it were 8 by 8 there are many good microcontroller solutions that would be up to the task (and I'm not an expert by any means).

Add to that as well that you need an additional 8 pins to output the ASCII+strobe for the Replica I. Now we're up to 26 pins (and this allows no modifier key support but that is dubious in any event with the Apple/Replica I).

Any thoughts on how to proceed? What chip to use? As I say, I'm no expert but willing to have a go at this.

At a raw assembly level, the only chips I've had experience and success with are 68HC11 chips.

My sense is that the better route to pursue would be with AVR chips, but I don't know anything about them.

Any with experience who can suggest a direction to pursue?
User avatar
J. Calhoun
 
Posts: 70
Joined: Nov Sun 19, 2006 3:10 pm
Location: San Jose, CA

Postby vbriel » Nov Wed 29, 2006 6:47 am

It can be done with a simple microntroller. I prefer the AVR since that's what I use but a pic or 80c51 or others will also work. I have some 2e keyboards laying around I should spend the time to do this someday. It wouldn't take that long to decode the keys and the code.

Vince
User avatar
vbriel
Site Admin
 
Posts: 1184
Joined: Jul Tue 19, 2005 12:10 pm
Location: Ohio

Postby J. Calhoun » Nov Wed 29, 2006 11:35 am

It can be done with a simple microntroller. I prefer the AVR since that's what I use

I don't mind trying it.

But which AVR chip would you use? 8 rows, 10 columns, SHIFT modifier, plus 8 out for ASCII+strobe. Unless I'm missing something that's at least 27 pins. Atmega32? Or is there some clever trick you can use to keep the pin count down and swing a smaller AVR chip?
User avatar
J. Calhoun
 
Posts: 70
Joined: Nov Sun 19, 2006 3:10 pm
Location: San Jose, CA

Postby vbriel » Nov Thu 30, 2006 1:01 pm

No, you don't need that many I/O. Look at the pins of the keyboard. You have 10X8 plus shift and control keys for 20. Open apple keys aren't neeeded, nor is caps lock since the apple 1 is all upper case. Now, reset is a keyswitch that combined with ctrl is grounded. That fits right into what you need for reset. RESET on the 6502 needs to be grounded to reset. It is normally kept at 5V otherwise. So, to reset the 6502 with the apple 2e keyboard, you have to use ctrl and reset.

I'm finishing up getting ready to order the batch of expansion boards and I'm working on one other board for students and people that want to play with circuits, then I can work on a keyboard adapter. It is long overdue. I've been meaning to do this because I want to recreate the keyboard encoder for Apple II and IIplus that always fail.

Vince
User avatar
vbriel
Site Admin
 
Posts: 1184
Joined: Jul Tue 19, 2005 12:10 pm
Location: Ohio

Postby J. Calhoun » Dec Fri 01, 2006 1:10 am

No, you don't need that many I/O. Look at the pins of the keyboard.


You list the I/O needed to read the keyboard but the same microcontroller needs to also talk to the Replica I on an additional 8 I/O lines - unless you can somehow re-use the keyboard inputs.


So, now it seems I have a Mac Plus keyboard as well which, for better or worse, talks in a serial-like manner. This drops te pin count considerably but is made up for by the arcane protocol I have to implement on the microcontroller.

The physical keys themselves are great and "clacky" like the Apple II keyboard. Just no Reset key....

I'm going to have a go at it first since it seems you are planning to tackle the Apple II anyway. As well, I have microcontrollers that have the pins (or lack thereof) for this job. I'll post if I have any success.
User avatar
J. Calhoun
 
Posts: 70
Joined: Nov Sun 19, 2006 3:10 pm
Location: San Jose, CA

Postby vbriel » Dec Fri 01, 2006 8:06 am

Yeah, duh I need to have coffee before answering forums :) Another option besides a huge bulky microcontroller is a smaller one like the ATMEGA8515 or ATMEGA16 with ser/par shift register to generate the extra I/O pins needed. That might be enough to get the job done with 1 micro DIP and 1 shift register. I always look to keep things DIP through hole for kit builders when takes away from some choices at times but makes things better in the long run.

The ASCII is only 7 bit plus strobe and I can't remember the strobe length but the data is out there about it. I matched apple II strobe timing when I did the ps/2 adapter circuit.

Keep us updated on the project or if you get stuck somewhere.

Vince
User avatar
vbriel
Site Admin
 
Posts: 1184
Joined: Jul Tue 19, 2005 12:10 pm
Location: Ohio

Postby J. Calhoun » Dec Sun 03, 2006 2:40 am

I gave up trying to talk to the Mac 128K/512K/Plus keyboard. I found the protocol to talk to the keyboard but I was unable to get anything to work. I'm still new at microcontrollers though, so that may have had a lot to do with it.

I've been playing with an Arduino board (Atmega8-based microcontroller). It has a high level (C) programming environment so I don't spend too much time pulling my hair out. So I decided to go ahead and do a Keyboard 101 with the Apple IIe I had. While the Arduino doesn't have nearly enough pins for the job, I was able to read a majority of the Apple IIe keys. The keycode (row and column) I mapped to ASCII with a table and output to a serial LCD display. Sure enough, I could type to the LCD display (sans a few characters).

Next I think I might attach a shift register and see if I can scan the whole keyboard with that (with pins to spare).
User avatar
J. Calhoun
 
Posts: 70
Joined: Nov Sun 19, 2006 3:10 pm
Location: San Jose, CA

Postby vbriel » Dec Mon 11, 2006 9:17 pm

Well, I'm 3/4 of the way finished with my encoder replacement board for the Apple 2. Right now, I need to add control key sequence to decode when ctrl is pressed with a key. After it is finished I can mod the code to work with a IIe keyboard. This will give a 1 chip solution to people looking for an ASCII keyboard. After all, an ASCII keyboard is just a matrix keyboard with decoding logic.

I just brought back to life an old IIplus keyboard with a bad encoder. I replaced it with my design and it works great now on my replica 1. I think I can even add my ps/2 encoder code so people can have an external keyboard on their apple II/IIplus if they want! This will also apply to the IIe keyboards when it is finished. Just rambling off-topic.

Vince
User avatar
vbriel
Site Admin
 
Posts: 1184
Joined: Jul Tue 19, 2005 12:10 pm
Location: Ohio

Postby Kallikak » Dec Tue 12, 2006 12:02 am

vbriel wrote:I just brought back to life an old IIplus keyboard with a bad encoder.
Now that *is* interesting news.
Kallikak
 
Posts: 172
Joined: Jan Sun 29, 2006 6:42 pm
Location: Sydney

Postby J. Calhoun » Dec Tue 12, 2006 3:04 am

So, not knowing when Vince was going to get around to it, I have continued working on a IIe keyboard interface myself.

I have an Atmega8 (the Arduino board I mentioned above) driving an 8-bit serial to parallel shift register. Two output pins from the microcontroller drive this.

The eight outputs from the shift register drive the rows of the keyboard matrix. I start a one (high) on the shift register and move it through all eight positions (rows).

Ten more pins of the microcontroller read the ten columns on the keyboard matrix. I have tied each of the inputs to ground via a 100K resistor (a pull-down resisitor).

The microcontroller software constanly scans the keyboard by running the shift register and testing each of the ten inputs over and over. When a key is pressed, one of the ten inputs goes high. I wait a millisecond or so and test again (key debounce).

I mapped the row/column matrix to ASCII.

I'm driving a serial LCD right now for testing purposes. I can type on the Apple IIe keyboard directly to the serial LCD!

Tomorrow I am going to handle the SHIFT key. As it turns out that there is a whole row of the keyboard matrix the Replica I cannot use (these are basically cursor keys and such) I will use the first output of the shift register to scan the SHIFT key. I then need to map the key code to the appropriate shifted ASCII.

The next step was going to be to re-use the shift register as an output for the Replica I and afford another output pin from the microcontroller for the Strobe. (That actually leaves me one unused pin.)

But it sounds like Vince is racing ahead of me... Still, I'm learning a lot and enjoying it.
User avatar
J. Calhoun
 
Posts: 70
Joined: Nov Sun 19, 2006 3:10 pm
Location: San Jose, CA

Postby vbriel » Dec Tue 12, 2006 7:34 am

That's great, no race if you can get it done, it's all yours. My project was for something different that I was going to adapt for use with the IIe keyboard. I know a lot of people have been asking for ASCII keyboards and this will solve the problem. Last night I got the whole matrix working for the IIplus, then added the shift key option which I simply increase the .db lookup by the number of matrix keys and put all the keys in a second .db (database). I still have to add control database and function and REPEAT. I was going to do an auto repeat but the apple IIplus keyboards have a rept key so I'll just keep it like original.

Vince
User avatar
vbriel
Site Admin
 
Posts: 1184
Joined: Jul Tue 19, 2005 12:10 pm
Location: Ohio

Postby J. Calhoun » Dec Tue 12, 2006 10:58 am

After it is finished I can mod the code to work with a IIe keyboard.

How do the II and IIe keyboards different pinouts figure in to your plans?

I think the IIe has 26 pins and the II just 25 — are they the same 8 x 10 matrix (so I've done my IIe homework but not my II)? The IIe has two rows of 13 pins, the II just one row of 25. It would be nice if there were headers provided for either (one could of course opt not to solder on the one header they didn't need).

Perhaps a jumper could indicate the keyboard type (II or IIe). Perhaps a header could be provided for Reset....

What microcontroller are you using? One with lots of pins or are you going with a shift register?
User avatar
J. Calhoun
 
Posts: 70
Joined: Nov Sun 19, 2006 3:10 pm
Location: San Jose, CA

Postby vbriel » Dec Tue 12, 2006 12:57 pm

They are close but a little different. The bulk matrix for the II is 5X10 plus ctrl, shift and repeat keys. These are the only pins that need I/O. Reset goes to reset, the other end of reset goes to ground. I ground 1 side of shift and control and use pull up resistor on microcontroller. Then if the input goes low on those I know they are triggered.

The IIe keyboard has 8x10 matrix plus shift and ctrl. With 8 bits for ascii out thats 28, the AMTMEGA8515 has 27 :(

Maybe ctrl can be dropped for the replica since it isn't needed? I don't think I can settle for that.

Vince
User avatar
vbriel
Site Admin
 
Posts: 1184
Joined: Jul Tue 19, 2005 12:10 pm
Location: Ohio

Postby J. Calhoun » Dec Tue 12, 2006 2:05 pm

Maybe ctrl can be dropped for the replica since it isn't needed?

That's fine with me.

I got SHIFT working and I'm resuing the shift register to output ASCII to the Replica I.

Unfortunately, the Replica I is ignoring me. No apparent input seen from the Replica I. (I did remember to put the jumper on the keyboard header.)

- Does the Replica I SE have the same ASCII keyboard pinout in your docs?
- Are the pins described in the docs as viewed from the socket on the Replica I motherboard?
- What about the pulse? Pull low for 30 milliseconds and then high? Or high then low?

I'm close....
User avatar
J. Calhoun
 
Posts: 70
Joined: Nov Sun 19, 2006 3:10 pm
Location: San Jose, CA

Postby vbriel » Dec Tue 12, 2006 11:58 pm

The keyboard gets a 30ms rising pulse. I would keep with the shift register idea. 2 makes 8 and gets you lots of extra pins. I've just about finished the IIplus encoder. I have some clean up work to do. My thing is I want it to act just like the IIplus keyboards do so I am trying to emulate how it responds when multiple keys are pressed, things like that.

The schematic for the SE is the same. The pin out is a match for the Apple 2 hardware. Pin 1 is 5V, 2 is strobe, etc.

Is your dev board self powered? Might want to tie the gnds together so that you are getting a common ref to ground. Put a scope on your strobe signal and check it. Strobe is pin 40 on the 6821. Here's my formula for sending a byte.

I take ascii data and add $80 to it (that's the strobe bit)
I output that value for 30ms
I then turn off the strobe by outputting just the ascii value without the strobe bit. I leave that value on the keyboard port until I send the next keystroke. This is how the apple 1 and apple II sends/receives its keyboard data.

Vince
User avatar
vbriel
Site Admin
 
Posts: 1184
Joined: Jul Tue 19, 2005 12:10 pm
Location: Ohio

Next

Return to replica 1 General Discussion

Who is online

Users browsing this forum: No registered users and 3 guests

cron