Witam. Czy mógłby w skrócie ktoś wyjaśnić o co w tym zadaniu chodzi?
Oczywiście mogę sam wklepać i przetłumaczyć, ale co z tego jak dalej nie wiem o co w tym chodzi.
7. Scanning the Keypad - logic diagram extract
Notes on Keypads
<- get the source code
The following program shows how to scan the keypad. The program halts (to be precise, sits in an endless loop) once a key is pressed.
; This program scans the keypad.
; While no key is pressed the program
; scans row0, row1, row2, row3 and back to
; row0, continuously.
; When a key is pressed the key number
; is placed in R0.
; For this program, the keys are numbered
; as:
; +----+----+----+
; | 11 | 10 | 9 | row3
; +----+----+----+
; | 8 | 7 | 6 | row2
; +----+----|----+
; | 5 | 4 | 3 | row1
; +----+----+----+
; | 2 | 1 | 0 | row0
; +----+----+----+
; col2 col1 col0
; The pressed key number will be stored in
; R0. Therefore, R0 is initially cleared.
; Each key is scanned, and if it is not
; pressed R0 is incremented. In that way,
; when the pressed key is found, R0 will
; contain the key's number.
; The general purpose flag, F0, is used
; by the column-scan subroutine to indicate
; whether or not a pressed key was found
; in that column.
; If, after returning from colScan, F0 is
; set, this means the key was found.
start:
MOV R0, #0 ; clear R0 - the first key is key0
; scan row0
SETB P0.3 ; set row3
CLR P0.0 ; clear row0
CALL colScan ; call column-scan subroutine
JB F0, finish ; | if F0 is set, jump to end of program
; | (because the pressed key was found and its number is in R0)
; scan row1
SETB P0.0 ; set row0
CLR P0.1 ; clear row1
CALL colScan ; call column-scan subroutine
JB F0, finish ; | if F0 is set, jump to end of program
; | (because the pressed key was found and its number is in R0)
; scan row2
SETB P0.1 ; set row1
CLR P0.2 ; clear row2
CALL colScan ; call column-scan subroutine
JB F0, finish ; | if F0 is set, jump to end of program
; | (because the pressed key was found and its number is in R0)
; scan row3
SETB P0.2 ; set row2
CLR P0.3 ; clear row3
CALL colScan ; call column-scan subroutine
JB F0, finish ; | if F0 is set, jump to end of program
; | (because the pressed key was found and its number is in R0)
JMP start ; | go back to scan row 0
; | (this is why row3 is set at the start of the program
; | - when the program jumps back to start, row3 has just been scanned)
finish:
JMP $ ; program execution arrives here when key is found - do nothing
; column-scan subroutine
colScan:
JNB P0.4, gotKey ; if col0 is cleared - key found
INC R0 ; otherwise move to next key
JNB P0.5, gotKey ; if col1 is cleared - key found
INC R0 ; otherwise move to next key
JNB P0.6, gotKey ; if col2 is cleared - key found
INC R0 ; otherwise move to next key
RET ; return from subroutine - key not found
gotKey:
SETB F0 ; key found - set F0
RET ; and return from subroutine
It may appear as if this program does nothing. Remember, the program simply scans the keypad until a key is pressed. It then places the key number in R0 and enters an endless loop, doing nothing. Therefore, to see that it has performed the task correctly, examine the contents of R0 after a key is pressed. Also remember that, if the update frequency is set to 1, it will take a short amount of time for they pressed key's number to appear in R0.
Key number: the key number mentioned here is not the number on the key, but the key's position in the matrix. The # key is key number 0, 0 key is key number 1, * key is key number 2, and so on.
Further exercises for the student might be:
Modify the program so that the keypad is scanned continuously (ie: it doesn't stop after one key-press).
Write extra code that displays the key symbol on one of the 7-segment displays. For example, if key 4 is pressed, the number 8 appears on the display. If key 10 is pressed the number 2 appears on the display. (Note: the symbols # and * cannot be displayed on a 7-segment display, but some special characters could be invented and displayed instead.
Oczywiście mogę sam wklepać i przetłumaczyć, ale co z tego jak dalej nie wiem o co w tym chodzi.
7. Scanning the Keypad - logic diagram extract
Notes on Keypads
<- get the source code
The following program shows how to scan the keypad. The program halts (to be precise, sits in an endless loop) once a key is pressed.
; This program scans the keypad.
; While no key is pressed the program
; scans row0, row1, row2, row3 and back to
; row0, continuously.
; When a key is pressed the key number
; is placed in R0.
; For this program, the keys are numbered
; as:
; +----+----+----+
; | 11 | 10 | 9 | row3
; +----+----+----+
; | 8 | 7 | 6 | row2
; +----+----|----+
; | 5 | 4 | 3 | row1
; +----+----+----+
; | 2 | 1 | 0 | row0
; +----+----+----+
; col2 col1 col0
; The pressed key number will be stored in
; R0. Therefore, R0 is initially cleared.
; Each key is scanned, and if it is not
; pressed R0 is incremented. In that way,
; when the pressed key is found, R0 will
; contain the key's number.
; The general purpose flag, F0, is used
; by the column-scan subroutine to indicate
; whether or not a pressed key was found
; in that column.
; If, after returning from colScan, F0 is
; set, this means the key was found.
start:
MOV R0, #0 ; clear R0 - the first key is key0
; scan row0
SETB P0.3 ; set row3
CLR P0.0 ; clear row0
CALL colScan ; call column-scan subroutine
JB F0, finish ; | if F0 is set, jump to end of program
; | (because the pressed key was found and its number is in R0)
; scan row1
SETB P0.0 ; set row0
CLR P0.1 ; clear row1
CALL colScan ; call column-scan subroutine
JB F0, finish ; | if F0 is set, jump to end of program
; | (because the pressed key was found and its number is in R0)
; scan row2
SETB P0.1 ; set row1
CLR P0.2 ; clear row2
CALL colScan ; call column-scan subroutine
JB F0, finish ; | if F0 is set, jump to end of program
; | (because the pressed key was found and its number is in R0)
; scan row3
SETB P0.2 ; set row2
CLR P0.3 ; clear row3
CALL colScan ; call column-scan subroutine
JB F0, finish ; | if F0 is set, jump to end of program
; | (because the pressed key was found and its number is in R0)
JMP start ; | go back to scan row 0
; | (this is why row3 is set at the start of the program
; | - when the program jumps back to start, row3 has just been scanned)
finish:
JMP $ ; program execution arrives here when key is found - do nothing
; column-scan subroutine
colScan:
JNB P0.4, gotKey ; if col0 is cleared - key found
INC R0 ; otherwise move to next key
JNB P0.5, gotKey ; if col1 is cleared - key found
INC R0 ; otherwise move to next key
JNB P0.6, gotKey ; if col2 is cleared - key found
INC R0 ; otherwise move to next key
RET ; return from subroutine - key not found
gotKey:
SETB F0 ; key found - set F0
RET ; and return from subroutine
It may appear as if this program does nothing. Remember, the program simply scans the keypad until a key is pressed. It then places the key number in R0 and enters an endless loop, doing nothing. Therefore, to see that it has performed the task correctly, examine the contents of R0 after a key is pressed. Also remember that, if the update frequency is set to 1, it will take a short amount of time for they pressed key's number to appear in R0.
Key number: the key number mentioned here is not the number on the key, but the key's position in the matrix. The # key is key number 0, 0 key is key number 1, * key is key number 2, and so on.
Further exercises for the student might be:
Modify the program so that the keypad is scanned continuously (ie: it doesn't stop after one key-press).
Write extra code that displays the key symbol on one of the 7-segment displays. For example, if key 4 is pressed, the number 8 appears on the display. If key 10 is pressed the number 2 appears on the display. (Note: the symbols # and * cannot be displayed on a 7-segment display, but some special characters could be invented and displayed instead.