各位大神们,帮忙修改下这个程序,就此谢过
.model small.586
.stack
.data
p8255a=288h ;A口地址
p8255b=p8255a+1 ;B口地址
p8255c=p8255a+2 ;C口地址
p8255Ctrl=p8255a+3 ;控制口地址
p8254a=280h ;通道0地址
p8254b=p8254a+1 ;通道1地址
p8254c=p8254a+2 ;通道2地址
p8254Ctrl=p8254a+3 ;控制口地址
msg db 'Press anykey to Exit',0dh,0ah,'$'
.code
main proc
mov ax,@data
mov ds,ax ;建立数据段
mov dx,offset msg
mov ah,09h ;显示字符串
int 21h
call init8255
call Appmain
mov ah,4ch ;返回DOS
int 21h
ret
main endp
init8255 proc
mov dx,p8255Ctrl ;控制口地址
mov al,8ah ;设置8255为B,C口输入,A为输出
out dx,al ;控制字:10001010B
ret
init8255 endp
Appmain proc
mov dx,p8255b ;检测B口状态
in al,dx
mov cl,al
test:mov cl,al
cmp al,01h
jnz judge1
initk0:mov dx,p8254Ctrl ;初始化计数器0,1,实现定时0.5s
mov al,36h
out dx,al
mov dx,p8254a
mov ax,500
out dx,al
mov al,ah
out dx,al
mov dx,p8254Ctrl
mov al,76h
out dx,al
mov dx,p8254b
mov ax,1000
out dx,al
mov al,ah
out dx,al
mov bl,80h ;点亮L7
change:mov dx,p8255a
mov al,bl
out dx,al ;输出
next:mov dx,p8255c
in al,dx
and al,80h
jnz hight ;判断是否c口为下降沿
cmp ah,1
jnz next
mov ah,0
jmp x
hight:mov ah,1
jmp next
x:
mov dl,0ffh ;直接控制台IO,相当于C中while(!kbhit())
mov ah,06h ;等待按键
int 21h ;al=输入字符
jnz done ;若无按键,则继续
mov al,bl
cmp al,01h ;判断是否到达L0
jz change1
mov dx,p8255a
out dx,al ;输出
ror bl,2
mov dx,p8255b ;检测B口状态
in al,dx
cmp al,cl
jnz test
jmp next
change1:mov dx,p8255a
mov al,bl
out dx,al ;输出
next1:mov dx,p8255c
in al,dx
and al,80h
jnz hight1 ;判断是否c口为下降沿
cmp ah,1
jnz next1
mov ah,0
jmp out1
hight1: mov ah,1
jmp next1
out1:
;mov dx,offset msg
;mov ah,09h ;显示字符串
;int 21h
mov dl,0ffh ;直接控制台IO,相当于C中while(!kbhit())
mov ah,06h ;等待按键
int 21h ;al=输入字符
jnz done ;若无按键,则继续
mov al,bl
cmp al,80h
jz change
mov dx,p8255a
out dx,al ;输出
rol bl,1
mov dx,p8255b ;检测B口状态
in al,dx
cmp al,cl
jnz test
jmp next1
judge1:cmp al,02h
jnz judge2
initk1:mov dx,p8254Ctrl ;初始化计数器0,1,实现定时1s
mov al,36h
out dx,al
mov dx,p8254a
mov ax,100
out dx,al
mov al,ah
out dx,al
mov dx,p8254Ctrl
mov al,76h
out dx,al
mov dx,p8254b
mov ax,10000
out dx,al
mov al,ah
out dx,al
mov bl,80h ;点亮L7
jmp next
judge2:cmp al,04h
jnz judgeelse
judgeelse:
mov dx,p8254Ctrl ;初始化计数器0,1,实现定时1s
mov al,36h
out dx,al
mov dx,p8254a
mov ax,100
out dx,al
mov al,ah
out dx,al
mov dx,p8254Ctrl
mov al,76h
out dx,al
mov dx,p8254b
mov ax,10000
out dx,al
mov al,ah
out dx,al
mov bl,80h ;点亮L7
jmp next
initk2:mov dx,p8254Ctrl ;初始化计数器0,1,实现定时1.5s
mov al,36h
out dx,al
mov dx,p8254a
mov ax,1500
out dx,al
mov al,ah
out dx,al
mov dx,p8254Ctrl
mov al,76h
out dx,al
mov dx,p8254b
mov ax,1000
out dx,al
mov al,ah
out dx,al
mov bl,80h ;点亮L7
jmp next
done:
ret
Appmain endp
end main