Apple IIe Keyboard Interface

What have you built or do you want to design to go with your replica 1

Apple IIe Keyboard Interface

Postby J. Calhoun » Jan Wed 10, 2007 2:20 pm

The project is coming to a close. It's been several months since I first placed a bid on an Apple IIe keyboard on eBay.

When it arrived I cleaned it up and began decoding the keyboard matrix. Later (after my own efforts) I found that Vince had linked to a scan of the IIe schematic on the AppleFritters website.

Image

Here is my own data. Looking at the cable coming out of the keyboard I numbered the pins:

Code: Select all
 0  1  2  3  4  5  6  7  8  9 10 11 12
13 14 15 16 17 18 19 20 21 22 23 24 25
                   H


The 'H' at the bottom above indicates the registration thingy on the connector.

The pins then are:

Code: Select all
0 Row 4
1 SHIFT
2 Col 0
3 Row 0
4 Row 1
5 Row 2
6 Row 3
7 Col 1
8 Col 2
9 Col 3
10 Col 4
11 Col 5
12 Col 6
13 Col 7
14 Col 8
15 Row 5
16 Row 6
17 Row 7
18 RESET
19 COM
20 CONTROL
21 CAPS LOCK
22 OPEN APPLE
23 CLOSED APPLE
24 LIGHT
25 Col 9


The rows and columns keys then correspond to:

Code: Select all
    2  7  8  9 10 11 12 13 14 25
   ------------------------------
