大三完成的硬件课设,在其中遇到的一些困难和解决方法抽出寒假没事做做总结,希望可以帮到:
proteus仿真软件的使用:
实验箱的连接图
仿真图
DATA SEGMENT
NUMS DB 3FH,06H,5BH,4FH,66h,6dh,7dh,07h,7fh,6fh,79H ;
;SELECT_OUTSMG1 DB 0H, 0FEH, 0FDH, 0FBH, 0F7H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,SS:SSTACK
START:
MOV AX,DATA
MOV DS,AX
MOV AX,SSTACK
MOV SS,AX
MOV DX, MY8255_MODE
MOV AL, 81H ;1000 0001 表示A口B口C口高四位输出,C口低4位为输入
OUT DX, AL ;控制字送控制寄存器
MOV BX,0 ;清零
CTRL:
MOV AH,0 ;AX的高8位清零
MOV DX ,MY8255_C
IN AL,DX ;C口值送AL,进行输入
TEST AL,00000001B ;AL是否等于1,进行and操作,影响标志位
JNZ T1 ;若AL为XXXX XXX1,跳T1
TEST AL, 00000010B
JNZ T2 ;若AL为XXXX XX1X,跳T2
TEST AL, 00000100B
JNZ T3 ;若AL为XXXX X1XX,跳T3
TEST AL,00001000B
JNZ T4 ;若AL为XXXX 1XXX,跳T4
MOV CX ,0000H ;CX送0
JMP A1
L1:
MOV CX ,0000H ;CX送0
JMP A1
T1:
MOV CX,15 ;CX送10
MOV DX ,MY8255_C
MOV AL,00010000B ;
out DX, AL ;将AL的值给C口
JMP A1
T2:
MOV CX,25 ;CX送20
MOV DX ,MY8255_C
MOV AL,00100000B
OUT DX, AL
JMP A1
T3:
MOV CX,35
MOV DX ,MY8255_C
MOV AL,01000000B
OUT DX, AL
JMP A1
T4:
MOV CX,45 ;CX送60
MOV DX ,MY8255_C
MOV AL,10000000B
OUT DX, AL
JMP A1
A1:
CMP BX,CX
JNZ AMD ;ZF=0,跳AMD
CMP BX,0
JE CWT ;ZF=1,跳CWT
AMD:
CMP CX,BX
JB ASD ;CX小于BX,跳ASD
CALL PRINT1 ;执行子程序,会返回
JMP CTRL
ASD:
CALL PRINT2
JMP CTRL
CWT:
CALL PRI
JMP CTRL
PRINT1 PROC
;因为每次只能亮1个的原因,所以要call多次实现肉眼错觉
CALL PRI
INC BX
CMP BX,CX
JB PRINT1
MOV BX,CX
RET
PRINT1 ENDP
PRINT2 PROC
CALL PRI
DEC BX
CMP CX,BX
JB PRINT2
MOV BX,CX
RET
PRINT2 ENDP
PRI PROC
PUSH CX
PUSH DX
PUSH AX
PUSH BX
MOV AX,BX
MOV BX,0
;MOV AX,BX
MOV CL,10
DIV CL
MOV CX,0
MOV CX,0000000000111110B ;0000 1110b,就是设置第一个亮
MOV BL,AL
CALL YANSHI
CALL HUA
CALL YANSHI
MOV BL,AH
MOV CX,0000000000111101B ;0000 1101b,就是设置第二个亮
CALL HUA
CALL YANSHI
MOV CX,0000000000111011B ;0000 1011b,就是设置第三个亮
MOV BL,AL
CALL HUA
CALL YANSHI
POP BX
POP AX
POP DX
POP CX
RET
PRI ENDP
HUA PROC
PUSH BX
PUSH AX
;控制第XXX灯亮
MOV DX,MY8255_B
MOV AX,CX
OUT DX,AX ;B口输出CX
;输出值到数码管
MOV BH,0
MOV DX,MY8255_A
MOV SI,OFFSET NUMS
MOV AX,[SI+BX]
OUT DX,AX ;A口输出BX,也就是NUMS[BX]
POP AX
POP BX
RET
HUA ENDP
YANSHI PROC
PUSH CX
MOV CX,1000
YS:
CALL YANSHI2
DEC CX
JNZ YS
POP CX
RET
YANSHI ENDP
YANSHI2 PROC
PUSH CX
MOV CX,1
TYUY:
DEC CX
JNZ TYUY
POP CX
RET
YANSHI2 ENDP
CODE ENDS
END START