这是我上微机原理课时写过的一些8086 Proteus仿真设计,分享给大家。
汽车车灯系统设计: 用四个发光二极管分别模拟车头左右灯和车尾左右灯。用五个按键控制五个状态:左转、右转、刹车、双闪、夜车。 左转:(判断状态:日间、夜间) (1)左灯闪烁(0.5s)(日间) (2)左灯双闪(0.5s)后闪烁(0.5s)(夜间) 左转:(判断状态:日间、夜间) (1)右灯闪烁(0.5s)(日间) (2)右灯双闪(0.5s)后闪烁(0.5s)(夜间) 刹车:(判断状态:日间、夜间) (1)所有灯常亮(0.5s)(日间) (2)所有灯双闪(0.5s)后闪烁(0.5s)(夜间) 双闪:所有灯闪烁两次(0.5s) 夜车:所有灯常亮
程序:
- ;;;===汽车尾灯设计===;;;
- ;定义8255的地址
- PA8255 EQU 0200H
- PB8255 EQU 0202H
- PC8255 EQU 0204H
- CON8255 EQU 0206H
- ;定义8253的部分地址
- P8253T0 EQU 0400H
- P8253CON EQU 0406H
- STACK SEGMENT
- STK DB 200 DUP(0)
- TOP DW $-STACK
- STACK ENDS
- CODE SEGMENT
- ASSUME CS:CODE,SS:STACK
- START:
-
- MOV DX,STACK
- MOV SS,DX
- MOV SP,TOP
- ;8255初始化
- MOV AL,82H ;1000 0010
- MOV DX,CON8255
- OUT DX,AL
- MOV DX,PA8255
- MOV AL,0FFH
- OUT DX,AL
- ;;;===每种状态输出对应的数据===
- ;;;===例如(0200H)=1111 0101 左转时,先是前后左灯亮0.5s
- ;;;===然后灯全灭0.5s。高四位保存全灭状态,低四位保存前后左灯亮状态
- ;;;===所以左转时,只要把 (0200H)=1111 0101左移四位即可。
- MOV SI,0200H
- MOV AL,0FAH
- MOV [SI],AL
- MOV [SI+1],0F5H
- MOV [SI+2],0F0H
- MOV [SI+3],00H
- MOV [SI+4],50H
- MOV [SI+5],0A0H
- BEGIN:
- MOV DX,PB8255
- IN AL,DX
- AND AL,1FH
- CMP AL,1EH
- JZ NEXT1 ;左转
- CMP AL,1DH
- JZ NEXT2 ;右转
- CMP AL,1BH
- JZ NEXT3 ;双闪
- CMP AL,17H
- JZ NEXT4 ;刹车
- CMP AL,0FH
- JZ NEXT5 ;夜间
- CMP AL,0EH
- JZ NEXT6 ;夜间+左转
- CMP AL,0DH
- JZ NEXT7 ;夜间+右转
-
- INIT:
- MOV DX,PA8255
- MOV AL,0FFH
- OUT DX,AL
- JMP BEGIN
- NEXT1:
- CALL LEFT
- JMP BEGIN
- NEXT2:
- CALL RIGHT
- JMP BEGIN
- NEXT3:
- CALL SHUAN_SHAN
- JMP BEGIN
- NEXT4:
- CALL SHA_CHE
- JMP BEGIN
- NEXT5:
- CALL NIGHT
- JMP BEGIN
- NEXT6:
- CALL NIGHT_LEFT
- JMP BEGIN
- NEXT7:
- CALL NIGHT_RIGHT
- JMP BEGIN
- ;;;===左转右转等子程序
- LEFT PROC
- MOV DX,PA8255
- MOV AL,[SI]
- OUT DX,AL
- CALL DELAY
- ROL AL,4
- MOV [SI],AL
- RET
- LEFT ENDP
- RIGHT PROC
- MOV DX,PA8255
- MOV AL,[SI+1]
- OUT DX,AL
- CALL DELAY
- ROL AL,4
- MOV [SI+1],AL
- RET
- RIGHT ENDP
- SHUAN_SHAN PROC
- MOV DX,PA8255
- MOV AL,[SI+2]
- OUT DX,AL
- CALL DELAY
- ROL AL,4
- MOV [SI+2],AL
- RET
- SHUAN_SHAN ENDP
- SHA_CHE PROC
- MOV DX,PA8255
- MOV AL,[SI+3]
- OUT DX,AL
- CALL DELAY
- ROL AL,4
- MOV [SI+3],AL
- RET
- SHA_CHE ENDP
- NIGHT PROC
- MOV DX,PA8255
- MOV AL,[SI+3]
- OUT DX,AL
- CALL DELAY
- ROL AL,4
- MOV [SI+3],AL
- RET
- NIGHT ENDP
- NIGHT_LEFT PROC
- MOV DX,PA8255
- MOV AL,[SI+4]
- OUT DX,AL
- CALL DELAY
- ROL AL,4
- MOV [SI+4],AL
- RET
- NIGHT_LEFT ENDP
- NIGHT_RIGHT PROC
- MOV DX,PA8255
- MOV AL,[SI+5]
- OUT DX,AL
- CALL DELAY
- ROL AL,4
- MOV [SI+5],AL
- RET
- NIGHT_RIGHT ENDP
- ;;;===延时程序
- DELAY PROC
- PUSH AX
- MOV AL,10H ;0001 0000,8位计数器,方式0,BCD码计数
- MOV DX,P8253CON ;写入工作方式控制字
- OUT DX,AL
- MOV AL,5H ;给T0赋初值
- MOV DX,P8253T0
- OUT DX,AL
-
- L2:
- MOV DX,PB8255
- IN AL,DX
- AND AL,20H
- CMP AL,00H
- JZ L2
- POP AX
- RET
- DELAY ENDP
- CODE ENDS
- END START
复制代码
可控时间间隔流水灯仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- ;;;=== Create By XuHe 2018 1.18 ===;;;
- ;;;===可加速、减速流水灯===;;;
- ;;;===初始时,时间间隔为一秒,按加速键加速
- ;;;===按减速键减速
- ;定义8255的地址
- PA8255 EQU 0200H
- PB8255 EQU 0202H
- PC8255 EQU 0204H
- CON8255 EQU 0206H
- ;定义8253的部分地址
- P8253T2 EQU 0404H
- P8253CON EQU 0406H
- STACK SEGMENT
- STK DB 200 DUP(0)
- TOP DW $-STACK
- STACK ENDS
- CODE SEGMENT
- ASSUME CS:CODE,SS:STACK
- START:
-
- MOV DX,STACK
- MOV SS,DX
- MOV SP,TOP
- ;8255初始化
- MOV AL,82H
- MOV DX,CON8255
- OUT DX,AL
-
- MOV SI,0200H
- MOV AL,0AH
- MOV [SI],AL
- MOV AL,7FH
- BEGIN:
- CALL DISPLAY
- PUSH AX
- MOV DX,PB8255
- IN AL,DX
- AND AL,02H
- CMP AL,00H
- JNZ NEXT
- MOV AL,[SI]
- DEC AL
-
- CMP AL,0
- JZ NEXT
- MOV [SI],AL
- NEXT:
- MOV DX,PB8255
- IN AL,DX
- AND AL,04H
- CMP AL,00H
- JNZ NEXT1
- MOV AL,[SI]
- INC AL
-
- CMP AL,14H
- JZ NEXT1
- MOV [SI],AL
- NEXT1:
- POP AX
- JMP BEGIN
- DISPLAY PROC
- L1:
-
- MOV DX,PA8255
- OUT DX,AL
- CALL DELAY
- ROL AL,1
-
- RET
- DISPLAY ENDP
-
- DELAY PROC
- PUSH AX
-
- MOV AL,90H ;1001 0000,8位计数器,方式0,BCD码计数
- MOV DX,P8253CON ;写入工作方式控制字
- OUT DX,AL
- MOV SI,0200H
- MOV AL,[SI] ;给T0赋初值
- MOV DX,P8253T2
- OUT DX,AL
-
- L2:
- MOV DX,PB8255
- IN AL,DX
- CMP AL,0FEH
- JZ L2
-
- POP AX
-
- RET
- DELAY ENDP
- CODE ENDS
- END START
复制代码
所有资料51hei提供下载:
|