19 5月, 2016

微机系统与接口实验(九)—键盘扫描实验

1. 实验目的

  • 了解键盘扫描及数码显示的基本原理,熟悉 8255 的编程。

2. 实验内容

  • 题目1::将键盘进行编号,记作 0~F,当按下其中一个按键时,将该按键对应的编号在一个数码管上显示出来,当再按下一个按键时,便将这个按键的编号在下一个数码管上显示出来。
  • 注:因为想做实验十,老师说实验十做出来平时成绩给满分,所以本次试验只做了一个了解一下基本原理就不做了。

3. 实验1

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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
MY8255_A EQU 0600H
MY8255_B EQU 0602H
MY8255_C EQU 0604H
MY8255_CON  EQU 0606H
SSTACK  SEGMENT STACK
    DW 16 DUP(?)
SSTACK  ENDS
 
DATA SEGMENT
    DTABLE  DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H, 7FH,6FH,77H,7CH,39H,5EH,79H,71H
DATA ENDS
CODE SEGMENT
    ASSUME CS:CODE,DS:DATA
START:  
    MOV AX,DATA
    MOV DS,AXMOV -SI,3000H
    MOV AL,00H
    MOV [SI],AL             ;清显示缓冲
    MOV [SI+1],AL
    MOV [SI+2],AL
    MOV [SI+3],AL
    MOV [SI+4],AL
    MOV [SI+5],AL
    MOV DI,3005H
    MOV DX,MY8255_CON       ;写 8255 控制字
    MOV AL,81H
    OUT DX,AL
BEGIN:  
    CALL DIS                ;调用显示子程序
    CALL CLEAR              ;清屏
    CALL CCSCAN             ;扫描
    JNZ INK1
    JMP BEGIN
 
INK1:  
    CALL DIS
    CALL DALLY
    CALL DALLY
    CALL CLEAR
    CALL CCSCAN
    JNZ INK2                ;有键按下,转到 INK2
    JMP BEGIN
    ;确定按下键的位臵
INK2:  
    MOV CH,0FEH
    MOV CL,00H
 
COLUM:  
    MOV AL,CH
    MOV DX,MY8255_A
    OUT DX,AL
    MOV DX,MY8255_C
    IN AL,DX
L1: 
    TEST AL,01H             ;is L1?
    JNZ L2
    MOV AL,00H              ;L1
    JMP KCODE
L2: 
    TEST AL,02H             ;is L2?
    JNZ L3
    MOV AL,04H              ;L2
    JMP KCODE
L3: 
    TEST AL,04H             ;is L3?
    JNZ L4
    MOV AL,08H              ;L3
    JMP KCODE
L4: 
    TEST AL,08H             ;is L4?
    JNZ NEXT
    MOV AL,0CH              ;L4
KCODE:  
    ADD AL,CL
    CALL PUTBUF
    PUSH AX
KON: 
    CALL DIS
    CALL CLEAR
    CALL CCSCAN
    JNZ KON
    POP AX
NEXT:  
    INC CL
    MOV AL,CH
    TEST AL,08H
    JZ KERR
    ROL AL,1
    MOV CH,AL
    JMP COLUM
KERR:  
    JMP BEGIN
CCSCAN: 
    MOV AL,00H              ;键盘扫描子程序
    MOV DX,MY8255_A
    OUT DX,AL
    MOV DX,MY8255_C
    IN AL,DX
    NOT AL
    AND AL,0FH
    RET
CLEAR:  
    MOV DX,MY8255_B         ;清屏子程序
    MOV AL,00H
    OUT DX,AL
    RET
DIS: 
    PUSH AX                 ;显示子程序
    MOV SI,3000H
    MOV DL,0DFH
    MOV AL,DL
AGAIN:  
    PUSH DX
    MOV DX,MY8255_A
    OUT DX,AL
    MOV AL,[SI]
    MOV BX,OFFSET DTABLE
    AND AX,00FFH
    ADD BX,AX
    MOV AL,[BX]
    MOV DX,MY8255_B
    OUT DX,AL
    CALL DALLY
    INC SI
    POP DX
    MOV AL,DL
    TEST AL,01H
    JZ OUT1
    ROR AL,1
    MOV DL,AL
    JMP AGAIN
OUT1:  
    POP AX
    RET
DALLY:  
    PUSH CX                  ;延时子程序
    MOV CX,0006H
    T1: MOV AX,009FH
    T2: DEC AX
    JNZ T2
    LOOP T1
    POP CX
    RET
PUTBUF: 
    MOV SI,DI                ;存键盘值到相应位的缓冲中
    MOV [SI],AL
    DEC DI
    CMP DI,2FFFH
    JNZ GOBACK
    MOV DI,3005H
GOBACK: 
    RET
CODE ENDS
    END START

You may also like...

发表评论

电子邮件地址不会被公开。

This site uses Akismet to reduce spam. Learn how your comment data is processed.