利用8086和8255设计一个霓虹灯
仿真图,
CODE SEGMENT
ASSUME CS:CODE
IOCONPT EQU 0073H
IOAPT EQU 0070H
IOBPT EQU 0071H
IOCPT EQU 0072H
IOBDATA EQU 0500H
CONTPORT EQU 00DFH
DATAPORT EQU 00DEH
DATA1 EQU 0640H
START: JMP IOLED
IOLED: CALL FORMAT
CALL LEDDISP
MOV AX,0H
MOV DS,AX
MOV AL,82H
MOV DX,IOCONPT
OUT DX,AL
MOV DX,IOBPT
IN AL,DX
MOV BYTE PTR DS:[0501H],AL
MOV DX,IOCONPT
MOV AL,80H
OUT DX,AL
;只用C口
;L1--L8对应PC7--PC0
;(1)L1--L8闪烁四次
VV: MOV CX,4H ;设置8个灯闪烁次数
LEDSTART:MOV DX,IOCPT
MOV AL,00H ;点亮L1--L8
OUT DX,AL
CALL DELAY2
MOV DX,IOCPT
MOV AL,0FFH
OUT DX,AL ;L1--L8灯灭
CALL DELAY2
LOOP LEDSTART
CALL DELAY1 ;循环(L1--L8闪烁4次)
;(2)单灯流水(右四次,左四次,两边到中间四次)
MOV CX,4H
LED01 : MOV DX,IOCPT
MOV AL,7FH ;AL=0111 1111 B即点亮L1
OUT DX,AL
CALL DELAY2
AA: ROR AL,1 ;AL=1011 1111 B即点亮L2
OUT DX,AL
CALL DELAY2
CMP AL,80H
JA AA ;当循环右移AL的最高位再次为0时跳出循环
LOOP LED01
CALL DELAY1
MOV CX,4H
LED02: MOV DX,IOCPT
MOV AL,0FEH ;AL=1111 1110 B即点亮L8
OUT DX,AL
CALL DELAY2
BB: ROL AL,1 ;AL=1111 1101 B即点亮L7
OUT DX,AL
CALL DELAY2
CMP AL,80H
JA BB ;当循环左移AL的最高位再次为0时跳出循环
LOOP LED02 ;单灯向左流水点亮4次
CALL DELAY1
MOV CX,4H
LED03: MOV DX,IOCPT
MOV AH,0FFH ;AH=1111 1111B
MOV BH,AH ;BH=1111 1111B
SHR AH,1 ;AH=0111 1111B
MOV BL,AH
SHL BH,1 ;BH=1111 1110 B
AND AH,BH
MOV AL,AH ;AL=0111 1110 B
MOV AH,BL
OUT DX,AL ;点亮L1和L8
CALL DELAY2
CC: ROR AH,1 ;AH=1011 1111 B
MOV BL,AH
ROL BH,1 ;BH=1111 1101 B
AND AH,BH
MOV AL,AH ;AL=1011 1101 B
MOV AH,BL
OUT DX,AL ;点亮L2和L7
CALL DELAY2
CMP AL,80H
JA CC ;当AL的最高位为0时跳出循环
LOOP LED03 ;双灯相向移动4次
CALL DELAY1
MOV CX,7H
LED04: MOV DX,IOCPT
MOV AH,6DH ;AH=0110 1101 B L1、L4、L7 点亮
FF: CALL DD1 ;调用DD使L1、L4、L7 闪烁4下
ROR AH,1 ;AH=1011 0110 B L2、L5、L8 点亮
LOOP FF ;调用DD使L2、L5、L8 闪烁4下
;最终效果是
;L1、L4、L7闪烁4下(0110 1101 B )
;L2、L5、L8闪烁4下(1011 0110 B )
;L3、L6、L1闪烁4下(0101 1011 B )
;L4、L7、L2闪烁4下(1010 1101 B )
;L5、L8、L3闪烁4下(1101 0110 B )
;L6、L1、L4闪烁4下(0110 1011 B )
;L7、L2、L5闪烁4下(1011 0101 B )
;L8、L3、L6闪烁4下 到此为一个循环
;该循环一共进行4次
CALL DELAY1
JMP VV
DD1: PUSH CX
MOV CX,4H
EE: MOV AL,AH
OUT DX,AL ;AL=AH,点亮三个灯
CALL DELAY2
MOV AL,0FFH ;关掉三个灯
OUT DX,AL
CALL DELAY2
LOOP EE ;三个灯闪烁4次后跳出循环
POP CX
RET
DELAY1: PUSH AX
PUSH CX
MOV CX,0030H
DELY2: CALL DELAY2
LOOP DELY2
POP CX
POP AX
RET
DELAY2: PUSH CX
MOV CX,8000H
DELA1: LOOP DELA1
POP CX
RET
LEDDISP:MOV AL,90H
MOV DX,CONTPORT
OUT DX,AL
MOV BYTE PTR DS:[0600H],00
LED1: CMP BYTE PTR DS:[0600H],07H
JA LED2
MOV BL,DS:[0600H]
MOV BH,0H
MOV AL,CS:[BX+DATA1]
MOV DX,DATAPORT
OUT DX,AL
ADD BYTE PTR DS:[0600H],01H
JNZ LED1
LED2: RET
FORMAT: MOV BX,0
MOV WORD PTR DS:[BX+0640H],405BH
ADD BX,2
MOV WORD PTR DS:[BX+0640H],4040H
ADD BX,2
MOV WORD PTR DS:[BX+0640H],6D6DH
ADD BX,2
MOV WORD PTR DS:[BX+0640H],7F5BH
RET
CODE ENDS
END START
一周热门 更多>