DATA SEGMENT
TABLE1 DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH TABLE2 DB 0FEH,0FDH,0FBH,0F7H,0EFH,0DFH,0BFH,7FH BP DB
SI DB
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV DS,AX
MOV DX,0EEH ;A,B,C 方式0,A,C 输出,B 输入
MOV AL,10000011B
OUT DX,AL
MOV BP,00 ;BP初值设置0
CC1: CALL BB1;开始显示0
MOV DX,0ECH;读取C 口低位值
IN AL,DX
AND AL,0FH;检查开始抢答键是否按下
CMP AL,0EH
JNE CC1;没按下,跳到cc1,继续显示0
MOV CX,0FFH
MOV BP,1EH
CC2: CALL BB1;按下,开始显示1秒钟30
LOOP CC2
DEC BP;变量减一
JS CC4
MOV DX,0EAH;读取b 口值,看是否有人抢答
IN AL,DX
CMP AL,0FFH
JE CC2;没人抢,跳到cc2
CC3: MOV SI,07H
NEXT-TRY:IN AL,DX
CMP AL,TABLE2[SI];检查键值
JE DONE
DEC SI
JMP NEXT-TRY
DONE: MOV DX,0ECH;显示键值
MOV AL,0E0H
OUT DX,AL
LEA BX,TABLE1
MOV AX,SI
XLAT
MOV DX,0E8H
OUT DX,AL
CALL DELAY
CALL BB1
MOV DX,0ECH
IN AL,DX
AND AL,0FH
CMP AL,0CH
JNE DONE
CC4:MOV BP,0
CALL BB1
JMP CC4
BB1 PROC NEAR
MOV AX,BP
MOV DL,0AH
DIV DL
MOV BX,OFFSET TABLE1 XLAT
MOV DX,0E8H
OUT DX,AL
MOV AL,0B0H ;第三位显示
MOV DX,0ECH;C口高位
OUT DX,AL
CALL DELAY
MOV AL,AH
XLAT
MOV DX,0E8H
OUT DX,AL
MOV AL,70H ;第四位显
MOV DX,0ECH;C口高位
OUT DX,AL CALL DELAY RET BB1 ENDP
DELAY PROC NEAR MOV CX,00FAH T1: LOOP T1 RET
DELAY ENDP CODE ENDS
END START
|