Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

I Bài toán code giải quyết:

; this is an example of out instruction.

; it writes values to virtual i/o port

; that controls the stepper-motor.

; c:\emu8086\devices\stepper_motor.exe is on port 7

#start=stepper_motor.exe# ;khoi tao thu muc stepper

name "stepper" ;khoi tao ten

#make_bin# ;dinh loai du lieu dau ra cho tep

steps_before_direction_change = 20h ; 32 (decimal) ;dong co truoc khi thay doi

jmp start ;nhay khong dieu kien

; ========= data =============== ;du lieu nhi phan

; bin data for clock-wise ;du lieu nhi phan quay theo chieu kim dong ho

; half-step rotation: ;quay nua buoc

datcw db 0000_0110b ;nam cham 1 va 2 bat

db 0000_0100b ;nam cham 2 bat

db 0000_0011b ;nam cham 0 a 2 bat

db 0000_0010b ;nam cham 1 bat

; bin data for counter-clock-wise ;du lieu nhi phan quay nguoc chieu kim dong ho

; half-step rotation: ;quay nua buoc

datccw db 0000_0011b ;nam cham 0 va 1 bat

db 0000_0001b ;nam cham 0 bat


db 0000_0110b ;nam cham 1 va 2 bat

db 0000_0010b ;nam cham 1 bat

; bin data for clock-wise ;du lieu nhi phan quay theo chieu kim dong ho

; full-step rotation: ;quay mot buoc

datcw_fs db 0000_0001b ;nam cham 0 bat

db 0000_0011b ;nam cham 1 va 0 bat

db 0000_0110b ;nam cham 1 va 2 bat

db 0000_0000b ;khong nam cham nao bat

; bin data for counter-clock-wise ; du lieu nhi phan quay nguoc chieu kim dong ho

; full-step rotation: ;quay mot buoc

datccw_fs db 0000_0100b ;nam cham 2 bat

db 0000_0110b ;nam cham 1 va 2 bat

db 0000_0011b ;nam cham 0 va 1 bat

db 0000_0000b ;khong nam cham nao bat

start: ;bat dau

mov bx, offset datcw ; start from clock-wise half-step.

mov si, 0 ;gan gia tri thanh si = 0

mov cx, 0 ; step counter ;gan gia tri thanh cx = 0


next_step: ;buoc quay tiep

; motor sets top bit when it's ready to accept new command

wait: in al, 7 ;nhap trang thai hien tai

test al, 10000000b ;kiem tra dong co buoc da san sang hay chua

jz wait ;

mov al, [bx][si] ;tai du lieu dau tien vao thanh AL

out 7, al ;thuc hien quay theo dau ra thanh AL

inc si ;tang SI len 1

cmp si, 4 ;so sanh SI voi 4 su lieu vao trong datain

jb next_step ;

mov si, 0 ;Nhan SI = 0

inc cx ;tang cx len 1

cmp cx, steps_before_direction_change ;so sanh cx voi dong co truoc khi thay
doi

jb next_step ;

mov cx, 0 ;gan cx = 0

add bx, 4 ; next bin data

cmp bx, offset datccw_fs ;so sanh bx voi do lech datccw_fs

jbe next_step ;

mov bx, offset datcw ; return to clock-wise half-step.

jmp next_step
II Giải thích lưu đồ bài toán:

Delay START

SET THE COUNT FOR MOTOR


TO ROTATE
Initialize counter

OET THE CODE SEQUENCE FOR


MOTOR TO ROTATE
Decrement counter

SET A COUNTER FOR CODE


SEOUNCE

No SEND THE SEQUNCE TO PORT


Is A
counter
=0?

CALL DELAY

Yes
INCREAMENT THE POINTER

RET

DFEPETION SEOUENCE
ECREMDECREMENT THE COUNTER
AND

No CHECK
REPETION
COUNTER-

Yes
RETURN TPROORAMO
MAIN

You might also like