直流电机控制实验
- 格式:doc
- 大小:18.50 KB
- 文档页数:3
dispc macro c
mov dl,c
mov ah,2
int 21h
endm
disps macro s
mov ah,9
lea dx,s
int 21h
endm
datas segment
x db 150
s1 db 'n=$'
s2 db 'q/m$'
datas ends
codes segment
assume cs:codes,ds:datas
go: mov ax,datas
mov ds,ax;段地址填装
mov al,90h
mov dx,0c013h
out dx,al;8255控制字
l1: mov al,x
mov dx,0c020h;0832初值+-
out dx,al
mov al,10110000b
mov dx,0c003h;写8253的控制字,2#通道,先写低八位再写高八位
out dx,al
mov aX,1000
mov dx,0c002h
out dx,al;先写低八位
mov al,ah
out dx,al;写高八位
call delay
mov dx,0c002h
in al,dx;读2#通道的值
mov bl,al
in al,dx
mov bh,al;将AX中的剩余值给BX
mov ax,1000
sub ax,bx
mov bx,10
mul bx;电机的转速r/min
push ax
mov ah,2
mov bh,0
mov dh,12
mov dl,35
int 10h;置光标到12行35列
disps s1;显示n=
pop ax
mov bx,1000
mov dx,0
div bx
push dx
or al,30h
dispc al;显示千位
pop ax
mov bl,100
div bl
push ax
or al,30h
dispc al;显示百位
pop ax
mov al,ah
aam;十进制调整
or ax,3030h
push ax
dispc ah;显示十位
pop ax
dispc al;显示个位
disps s2;显示单位q/m
mov ah,6
mov dl,0ffh
int 21h;不等待接收单字符
cmp al,1bh;比较是否为ESC键
jne l3
mov ah,4ch
int 21h;不为ESC键则退出
l3: cmp al,'+'
jne l4
cmp x,255
je l4
add x,5
jmp l1
l4: cmp al,'-'
jne l5
cmp x,125
je l5
sub x,5
l5: jmp l1
delay proc
mov dx,0c003h
mov al,25h
out dx,al
mov al,61h
out dx,al
mov al,10h
mov dx,0c000h
out dx,al
mov dx,0c001h
out dx,al
mov dx,0c010h
d1: in al,dx
test al,1
jz d1
ret
delay endp
codes ends
end go