-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathE9_E1.ASM
70 lines (62 loc) · 1.84 KB
/
E9_E1.ASM
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
; Interface the keypad and read the key-codes (HEX) of all keys.
; Connect the keyboard to J2 of the trainer
; Set the trainer in to KEYBOARD MODE
; Configure Port A as Input and Port C as Output
; 8000H
BEGIN:
MOV DPTR, #E803H ; ADDRESS OF (J2) CONTROL REG
; SET ALL PORTS AS INPUTS; PORT_A IN INPUT MODE
MOV A, #90H ; CONTROL CODE
MOVX @DPTR, A ; SET CONTROL REGISTER WITH THE CODE
MOV A, #07H ; TO SEND HIGH ON ALL ROWS
DEC 82H ; DEC DPTR
MOVX @DPTR, A ; WRITE TO PORT_C
MOV 82H, #00H ; GO TO PORT_A
WAIT1:
MOVX A, @DPTR ; GET PORT_A INPUT TO ACCUMULATOR
; CHECK ALL KEYS RELEASED?
JNZ WAIT1 ; REPEAT UNTILL NON-ZERO INPUT GIVEN
LCALL DBOUNCE ; AWAIT DEBOUNCE KEYBOARD
WAIT2:
MOVX A, @DPTR ; READ PORT_A FOR COLUMNS
JZ WAIT2 ; CHECK ANY KEY PRESSED?
LCALL DBOUNCE ; AWAIT DEBOUNCE KEYBOARD
MOV R0, #00H ; INITIAL KEY CODE
MOV R1, #03H ; THE NUMBER OF ROWS
MOV R2, #80H ; TO SEND HIGH TO THE ROWS; INITIAL VALUE
NXT_ROW:
MOV DPTR, #E802H ; ADDRESS OF PORT_C
MOV A, R2 ; GET HIGH CODE TO ACCUMULATOR
RL A ; ROTATE LEFT TO GO TO THE NEXT ROW
MOV R2, A ; SAVE IN (R2)
MOVX @DPTR, A ; WRITE IN PORT_C
MOV DPL, #00H ; GO TO PORT_A
MOVX A, @DPTR ; GET PORT_A INPUT
JNZ FOUND ;
MOV A, R0 ;
ADD A, #08H ;
MOV R0, A ;
DJNZ R1, NXT_ROW ;
LJMP BEGIN ; EXIT AND BEGIN AGAIN
FOUND:
RRC A
JC OVER
INC R0
SJMP FOUND
OVER:
MOV 60H, R0 ; DISPLAY PLACEHOLDER
MOV F0H, #00H ; NO DOT
LCALL UPDDT ; SHOW IN DISPLAY FIELD
LJMP BEGIN ; REPEAT ENTIRE PROGRAM AGAIN
DBOUNCE:
MOV TMOD, #10H ; TIMER-1 IN MODE_1
; DELAY OF 20ms
MOV TH1, #B7H
MOV TL1, #FFH
SETB TR1 ; TIMER-1 SET
HERE:
JNB TF1, HERE ; WAIT UNTIL TIMER-1 OVERFLOWS
; RESET TIMER-1
CLR TF1
CLR TR1
RET ; RETURN BACK TO MAIN LOOP