3 | ?  >  N  B  V  C  X  <  M  Z
4 | O  I  Y  R  E  W  Q  U  T TAB
5 | L  :  G  F  H  S  D  K  J  A
6 | 9  8  6  4  3  2  1  7  5 ESC
0 | " SPC               UP CR   
15| -  0                 =  \   
16| }  {                 P  ~   
17|RT LF                DN DEL   


Pin numbers are along top and left edges above. UP, DN, LF, RT refer to the cursor keys. CR is return. (Wow these ASCII tables are tedious.)
Last edited by J. Calhoun on Jan Fri 19, 2007 11:18 pm, edited 1 time in total.
User avatar
J. Calhoun
 
Posts: 70
Joined: Nov Sun 19, 2006 3:10 pm
Location: San Jose, CA

Postby J. Calhoun » Jan Wed 10, 2007 11:59 pm

In order to talk to the Replica I, I needed a microcontroller to scan the keyboard and output the ASCII to the keyboard interface on the Replica.

I ended up buying the STK500 starter kit that Atmel sells from Digi-Key. It comes with everything you need — period. Only $79 and it even comes with a couple of microcontrollers.

http://www.digikey.com/scripts/DkSearch/dksus.dll?Criteria?Ref=6390&Site=US&Cat=33686194

The software is free and a version even comes on a CD with the STK500 (requires Windows unfortunately). There is plenty of help and tutorials out on the Web if you want to learn how to develop for these chips.

I ended up learning to program the ATMEGA8515 that came with the STK500. With all of its ports it easily handled the task with pins left to spare.

Here is the code I wrote. It works.

Code: Select all
;Apple IIe Keyboard to ASCII Interface
;
; PORT B represents the 8 rows of the keyboard (3,4,5,6,0,15,16,17)
; PORT A and part of PORT C represent inputs for the columns
; PORT D is used as the ASCII output

.include "8515def.inc"          ; Includes the 8515 definitions file


.def        temp = R16          ; Temp var
.def        row = R17           ; Row we are scanning
.def        temp2 = R18         ; Another temp var
.def        keycode = R19       ; Keyboard row/column code
.def        ASCII = R20         ; ASCII value for key
.def        lastkey = R21       ; last keycode

; ------------------------------ Begin

    rjmp    reset

; ------------------------------ reset

reset:
    ldi     temp, high(RAMEND)
    out     SPH, temp
    ldi     temp, low(RAMEND)   ; Set up stack pointer
    out     SPL, temp
   
    ldi     temp, 0xFF          ; PORTB outputs.
    out     DDRB, temp
    ldi     temp, 0x00          ; PORTA inputs.
    out     DDRA, temp
    ldi     temp, 0xFF          ; Enable pull-up resitors for PORTA
    out     PORTA, temp
    ldi     temp, 0xF0          ; PORTC inputs.
    out     DDRC, temp
    ldi     temp, 0xFF          ; Enable pull-up resitors for PORTC
    out     PORTC, temp
    ldi     temp, 0xFF          ; PORTD outputs.
    out     DDRD, temp
   
loop:
    rcall   scan_keyboard       ; Scan keyboard, keycode indicates key pressed
    cpi     keycode, 0xFF       ; 0xFF indicates no key press
    breq    store_lastkey       ; No key, save that and then scan again.
    cp      lastkey, keycode    ; See if key same one as last time (still held)
    breq    loop                ; If same key, don't send out ASCII again until key released
    rcall   get_ASCII           ; If key pressed, get ASCII
    ldi     temp, 0x80          ; Strobe bit.
    add     ASCII, temp         ; Set strobe bit.
    out     PORTD, ASCII        ; Strobe and output ASCII
    ldi     temp, 0x27          ; Amounts to a 40mS delay
    rcall   delay_temp          ; Hold strobe 40 milliseconds.
    ldi     temp, 0x80          ; Strobe bit.
    sub     ASCII, temp         ; Pull strobe bit off
    out     PORTD, ASCII        ; Leave unstrobed ASCII on port.
store_lastkey:
    mov     lastkey, keycode
    rjmp    loop                ; Scan again.
   
; ------------------------------ scan_keyboard

scan_keyboard:
    ldi     row, 0x00           ; Start at row 0.
    ldi     keycode, 0xFF       ; 0xFF indicates no key press.
    ldi     temp2, 0xFE         ; All bits high save row 0.
scan_new_row:
    out     PORTB, temp2        ; Drop low the row we are scanning.
    ldi     temp, 0x14          ; Short wait for port to settle.
short_wait:
    dec     temp
    brne    short_wait
   
    sbis    PINA, 0x00          ; Skip if column 0 set
    ldi     keycode, 0x01
    sbis    PINA, 0x01          ; Skip if column 1 set
    ldi     keycode, 0x02   
    sbis    PINA, 0x02          ; Skip if column 2 set
    ldi     keycode, 0x03   
    sbis    PINA, 0x03          ; Skip if column 3 set
    ldi     keycode, 0x04   
    sbis    PINA, 0x04          ; Skip if column 4 set
    ldi     keycode, 0x05   
    sbis    PINA, 0x05          ; Skip if column 5 set
    ldi     keycode, 0x06   
    sbis    PINA, 0x06          ; Skip if column 6 set
    ldi     keycode, 0x07   
    sbis    PINA, 0x07          ; Skip if column 7 set
    ldi     keycode, 0x08   
    sbis    PINC, 0x00          ; Skip if column 8 set
    ldi     keycode, 0x09   
    sbis    PINC, 0x01          ; Skip if column 9 set
    ldi     keycode, 0x0A
   
    cpi     keycode, 0xFF       ; Did we find a key
    brne    got_key
   
row_complete:
    inc     row
    cpi     row, 0x08           ; See if we have completed the last row
    breq    scan_done
    rol     temp2               ; Not done scanning, rotate row
    rjmp    scan_new_row
   
got_key:
    dec     keycode             ; Was 1-based, make 0-based.
    ldi     temp, 0x50          ; We want to skip 80 bytes to get to shifted data
    sbis    PINC, 0x02          ; Skip if SHIFT key not down
    add     keycode, temp       ; Add 80 to keycode
    cpi     row, 0x00
    breq    scan_done
    ldi     temp, 0x0A
add_row_offset:
    add     keycode, temp
    dec     row
    cpi     row, 0x00
    brne    add_row_offset
    rjmp    scan_done
   
scan_done:
    ret
   
; ------------------------------ delay_temp
   
delay_temp:
    ldi     temp2, 0xFF
delay_loop:
    dec     temp2
    cpi     temp2, 0x00
    brne    delay_loop
    dec     temp
    cpi     temp, 0x00
    brne    delay_temp
    ret

; ------------------------------ get_ASCII
   
get_ASCII:
    ldi     ZH, high(2 * code_2_ASCII)
    ldi     ZL, low(2 * code_2_ASCII)
    add     ZL, keycode
    brcc    got_ASCII
    inc     ZH
got_ASCII:
    lpm
    mov     ASCII, R0
    ret

; ------------------------------ code_2_ASCII

code_2_ASCII:
.db     0x2F, '.',  'N',  'B',  'V',  'C',  'X',  ',',  'M',  'Z'
.db     'O',  'I',  'Y',  'R',  'E',  'W',  'Q',  'U',  'T',  0x09
.db     'L',  ';',  'G',  'F',  'H',  'S',  'D',  'K',  'J',  'A'
.db     '9',  '8',  '6',  '4',  '3',  '2',  '1',  '7',  '5',  0x1B
.db     0x27, 0x20, '+',  '.',  '9',  '8',  0x00, 0x00, 0x0D, '*'
.db     '-',  '0',  '3',  '2',  '1',  '0',  0x00, '=',  0x5C, '/'
.db     ']',  '[',  '7',  '6',  '5',  '4',  0x1B, 'P',  '~',  ')'
.db     0x00, 0x00, 0x2C, 0x0D, '-',  '(',  0x20, 0x00, 0x00, '?'
.db     '?',  '>',  'N',  'B',  'V',  'C',  'X',  '<',  'M',  'Z'
.db     'O',  'I',  'Y',  'R',  'E',  'W',  'Q',  'U',  'T',  0x09
.db     'L',  ':',  'G',  'F',  'H',  'S',  'D',  'K',  'J',  'A'
.db     '(',  '*',  '^',  '$',  '#',  '@',  '!',  '&',  '%',  0x1B
.db     0x22, 0x20, '+',  '.',  '9',  '8',  0x00, 0x00, 0x0D, '*'
.db     '_',  ')',  '3',  '2',  '1',  '0',  0x00, '+',  '|',  '/'
.db     '}',  '{',  '7',  '6',  '5',  '4',  0x1B, 'P',  '~',  ')'
.db     0x00, 0x00, 0x2C, 0x0D, '-',  '(',  0x20, 0x00, 0x00, 0x1B
Last edited by J. Calhoun on Feb Fri 02, 2007 1:13 am, edited 2 times in total.
User avatar
J. Calhoun
 
Posts: 70
Joined: Nov Sun 19, 2006 3:10 pm
Location: San Jose, CA

Postby J. Calhoun » Jan Thu 11, 2007 12:53 am

Once I was satisfied with my breadboarded keyboard interface I tried out the company ExpressPCB in order to create a professional printed circuit board.

http://www.expresspcb.com/

They have Windows-only software you can download for free. It allows you to create nice PCBs with several layers, silkscreens etc. If you keep it to double-sided and 2.5 x 3.8 inches they'll give you three boards, not silkscreened, for $51. This is what I did.

Here is the layout I came up with (requires ExpressPCB software to view):

http://homepage.mac.com/calhoun/.Public/AppleIIeASCIIEncoder.pcb

(If file disappears, my site may be down due to bandwidth issues. The file should re-appear within a week.)

Here is a small screen grab:
Image

You can if you like, grab the PCB file linked to above, go to ExpressPCB to download their free software, and order your own boards. Since you get three boards you may want to go in with others on it.
User avatar
J. Calhoun
 
Posts: 70
Joined: Nov Sun 19, 2006 3:10 pm
Location: San Jose, CA

Postby J. Calhoun » Jan Fri 19, 2007 1:21 am

In my experience, the boards from ExpressPCB come back in about 4 days. Not bad. And here is the bare board (top-side):

(If images disappear, my site may be down temporarily due to bandwidth issues.)
Image

Here is the board with components in place:
Image

The ASCII and Keyboard sockets are very deliberately placed. The ASCII socket will connect easily via a 16-pin DIP ribbon cable connector to the corresponding socket on the Replica I. If the board is placed adjoining the lower edge (rightmost end) of the Replica I, the sockets are aligned. Also, the cable from the Apple IIe keyboard neatly folds and sockets into the 26 pin header without any 90 degree bends etc.

The circuit uses the ATMEGA8515, a few capacitors, and a crsytal oscillator as the primary components.

I placed one jumper to allow for you to ground the CONTROL (labeled CNTL on the PCB) key making the RESET key alone reset the Replica 1 (unjumpering it means CONTROL + RESET must be pressed to reset the Replica 1).

Other unused modifier keys I left solder holes for (CA is Closed Apple, OA - Open Apple, CL - Caps Lock).

Two unused port pins I singled out with jumpers (J1 and above unlabeled J2). These can be jumpered to ground. The software currently ignores these but could use them in the future — perhaps to allow for enabling auto-repeat for the keys or something. They correspond to PC3 and PC4.

PC5, PC6, and PC7 were also unused but solder holes were left for them for possible future use.

Finally, I had room on the board so I added the standard AVR ISP 10-pin header. I've never used these before and in my trial tonight I was not able to get it to work. Maybe I'm doing something wrong.
Last edited by J. Calhoun on Jan Fri 19, 2007 1:38 pm, edited 1 time in total.
User avatar
J. Calhoun
 
Posts: 70
Joined: Nov Sun 19, 2006 3:10 pm
Location: San Jose, CA

Postby J. Calhoun » Jan Fri 19, 2007 1:32 pm

Conclusion.

It works. I need to time the strobe to see if I'm really doing 40 mS. I may even try to back it down a bit so I don't miss a keystroke. But all that is in software. The board I am very satisfied with.

I think I messed up the square pad on the LED, so if you make this board, just be sure to get the LED in correctly. The LED, current limiting resisitor (R1) and reset switch (SW1) strictly speaking aren't needed. The 10-pin ISP socket isn't needed either if you don't plan to program the chip in place (still need to figure out how to do that).

Image

You can see it above installed (keyboard was disconnected for clarity). You can see too how nicely the ASCII ports of the two boards mate up.

One more comment for people that would follow a similar path. I was at first unable to take my work on the STK500 and move it to a prototype. The problem turned out to be that the AVR 8515 that is included with the STK500 can't do 8 MHz (and I was using an 8 MHz crystal on my proto). Don't make that mistake — if you want 8MHz, buy some ATMEGA8515's from Jameco or where ever.

Finally, the board peeking out from behind the keyboard (nearly installed):

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

Postby Aaron Teeling » Jan Fri 19, 2007 4:39 pm

Nice work on the keyboard adapter. Very clean layout and install. Looking forward to seeing the rest of your machine.
Aaron Teeling
 
Posts: 84
Joined: Oct Mon 17, 2005 7:49 pm
Location: Virginia Beach, VA

Postby devo » Feb Thu 01, 2007 7:45 am

You did a really impressive job here! I can't begin to tell you how helpful it's been to me as a reference, and I appreciate the detailed descriptions of the various parts of the project.

Can you tell me a little more about your ribbon cable connectors? I've had trouble finding something similar. I've decided to bite the bullet and try to design my own keypad PCB, and those connectors look like just the thing to hook it up to my replica I (or some other future victim).
devo
 
Posts: 30
Joined: Jan Thu 11, 2007 7:37 am
Location: Omaha, NE

Postby J. Calhoun » Feb Fri 02, 2007 1:23 am

Omaha is awesome. My wife grew up there — I grew up in Kansas City and met her at K.U.

Anyway....

The rainbow cable is flat ribbon cable from Jameco. On the ends are I think what Jameco call IDC DIP Flat Cable Plugs. I'd give you a URL but Jameco's page isn't coming up for me right now. The part number (it's in a catalog I am staring at right now) is 42673 (for the 16-pin style).

