微机原理课程设计-电子钟标准版 第2页
MOV CL,00H ;有键,识别按键,CL为列计数器
MOV BL,0feH ;第0列
LK4: MOV AL,BL
MOV DX,PORT2
OUT DX,AL
MOV DX,PORT2
IN AL,DX
NOT AL
AND AL,0FH ;结果为行值
JNZ KEYDOWN ;此列有键按下,计算键值
NEXT: INC CL ;扫描下一列
TEST BL,08H
JZ WT
ROL BL,1
JMP LK4
KEYDOWN:
MOV BX,0
CMPROW: CMP AL,ROW[BX]
JZ KEY/////////////////////////////////////////////////////stop
INC BX
JMP CMPROW
KEY: IMUL BX,3
mov ah,0
ADD CL,BL
mov al,cl
cmp al,10
jnz goto1
cmp stop,0
jnz p1
mov stop,1
jmp goto2
p1: mov stop,0
jmp goto2
goto1: cmp al,11
jnz goto2
mov stop,0
mov step,1
aga1: call input
cmp step,1
ja cmp2
mov ax,time
imul ax,10
mov hour,ax
inc step
jmp aga1
cmp2: cmp step,2
ja cmp3
mov ax,time
add hour,ax
inc step
jmp aga1
cmp3: cmp step,3
ja cmp4
mov ax,time
imul ax,10
mov min,ax
inc step
jmp aga1
cmp4: cmp step,4
ja cmp5
mov ax,time
add min,ax
inc step
jmp aga1
cmp5: mov step,0
mov stop,1
goto2: jmp aga
;////////////////////////////////////////////////////////////////中断程序
interupt proc far
push ax
push bx
push cx
push dx
lea bx,tab
;显示秒
mov cx,sec
mov ax,cx
div c10
mov dx,porta3
push ax
mov ah,0
xlat
out dx,al
pop ax
mov dx,portb3
mov al,0
xchg ah,al
xlat
out dx,al
;分钟
mov cx,min
mov ax,cx
div c10
mov dx,porta2
push ax
mov ah,0
xlat
out dx,al
pop ax
mov dx,portb2
mov al,0
xchg ah,al
xlat
out dx,al
;小时
mov cx,hour
mov ax,cx
div c10
mov dx,porta1
push ax
mov ah,0
xlat
out dx,al
pop ax
mov dx,portb1
mov al,0
xchg ah,al
xlat
out dx,al