These forums are now closed Forum Index These forums are now closed
Please see the new forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Keyboard Interfacing Frustrations

 
Post new topic   Reply to topic    These forums are now closed Forum Index -> Compatability
View previous topic :: View next topic  
Author Message
J. Calhoun



Joined: 19 Nov 2006
Posts: 71
Location: San Jose, CA

PostPosted: Jan Sat 06, 2007 1:15 am    Post subject: Keyboard Interfacing Frustrations Reply with quote

Well, I'm stymied. I've been trying to solve this problem all week to no avail so I'm going to try to ellicit experienced help.

In short, I've written code for the ATMEGA8515 that should scan an AppleIIe keyboard and output ASCII. In the simulator (AVRStudio4) it looks good. When I download the code to the chip .... it doesn't work.

Well, almost ... some of the keys work, just not all. It seems one row is off. The IIe keyboard is an 8 x 10 matrix. But the 8 keys in this column (?, O, L, 9, ", -, }, rt. cursor) report the wrong row.

I know the row is wrong because I quadruple checked it with a continuity tester. And furthermore, the same assumptions worked with my Arduino-based attempt to interface the IIe with the Replica I.

I've changed the PORT's around, I've rewritten the code several times in different ways, and it always behaves the same way; most of the keys work but for the 8 in the one column.

Since I'm new to AVR assembler, I thought maybe someone experienced will see a problem in my code. There is no debouncing, SHIFT key support, STROBING and other refinements, but that should make the code a little simpler to digest. And in any event, even this basic functionality is broken.

I looked at your code, Vince, for the PS/2 interface and made some changes to my code based on yours, but still to no luck.

I have PORTD going to the LED's on the STK500 for debugging. This is how I am checking the ROW values and determining they are wrong.

Code:
;Apple IIe Keyboard to ASCII Interface
;
; PORT B represents the 8 rows of the keyboard
; PORT A and part of PORT C represent inputs for the columns (and EVENTUAL modifiers)
; PORT D is used as the ASCII output (for debugging right now)

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


.def      temp = R16         ; Temp var
.def      keyrow = R17      ; Row we are scanning
.def      temp2 = R18         ; Another temp var
.def      keycode = R19      ; Keyboard row/column code

// ------------------------------ 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
;   out      PORTD, keycode 
   rjmp   loop
   
// ------------------------------ scan_keyboard

scan_keyboard:
   ldi      keyrow, 0x00
   ldi      keycode, 0xFF      ; Indicate no key with 0xFF
   ldi      temp2, 0xFE
scan_new_row:
   out      PORTB, temp2      ; Drop low the row we are scanning.
   
   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      keyrow
   cpi      keyrow, 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:
   out      PORTD, keyrow         ; TEMP - TESTING - WRONG ROW HERE FOR SOME KEYS
   dec      keycode            ; Was 1-based, make 0-based.
   cpi      keyrow, 0x00      ; If on row 0, we're done.
   breq   scan_done      ; keycode indicates offset into ASCII table
   ldi      temp, 0x0A      ; Otherwise, add 0x0A offset for each row
add_row_offset:      ; keyocde will then represent offset into ASCII table
   add      keycode, temp
   dec      keyrow
   cpi      keyrow, 0x00
   brne   add_row_offset
   
scan_done:
   ret
   
code_2_ASCII:
.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      '9',  '8',  '6',  '4',  '3',  '2',  '1',  '7',  '5',  0x1B
.db      0x22, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0D, 0x00
.db      '-',  '0',  0x00, 0x00, 0x00, 0x00, 0x00, '=',  0x5C, 0x00
.db      '}',  '{',  0x00, 0x00, 0x00, 0x00, 0x00, 'P',  '~',  0x00
.db      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
Back to top
View user's profile Send private message Visit poster's website
J. Calhoun



Joined: 19 Nov 2006
Posts: 71
Location: San Jose, CA

PostPosted: Jan Sun 07, 2007 5:06 am    Post subject: Reply with quote

I give up, sort of. If the keys want to be in different rows, I'm going to oblige them. I still don't know what is going on though.

I changed the ASCII values in my table to map to what the ATMEGA is seeing and sure enough I can type to the Replica I. All characters.

I see though that when I send a tilde (~) the Replica I sees a caret (^). Is that right? Maybe the Apple I didn't know these characters? And the bar (|) character is substituted as well. And a few others too (maybe the curly braces and perhaps one other key?).

I'll be using ExpressPCB to make up a few boards soon....
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    These forums are now closed Forum Index -> Compatability All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group