EDIT:

I found my invoice from Jameco. Here are the exact parts and description:

Code: Select all
    42673CE    CONNECTOR,IDC DIP PLUG,16PIN,         10       .45       4.50
   105671CE    * CBLE,28AWG,FLATRAINBOW,16CON        10       .40       4.07
User avatar
J. Calhoun
 
Posts: 70
Joined: Nov Sun 19, 2006 3:10 pm
Location: San Jose, CA

Postby devo » Feb Fri 02, 2007 1:50 pm

Found it, thanks!

An aside you might appreciate: my brother lives in Lawrence (he managed the Liberty Hall video store for a while). The first time my wife (born in Laguna Beach, lived in Berkeley for years) and I went down to visit him, she loved the town. She kept looking at the prices for houses and saying "Isn't there a zero missing in there somewhere?!"
devo
 
Posts: 30
Joined: Jan Thu 11, 2007 7:37 am
Location: Omaha, NE

Postby sfahey » Apr Tue 03, 2007 5:02 pm

J. Calhoun wrote:Conclusion.

It works. I need to time the strobe to see if I'm really doing 40 mS. I may even try to back it down a bit so I don't miss a keystroke. But all that is in software. The board I am very satisfied with.


Is this something you're planning to sell to others who don't have the time to assemble? BTW, Jayhawk here too. ;)
sfahey
 
Posts: 4
Joined: Jan Thu 04, 2007 10:58 am

Postby J. Calhoun » Apr Thu 05, 2007 12:17 am

Is this something you're planning to sell to others who don't have the time to assemble?


No. It hadn't occurred to me. Do you have an Apple IIe keyboard (that being, to my mind, the largest hurdle)?

BTW, Jayhawk here too.


That is strange.... What's with all these midwesterners?

An aside you might appreciate: my brother lives in Lawrence (he managed the Liberty Hall video store for a while)

Liberty Hall was (is?) an awesome video store / arts theater. I used to go there to rent those crazy foreign films that those crazy foreigners make. Netflix probably more or less killed these places though. I don't know though since I've been in San Jose for over 11 years now....
User avatar
J. Calhoun
 
Posts: 70
Joined: Nov Sun 19, 2006 3:10 pm
Location: San Jose, CA


Return to Creation Room

Who is online

Users browsing this forum: No registered users and 2 guests

cron