如何使步进电机实例交互式

时间:2016-11-17 07:05:56

标签: assembly rotation x86-16

我有步进电机代码,可以看到步进电机的工作原理,旋转度为22.5。这很好 但是,我想让它具有交互性,即如果点击右边的按钮,电机就会旋转。不是一个完整的想法,我愿意接受建议。 有什么想法吗?

修改 按钮我不是指硬连线按钮,只是任何形式的用户输入。无论是鼠标点击还是键盘按键等等。

PS:我正在使用emu8086

代码:

; 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#


name "stepper"

#make_bin#

steps_before_direction_change = 10h ; 16 (decimal)

jmp start

; ========= data ===============

; bin data for clock-wise
; half-step rotation:
datcw    db 6
         db 4
         db 3
         db 2

; bin data for counter-clock-wise
; half-step rotation:
datccw   db 3
         db 1
         db 6
         db 2


; bin data for clock-wise
; full-step rotation:
datcw_fs db 1
         db 3
         db 6
         db 0

; bin data for counter-clock-wise
; full-step rotation:
datccw_fs db 4
          db 6
          db 3
          db 0


start:
mov bx, offset datcw ; start from clock-wise half-step.
mov si, 0
mov cx, 0 ; step counter

next_step:
; motor sets top bit when it's ready to accept new command
wait:   in al, 7     
        test al, 10000000b
        jz wait

mov al, [bx][si]
out 7, al

inc si

cmp si, 4
jb next_step
mov si, 0

inc cx
cmp cx, steps_before_direction_change
jb  next_step

mov cx, 0
add bx, 4 ; next bin data

cmp bx, offset datccw_fs
jbe next_step

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

jmp next_step

1 个答案:

答案 0 :(得分:0)

如果我理解正确,在交互模式下你仍然可以从其中一张表中执行4x table-cell

所以可能是这样的:

out