简单IO接口作业
程序员文章站
2022-07-14 23:06:07
...
当只有最上面的开关为ON,8个LED灯全亮;
当只有最下面的开关为ON,中间4个LED灯亮;
当开关全部为ON,8个LED灯闪烁发光;
当开关为其余状态时,所有的LED灯全灭。
OUT373 EQU 0FF80H
IN245 EQU 0FF80H
CODE SEGMENT
ASSUME CS:CODE
START:
MOV DX,IN245
IN AL,DX
CMP AL,11111110B;当只有最上面的开关为ON,8个LED灯全亮;
JNZ A2
MOV AL,11111111B;........................8个LED灯全亮;
JMP A1
A2: CMP AL,01111111B;当只有最下面的开关为ON,中间4个LED灯亮;
JNZ A3
MOV AL,00111100B;........................中间4个LED灯亮;
JMP A1
A3: CMP AL,00000000B;当开关全部为ON,8个LED灯闪烁发光;
JNZ A4
JMP A5
A4: MOV AL,00000000B;当开关为其余状态时,所有的LED灯全灭。
JMP A1
A5: MOV CX,4;................8个LED灯闪烁发光;
MOV AL,01010101B
AG: NOT AL
MOV DX,OUT373
OUT DX,AL
call delay;延时函数
LOOP AG
A1: MOV DX,OUT373
OUT DX,AL
call delay
JMP START
delay: push dx
push ax
mov dx, 02H
mov ax, 0
s1: sub ax, 1;-1的反码是65535
sbb dx, 0;此时CF寄存器是1,则dx-1
cmp ax, 0;内循环
jne s1
cmp dx, 0;外循环
jne s1
pop ax
pop dx
ret
CODE ENDS
END START