Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
06/06/01 11:17
Read: times


 
#12245 - question about a keyboard
I have a 8255 attached to my 80C31 processor at 3C00h.
To the port pins I connected a full matrix keyboard which I made
myself. The keyboard consists of 5 ROWS and 11 COLUMNS.
The Rows are connected to PORT A and the Columns are connected to
port B (8) and C (3).
I wrote the following program to scan the thing and it works
beautifully, except for the special functions like SHIFT, ESC
ENTER etc. Those are things I will have to get into in time.
What I would like to do is:
The Shift I want to use for switching between capitals.
As you can see in the program I detect every key seperately and
do a MOV A,#51h (for example) to obtain the right character on my
LCD. (connected to 2 74HC573's).
Now my QUESTION !:
If I want to do non-capital characters I should do a check on
the status of the shift-key (store the status somewhere) and from
there decide wheter to use capitals or not. This would mean a lot
of code and checks extra in every detection in my program.
Or is there a smarter way to do this? I am not too lazy. heheh.

Before I call the program GET_KEY I scan port A in a loop
(I have PUSH and POP everywhere needed so I left them out here).

INIT_SCAN:
DO_SCAN:
MOV SCAN,#01h ;initialize SCAN
KEY_SCAN:
MOV DPTR,#3C00h ;point to port A
MOV A,SCAN ;read value of SCAN
MOVX @DPTR,A ;write to port A
CALL GET_KEY ;go to subroutine
RL A ;rotate A left
MOV SCAN,A ;save to SCAN
CJNE A,#20h,KEY_SCAN;repeat while SCAN < 20 (5 ROWS)
JMP INIT_SCAN ;restart

GET_KEY:
ROW_1:
CJNE A,#01h,GO_TO_ROW_2 ;if A > 01h then not ROW_1
JMP DECODE_ROW_1 ;decode ROW_1
GO_TO_ROW_2:
LJMP ROW_2
DECODE_ROW_1:
MOV DPTR,#3C01h ;point to port B
MOVX A,@DPTR ;read port B
;there's a lot of code here similar to what's beneath this,
;that decodes ROW_1 and a lot of code beneath the last line
;of ROW_2.
ROW_2:
CJNE A,#02h,GO_TO_ROW_3;if A > 02h then not ROW_2
JMP DECODE_ROW_2 ;decode ROW_2
GO_TO_ROW_3:
LJMP ROW_3
DECODE_ROW_2:
MOV DPTR,#3C01h ;point to port B
MOVX A,@DPTR ;read port B
Q_PRESSED:
CJNE A,#01h,R_PRESSED ;if A > 01h then R?
MOV LAST_KEY,A ;store A
MOV A,#51h ;Q pressed
MOV NEW_KEY,A
LJMP KEY_found
R_PRESSED:
CJNE A,#02h,S_PRESSED;if A > 02h then S?
MOV LAST_KEY,A ;store A
MOV A,#52h ;R pressed
MOV NEW_KEY,A
LJMP KEY_found
S_PRESSED:
CJNE A,#04h,T_PRESSED;if A > 04h then T?
MOV LAST_KEY,A ;store A
MOV A,#53h ;S pressed
MOV NEW_KEY,A
LJMP KEY_found
;and so forth for T,U etc
;below the actual write command for my LCD.
KEY_FOUND:
DEBOUNCE: ;debounce first before writing
MOV DEBOUNCE_1,#12h;load counter 1
DJNZ R0,$
MOV DEBOUNCE_2,#0FFh;load counter 2
DJNZ R1,$
MOVX A,@DPTR ;reload port B
CJNE A,LAST_KEY,EXIT_ALL
MOV A,NEW_KEY
JZ EXIT_ALL
CALL LCD_DATA ;saves A to HC573 for DATAbus
CALL LCD_Dwrite ;controls read write etc of LCD
call LCD_delay ;need a delay here
call LCD_idle ;remove write-state
wait: MOVX A,@DPTR ;get port B again
JNZ wait ;and loop here untill KEY released
EXIT_ALL:

List of 5 messages in thread
TopicAuthorDate
question about a keyboard            01/01/70 00:00      
RE: question about a keyboard            01/01/70 00:00      
RE: question about a keyboard            01/01/70 00:00      
RE: question about a keyboard            01/01/70 00:00      
RE: question about a keyboard            01/01/70 00:00      

Back to Subject List