8086芯片八路抢答器仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
8086抢答器源程序如下:
- ;$CS$ $A1$ $A0$
- ; 1 1 1 控制端口
- ; 1 0 0 数据A
- ; 1 0 1 数据B
- ; 1 1 0 数据C
- C8255 EQU 306H ;0011 0000 0110b
- IPA EQU 300H ;0011 0000 0000b
- IPB EQU 302H ;0011 0000 0010b
- IPC EQU 304H ;0011 0000 0100b
- A8255 EQU 206H ;0010 0000 0110b
- APA EQU 200H ;0010 0000 0000b
- APB EQU 202H ;0010 0000 0010b
- APC EQU 204H ;0010 0000 0100b
- C8253 EQU 106H ;0001 0000 0110b
- CPA EQU 100H ;0001 0000 0000b
- CPB EQU 102H ;0001 0000 0010b
- CPC EQU 104H ;0001 0000 0100b
- data segment
- ;blank DD 255 DUP(?)
- LED DW 40H,79H,24H,30H,19H,12H,02H,78H,00H,10H
- HH DW 00H
- HL DW 00H
- LP DW 0H
- MS DW 0H
- sxh dw 0h,?,?
- sss dw 0h,?,?
- keydata db 0feh,0fdh,0fbh,0f7h,0efh,0dfh,0bfh,07fh ;0 ~ 7扫描码
- segdata db 3fh,06h,5bh,4fh,66h,6dh,7dh,07h,7fh,6fh,77h,7ch,39h,5eh,79h,71h
- flag db 0 ; 0 ~ F 对应字符代码
- zj db 00111111b
- tmp db 00111111b
- data ends
- code segment 'code' ;定义代码段
- assume cs:code,ds:data
- main proc far
-
- start:
- mov ax,data ;建立DS段地址
- mov ds,ax
- xor ax,ax
- mov es,ax
-
- mov ax,offset IT
- mov es:[8H],ax
-
- mov ax,seg IT
- mov es:[0AH],ax
-
- ;**********************************初始化C8255
- LL:
- mov dx,306H
- mov al,92h
- out dx,al
- mov dx,304h
- mov al,0FFh
- out dx,al
- ;**********************************程序初始化
- L:
- mov dx,302h
- in al,dx
- cmp al,0ffh
- jz L
- call delay10
- cmp al,011111110b ;判断是不是按下开始键
- jz L1
- jmp L
- ;**********************************复位(目前貌似没啥用了)
- L3:
- mov dx,IPC
- mov al,011000000b
- out dx,al ;数码管复位为0
-
- ;***********************************开始 数码管显示为0
- L1:
- mov dx,304h
- mov al,0c0h
- mov flag,0
- nop
- ;***********************************初始化A8255并进行按键检测
- AGAIN:
- mov dx,0206h
- mov al,92h
- out dx,al
- mov dx,0204h
- mov al,0c0h
- out dx,al
- mov dx,0302h
- in al,dx
- cmp al,7fh
- jz L3
- cmp al,0F7h
- jz LL
- mov dx,0300h
- in al,dx
- cmp al,0FFh
- jz AGAIN
- call delay10 ;延时防抖动
- in al,dx
- cmp flag,1 ;按下键后,判断flag是否为1
- jz AGAIN
- inc flag
- mov bx,0
- ;**********************************根据按下的值查表
- GKEY:
- mov ah,keydata[bx]
- cmp al,ah
- jz DISP
- inc bl
- LOOP GKEY
- ;**********************************再查表并显示抢答的一组
- DISP:
- inc bl
- mov al,segdata[bx]
- mov dx,IPC
- not al
- out dx,al
- mov tmp,al
- mov dx,IPB
- ;*********************************延时等待计时
- waits:
- call delay10
- in al,dx
- cmp al,11011111b ;判断是不是按下计时键
- jz L4
- jmp waits
- ;*********************************开始计时,计时完跳回程序最初位置
- L4:
- ;mov sss,1h
- call jishi
- ;mov sss,0h
- jmp start
- ;********************************延时循环
- loop1:
- loop $
- loop AGAIN
- main endp
- jishi proc
- ;*********************************初始化
- mov dx,A8255 ;选中控制寄存器 ***
- mov al,80H ;命令字 10000000
- out dx,al ;初始化8255
-
- mov dx,C8253 ;00010110 ;8253 ***
- mov al,00010100B
- out dx,al
-
- mov ax,03E8H
- mov dx,CPA ;****
- mov al,0H
- out dx,al
- mov dx,C8253 ;001000 *****
- mov al,00100100B
- out dx,al
- mov dx,CPA ;001000 ******
- mov al,ah
- out dx,al
- mov dx,APC ; ****
- mov al,00010000B
- out dx,al
- mov HH,00H
- mov HL,06H
- ;********************************初始赋值
- LOP1:
- mov ah,00000010B
- mov LP,0
- ;********************************数码管计数的显示
- LSP:
-
- mov bx,offset HH
- mov ax,LP
- xlat
- mov bx,offset LED
- xlat
-
- mov dx,APB ; *****
- out dx,al
- mov dx,APA ; *****
- mov al,ah
- out dx,al
- mov dx,APA ; *****
- mov al,0H
- out dx,al
- shr ah,1
- inc LP
- cmp ah,0H
- jz LOP1
- loop LSP
- ire:
- ret
- jishi endp
- IT proc
- ;********************************计时100ms
- inc MS
- cmp MS,64H
- jne re
- mov MS,0H
- jmp ad
- ;********************************秒的第二位减为0时重新赋值为9
- init:
- mov HH,0aH
- DEC HL
- jmp ad
- ;*******************************倒计时计数 C8255实时显示抢答组号
- ad:
- push dx
- push ax
- push bx
- push cx
- mov dx,C8255 ;0111 0000 0000b,8255A控制端口地址
- mov al,92H ;10010010b,方式选择字:PA,PB输入、PC输出
- out dx,al
- mov al,tmp
- mov dx,IPC
- out dx,al
- pop cx
- pop bx
- pop ax
- pop dx
- out dx,al
- mov dx,IPB
- in al,dx
- cmp sxh,1h
- jz start
- cmp HL,0
- JZ out1
- cmp HH,0
- jz init
- jmp oend
- ;******************************计数判断以及跳转
- oend:
- DEC HH
- cmp HH,00H
- jne re
- cmp HL,00H
- jz out2
-
- cmp HL,00H
- jz re
- jmp re
- out1:
- cmp HH,0
- jnz oend
- jmp ire
- out2:
- mov HH,0
- MOV HL,0
- re:
- iret
- IT endp
- delay10 proc
- mov cx,8820
- loop $
- ret
- delay10 endp ;延时
- code ends ;代码段结束
- end start
复制代码
所有资料51hei提供下载:
基于8086的八路抢答器.7z
(63.4 KB, 下载次数: 151)
|