Yasin DEMİR

#herseypaylasmakicin

———————————————————————————————————

Assembly ile Paralel Porttan Stepper Motor Kontrolü

———————————————————————————————————

.
Problem: Paralel port üzerinden bir step motor kontrol etmek. Step motor bir bilgisayara paralel port ile bağlı olacak ve klavye üzerinden kullanıcı tarafından kontrol edilecektir.
Kullanılacak Tuşlar:
R: saat yönünde dönen için
L: saatin tersi yönde dönen için
F: hızlı dönen için
S: yavaş dönen için
D: durdurma için

.

Turbo Assembler i buradan indirebilirsiniz.

Xp ve üzeri işletim sistemlerinde Portlar kapatıldığı için UserPort programı ile portu açmanız gerekli.

clrscr macro
push ax
push bx
push cx
push dx
mov ax,0600h
mov bh,07h
mov cx,00000
mov dx,184fh
int 10h
pop dx
pop cx
pop bx
pop ax
endm

setcrsr macro data
push ax
push bx
push dx
mov ah,02h
mov bh,00
mov dx,data
int 10h
pop dx
pop bx
pop ax
endm

writemsg macro data
push ax
push bx
push dx
mov ah,09h
mov bh,00
mov dx,offset data
int 21h
pop dx
pop bx
pop ax
endm

Fastm Macro
local l1
push cx
mov cx,1000
l1:    loop l1
pop cx
endm

Slowm Macro
local l1
push cx
mov cx,10000
l1:    loop l1
pop cx
endm

rorm macro
push cx
mov cl,1
ror al,cl
pop cx
endm

rolm macro
push cx
mov cl,1
rol al,cl
pop cx
endm

menum macro data1,data2,data3,data4,data6,data7
clrscr
setcrsr 0101H
writemsg data1
setcrsr 0101H
writemsg data7
setcrsr 0301H
writemsg data2
setcrsr 0401H
writemsg data3
setcrsr 0501H
writemsg data4
setcrsr 0601H
writemsg data6
endm

Right macro data1,data2,data3,data4,data6,data7
local Fast,Slow,Exit

menum data1,data2,data3,data4,data6,data7
mov bl,99H
mov dx,0378H

mov ah,01h
mov bh,00
int 21h

cmp al,’F’
je Fast
cmp al,’f’
je Fast
cmp al,’S’
je Slow
cmp al,’s’
je Slow
cmp al,’D’
je Exit
cmp al,’d’
je Exit

Fast:    mov al,bl
out dx,al
rorm
mov bl,al
Fastm
mov ah,01h
int 16h
jz Fast
mov ah,00h
int 16h

cmp al,’S’
je Slow
cmp al,’s’
je Slow
cmp al,’D’
je Exit
cmp al,’d’
je Exit
jmp Fast

Slow:    mov al,bl
out dx,al
rorm
mov bl,al
Slowm
mov ah,01h
int 16h
jz Slow
mov ah,00h
int 16h

cmp al,’F’
je Fast
cmp al,’f’
je Fast
cmp al,’D’
je Exit
cmp al,’d’
je Exit
jmp Fast

Exit:
endm

Left macro data1,data2,data3,data4,data6,data7
local Fast,Slow,Exit

menum data1,data2,data3,data4,data6,data7
mov bl,99H
mov dx,0378H

mov ah,01h
mov bh,00
int 21h

cmp al,’F’
je Fast
cmp al,’f’
je Fast
cmp al,’S’
je Slow
cmp al,’s’
je Slow
cmp al,’D’
je Exit
cmp al,’d’
je Exit

Fast:    mov al,bl
out dx,al
rolm
mov bl,al
Fastm
mov ah,01h
int 16h
jz Fast
mov ah,00h
int 16h

cmp al,’S’
je Slow
cmp al,’s’
je Slow
cmp al,’D’
je Exit
cmp al,’d’
je Exit
jmp Fast

Slow:    mov al,bl
out dx,al
rolm
mov bl,al
Slowm
mov ah,01h
int 16h
jz Slow
mov ah,00h
int 16h

cmp al,’F’
je Fast
cmp al,’f’
je Fast
cmp al,’D’
je Exit
cmp al,’d’
je Exit
jmp Fast

Exit:
endm

.model small
.stack 64H
.data
msg1 db ‘-STEPPER MOTOR CONTROLLER WITH LTP-$’
msg2 db ‘          -MAIN MENU-$’
msg3 db ‘     1. Press R & r for Right$’
msg4 db ‘     2. Press L & l for Left$’
msg5 db ‘     3. Press D & d for Terminate The Program$’
msg6 db ‘     1. Press S & s for Slow Motion$’
msg7 db ‘     2. Press F & f for Fast Motion$’
msg8 db ‘     3. Press D & d for Turn Back Main Menu$’
msg10 db ‘     Press Here ==> $’
msg11 db ‘     -You can Change your motion when running-$’

.code
main:    mov ax,@data
mov ds,ax

again:        clrscr
setcrsr 0101H
writemsg msg1
setcrsr 0201H
writemsg msg2
setcrsr 0301H
writemsg msg3
setcrsr 0401H
writemsg msg4
setcrsr 0501H
writemsg msg5
setcrsr 0601H
writemsg msg10

mov ah,01h
mov bh,00
int 21h
cmp al,’R’
je l1
cmp al,’r’
je l1
cmp al,’L’
je l2
cmp al,’l’
je l2
cmp al,’D’
je exit
jmp exit
cmp al,’d’
je exit
l1:        call RR
l2:        call LL
jmp again
exit:
mov ah,4ch
int 21h

RR:
Right msg1,msg6,msg7,msg8,msg10,msg11
RET

LL:
Left msg1,msg6,msg7,msg8,msg10,msg11
RET
end main