;FILENAME:   STLAB031.ASM
;DATE:       March 16, 1996
;TITLE:      Stepping motor control
;HARDWARE:   JAZZ-31

; JAZZ-31 utilities subroutines
SCANK    EQU    0099H   ;scan disp & kb 1 loop
UBEEP    EQU    00A5H   ;user beep
; Pin Interface
PC_8255  EQU    0FA02H  ;8255 port c (pc0-pc3 = KEYIN)
CTL_8255 EQU    0FA03H  ;8255 control port
; Variables
DISBUF   EQU    32H     ;LED display buffer

;Program 1: Stepping motor direction rotation control
;           (two phase exitation)

        ORG     8100H
MAIN:
        LCALL   INIT_8255       ;set 8255 mode
LOOP1:
        LCALL   INIT_DISPLAY
        LCALL   SCANK
        CJNE    A,#0EH,LOOP2    ;key E
LOOP11: LCALL   DRIVE_LEFT      ;rotate left
        LCALL   SCANK
        CJNE    A,#0DH,LOOP11
        SJMP    LOOP21

LOOP2:  CJNE    A,#0DH,LOOP1    ;key D
LOOP21: LCALL   DRIVE_RIGHT     ;rotate right
        LCALL   SCANK
        CJNE    A,#0EH,LOOP21
        SJMP    LOOP11

;
; Left direction rotation
;
DRIVE_LEFT:
;       LCALL   UBEEP
        MOV     R0,#04H         ;4 step
        MOV     A,#0CCH         ;2 initial phase
        MOV     DPTR,#PC_8255
DRVL1:
        MOVX    @DPTR,A
        RL      A
        LCALL   DELAY
        DJNZ    R0,DRVL1
        RET
;
; Right direction rotation
;
DRIVE_RIGHT:
;       LCALL   UBEEP
        MOV     R0,#04H         ;4 step
        MOV     A,#0CCH         ;2 initial phase
        MOV     DPTR,#PC_8255
DRVR1:
        MOVX    @DPTR,A
        RR      A
        LCALL   DELAY
        DJNZ    R0,DRVR1
        RET
;
; Delay time for stepping motor control
;
DELAY:
        MOV     R2,#32H
DLAY1:
        MOV     R3,#00H
        NOP
        NOP
        DJNZ    R3,$
        DJNZ    R2,DLAY1
        RET
;
; Initial 8255 mode of operation
;
INIT_8255:
        MOV     DPTR,#CTL_8255  ;Init 8255 mode
        MOV     A,#81H          ;PC(low) = in PC(high) = out
        MOVX    @DPTR,A
        RET
;
; Initial display buffer
;
INIT_DISPLAY:
        MOV    DISBUF,#00H
        MOV    DISBUF+1,#00H
        MOV    DISBUF+2,#00H
        MOV    DISBUF+3,#40H
        MOV    DISBUF+4,#40H
        MOV    DISBUF+5,#00H
        MOV    DISBUF+6,#00H
        MOV    DISBUF+7,#00H
        RET
;
        END
