控制步进电机转向

单转

code segement
     assume cs:code,ds:code
     org 100h
start:jmp begin
     psta db 05h,15h,14h,54h,50h,51h,41h,45h  ;相序表
message db 'Press sw2 to start !'             ;系统提示
        db 0dh,0ah
        db 'if you want to quit,press sw1 !'
        db 0dh,0ah,'$'
begin:  mov ax,cs
        mov ds,ax
        mov ah,09h                            ;显示提示信息
        mov dx,seg message
        int 21h
        mov dx,303h         ;初始化8255A
        mov a1,81h
        out dx,al
        mov al,09h        ;置pc4=1,关闭74LS37
        out dx,al
L:      mov dx,302h               ;查sw2按下?(pc1=0?)
        in  al,dx
        and al,02h             ;未按下,等待
        jnz L
        mov dx,303h                 ;置pc4=0,打开74LS37
        mov al,08h
        out dx,al
reload: mov si,sffset psta             ;设 相序表指针
        mov cx,8         ;设8拍循环次数
lop:    mov dx,302h             ;查sw1按下?(pc0=0?)
        in al,dx
        and al,01h
        jz quit              ;已按下,退出
        mov al,[si]           ;未按下,送相序表代码到pa
        mov dx,300h
        out dx,al
        mov di,0afh
        mov bx,0ffffh           ;延迟
delay:  dec bx
        jnz delay
        dec di
        jnz delay
        inc si              ;相序表指针+1
        dec cx                     ;循环次数-1
        jnz lop              ;未到8次,继续
        jmp reload           ;已到8次,重新
quit:   mov dx,303h         ;置PC4=1
        mov al,09
        out dx,al
        mov ah,4ch          ;程序退出
        int 21h
code ends
        end start

正反转

code segment

     assume cs:code,ds:code
     org 100h
start:jmp begin
     psta db 05h,15h,14h,54h,50h,51h,41h,45h
pstb db 45h,41h,51h,50h,54h,14h,15h,05h ;相序表
message db 'Press sw2 to start !'             ;系统提示
        db 0dh,0ah
        db 'if you want to quit,press sw1 !'
        db 0dh,0ah,'$'
begin:  mov ax,cs
        mov ds,ax
        mov ah,09h                            ;显示提示信息
        mov dx,seg message
        mov ds,dx
        mov dx,offset message
        int 21h
        mov dx,303h         ;初始化8255A
        mov al,81h
        out dx,al
        mov al,09h        ;置pc4=1,关闭74LS37
        out dx,al
L:      mov dx,302h               ;查sw2按下?(pc1=0?)
        in  al,dx
        and al,02h             ;未按下,等待
        jnz L
        mov dx,303h                 ;置pc4=0,打开74LS37
        mov al,08h
        out dx,al
reload:  mov si,offset psta
        mov cx,8                ;设8拍循环次数
lop1:    mov dx,302h             ;查sw1按下?(pc0=0?)
        in al,dx
        and al,01h
        jz lop2              ;已按下,退出
        mov al,[si]           ;未按下,送相序表代码到pa
        mov dx,300h
        out dx,al
        mov di,0afh
        mov bx,0ffffh           ;延迟
delay1:  dec bx
        jnz delay1
        dec di
        jnz delay1
        inc si              ;相序表指针+1
        dec cx                     ;循环次数-1
        jnz lop1              ;未到8次,继续
        jmp reload          ;已到8次,重新
reload1: mov si,offset pstb
         mov cx,8           ;设8拍循环次数
lop2:    mov dx,302h             ;查sw1按下?(pc0=0?)
        in al,dx
        and al,02h
        jz lop1              ;已按下,退出
        mov al,[si]           ;未按下,送相序表代码到pa
        mov dx,300h
        out dx,al
        mov di,0afh
        mov bx,0ffffh           ;延迟
delay:  dec bx
        jnz delay
        dec di
        jnz delay
        inc si              ;相序表指针+1
        dec cx                     ;循环次数-1
        jnz lop2              ;未到8次,继续
        jmp reload1          ;已到8次,重新

code ends
        end start

原文地址:https://www.cnblogs.com/liudehao/p/4469575.html