08 ตุลาคม 2554

[ASSEMBLY] โปรแกรมควบคุม Steper Motor


.model small
.data
PDATA equ 3BCh

BUFF1   equ 01111111B
LATCH1  equ 10000000B

TAB1 db 01h,03h,02h,06h,04h,0Ch,08h,09h
    TAB2    db 09h,08h,0Ch,04h,06h,02h,03h,01h
    LEFT    EQU 4Bh
    RIGHT   EQU 4Dh
    ENTER   EQU 1Ch
    SCANKEY db  ?
    ASCII   db  ?
 
.code
mov ax,@data
mov ds,ax

Next: call RDKEY
call CHKKEY

cmp SCANKEY,ENTER
jne Next

Exit:
       mov ah,4Ch
       int 21h

WRT_DATA proc near
        push cx
     
        mov cx,10
and al,BUFF1
mov dx,PDATA
LD1:out dx,al
   loop LD1
 
   mov cx,10
or al,LATCH1
mov dx,PDATA
    LD2:out dx,al
   loop LD2
 
   pop cx  
        ret
WRT_DATA endp

RDKEY   proc near
        mov  ah,00h
   int  16h
   mov  SCANKEY,ah
   mov  ASCII,al

        ret
RDKEY   endp

CHKKEY  proc near
        cmp  SCANKEY,LEFT
        jne  RKEY
       
        mov cl,8
        mov di,offset TAB2
        call ROTATE
        jmp  EXT
     
RKEY:   mov cl,8
        mov di,offset TAB1
        call ROTATE
        jne  EXT
           
EXT:    ret
CHKKEY  endp

ROTATE  proc near      
;ST:    mov cl,8
; mov di,offset TAB1

NT:     call WRT_DATA
   call Delay
inc di
dec cl

jnz NT
; jmp ST
        ret
ROTATE  endp

Delay proc near
        push cx
        push dx
mov dx,1000

DL2:mov cx,50000
DL1:mov al,[di]

   loop DL1
dec dx
jnz DL2

pop dx
pop cx
ret
Delay endp

end