微机系统与接口实验考试题目(2014级题目-01)
题目要求:使用X86汇编语言实现如下所述功能:
使用两位开关K6、K7和数码管,当拨动K6、k7为00时,要求将6位数码管清屏;
当拨动K6、k7为01时,在数码管第五、六显存单元显示“--|”段码;
当拨动K6、k7为10时,在数码管第一、二显存单元显示“|--”段码;
代码:
MY8255_A EQU 0600H
MY8255_B EQU 0602H
MY8255_C EQU 0604H
MY8255_CON EQU 0606H
CODE SEGMENT
ASSUME CS:CODE
START:
MOV 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 DX,MY8255_CON ;写 8255 控制字
MOV AL,89H ;A,B口输出,C口输入,用来读入开关状态
OUT DX,AL
X0:
CALL DIS
MOV DX,MY8255_C
IN AL,DX
AND AL,0C0H ;读取开关K6,K7
CMP AL,00H ;K6K7=00
JZ X1
CMP AL,40H ;K6K7=01
JZ X2
CMP AL,80H ;K6K7=10
JZ X3
CMP AL,0C0H ;K6K7=11
JZ X4
JMP X0
X1:
CALL CLRBUF ;将显存清空
JMP X0
X2:
CALL CLRBUF
MOV SI,3000H
MOV [SI],70H ;"|-"的段码放在第一个显存单元
MOV [SI+1],40H ;"-"的段码放在第二个显存单元
J2: CALL DIS
CALL CLEAR
CALL DELAY1
;CALL DELAY2
MOV DX,MY8255_C
IN AL,DX
AND AL,0C0H ;读取开关K6,K7
CMP AL,40H
JZ J2 ;如果开关状态未改变则一直循环以做到闪烁显示
JMP X0
X3:
CALL CLRBUF
MOV SI,3004H
MOV [SI],40H ;"-"的段码放在第五个显存单元
MOV [SI+1],46H ;"-|"的段码放在第六个显存单元
J3: CALL DIS
CALL CLEAR
CALL DELAY1
;CALL DELAY2
MOV DX,MY8255_C
IN AL,DX
AND AL,0C0H ;读取开关K6,K7
CMP AL,80H
JZ J3 ;如果开关状态未改变则一直循环以做到闪烁显示
JMP X0
X4:
MOV SI,3000H
MOV AL,40H
MOV [SI],AL ;将"-"的段码放在全部六个显存单元
MOV [SI+1],AL
MOV [SI+2],AL
MOV [SI+3],AL
MOV [SI+4],AL
MOV [SI+5],AL
JMP X0
CLEAR:
MOV DX,MY8255_B ;清屏子程序
MOV AL,00H
OUT DX,AL
RET
DIS:
PUSH AX ;显示子程序,作用为将六个显存中的数据依次取出并送给相应的数码管显示
MOV SI,3000H
MOV DL,7FH ;01 111111
MOV AL,DL
AGAIN:
ROL AL,1 ;选择下一个显像管
MOV DL,AL
PUSH DX
MOV DX,MY8255_A
OUT DX,AL
MOV AL,[SI] ;键号
MOV DX,MY8255_B
OUT DX,AL
CALL DELAY ;显示
INC SI ;下一个键号
POP DX
MOV AL,DL
TEST AL,20H
JZ OUT1
MOV DL,AL
JMP AGAIN
OUT1:
POP AX
RET
DELAY:
PUSH CX ;短延时子程序,用于显示子程序循环显示六个数码管
MOV CX,04FFH
T1: LOOP T1
POP CX
RET
DELAY1:
PUSH AX
PUSH CX ;长延时子程序,用于控制闪烁
MOV CX,0004H
TT1: MOV AX,0FFFFH
TT2: DEC AX
JNZ TT2
LOOP TT1
POP CX
POP AX
RET
DELAY2:
PUSH CX
MOV CX,0FFH
CLRBUF:
MOV 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
RET
CODE ENDS
END START
MY8255_A EQU 0600H
MY8255_B EQU 0602H
MY8255_C EQU 0604H
MY8255_CON EQU 0606H
CODE SEGMENT
ASSUME CS:CODE
START:
MOV 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 DX,MY8255_CON ;写 8255 控制字
MOV AL,89H ;A,B口输出,C口输入,用来读入开关状态
OUT DX,AL
X0:
CALL DIS
MOV DX,MY8255_C
IN AL,DX
AND AL,0C0H ;读取开关K6,K7
CMP AL,00H ;K6K7=00
JZ X1
CMP AL,40H ;K6K7=01
JZ X2
CMP AL,80H ;K6K7=10
JZ X3
CMP AL,0C0H ;K6K7=11
JZ X4
JMP X0
X1:
CALL CLRBUF ;将显存清空
JMP X0
X2:
CALL CLRBUF
MOV SI,3000H
MOV [SI],70H ;"|-"的段码放在第一个显存单元
MOV [SI+1],40H ;"-"的段码放在第二个显存单元
J2: CALL DIS
CALL CLEAR
CALL DELAY1
;CALL DELAY2
MOV DX,MY8255_C
IN AL,DX
AND AL,0C0H ;读取开关K6,K7
CMP AL,40H
JZ J2 ;如果开关状态未改变则一直循环以做到闪烁显示
JMP X0
X3:
CALL CLRBUF
MOV SI,3004H
MOV [SI],40H ;"-"的段码放在第五个显存单元
MOV [SI+1],46H ;"-|"的段码放在第六个显存单元
J3: CALL DIS
CALL CLEAR
CALL DELAY1
;CALL DELAY2
MOV DX,MY8255_C
IN AL,DX
AND AL,0C0H ;读取开关K6,K7
CMP AL,80H
JZ J3 ;如果开关状态未改变则一直循环以做到闪烁显示
JMP X0
X4:
MOV SI,3000H
MOV AL,40H
MOV [SI],AL ;将"-"的段码放在全部六个显存单元
MOV [SI+1],AL
MOV [SI+2],AL
MOV [SI+3],AL
MOV [SI+4],AL
MOV [SI+5],AL
JMP X0
CLEAR:
MOV DX,MY8255_B ;清屏子程序
MOV AL,00H
OUT DX,AL
RET
DIS:
PUSH AX ;显示子程序,作用为将六个显存中的数据依次取出并送给相应的数码管显示
MOV SI,3000H
MOV DL,7FH ;01 111111
MOV AL,DL
AGAIN:
ROL AL,1 ;选择下一个显像管
MOV DL,AL
PUSH DX
MOV DX,MY8255_A
OUT DX,AL
MOV AL,[SI] ;键号
MOV DX,MY8255_B
OUT DX,AL
CALL DELAY ;显示
INC SI ;下一个键号
POP DX
MOV AL,DL
TEST AL,20H
JZ OUT1
MOV DL,AL
JMP AGAIN
OUT1:
POP AX
RET
DELAY:
PUSH CX ;短延时子程序,用于显示子程序循环显示六个数码管
MOV CX,04FFH
T1: LOOP T1
POP CX
RET
DELAY1:
PUSH AX
PUSH CX ;长延时子程序,用于控制闪烁
MOV CX,0004H
TT1: MOV AX,0FFFFH
TT2: DEC AX
JNZ TT2
LOOP TT1
POP CX
POP AX
RET
DELAY2:
PUSH CX
MOV CX,0FFH
CLRBUF:
MOV 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
RET
CODE ENDS
END START