CLRSCR MACRO
MOV AX,0600H
MOV BH,07
MOV CX,0
MOV DX,184FH
INT 10H
ENDM
SETCUR MACRO ROW,COL
MOV AH,02
MOV BH,00
MOV DH,ROW
MOV DL,COL
INT 10H
ENDM
STRING MACRO DATA1
MOV AH,09
MOV DX,OFFSET DATA1
INT 21H
ENDM
CHAR MACRO DATA2
MOV AH,02
MOV DL,DATA2
INT 21H
ENDM
SPEED MACRO VAL1,RES,SVN
LOCAL C1,C2,C3,C4,C5,C6,C7,C8,RET1
MOV CH,VAL1
CMP CH,'1'
JE C1
CMP CH,'2'
JE C2
CMP CH,'3'
JE C3
CMP CH,'4'
JE C4
CMP CH,'5'
JE C5
CMP CH,'6'
JE C6
CMP CH,'7'
JE C7
CMP CH,'8'
JE C8
C1:MOV CX,0FFFFH
MOV DL,10H
JMP RET1
C2:MOV CX,0A000H
MOV DL,20H
JMP RET1
C3:MOV CX,7300H
MOV DL,30H
JMP RET1
C4:MOV CX,5300H
MOV DL,40H
JMP RET1
C5:MOV CX,3000H
MOV DL,50H
JMP RET1
C6:MOV CX,2000H
MOV DL,60H
JMP RET1
C7:MOV CX,1500H
MOV DL,70H
JMP RET1
C8:MOV CX,0900H
MOV DL,80H
RET1: MOV RES,CX
MOV SVN,DL
ENDM
DELAY MACRO VALUE
LOCAL BACK1,BACK2
MOV CX,0FFFH
BACK2: MOV BX,VALUE
BACK1: DEC BX
JNZ BACK1
DEC CX
JNZ BACK2
ENDM
CIK MACRO MOTOR
MOV DX,0378H
MOV AL,MOTOR
OUT DX,AL
ENDM
.MODEL SMALL
.STACK 64
.DATA
A DB '--- STEPPER MOTOR CONTROL ---','$'
B DB 'Press E to Enter Speed Level :'
DB CR,LF, ' Between +1 and +8 to Rotate the Motor in Forward Direction'
DB CR,LF, ' Between -1 and -8 to Rotate the Motor in Reverse Direction'
DB CR,LF, ' Enter +-n to Rotate the Motor in Forward and Reverse Directions','$'
C DB 'Press U to Speed Up the Motor','$'
D DB 'Press D to Speed Down the Motor','$'
E DB 'Press S to Stop the Motor','$'
F DB 'Press Q to Quit','$'
G DB 'YOU ENTERED A WRONG VALUE! TRY AGAIN ...','$'
H DB 'Your choice:','$'
I DB 'Enter Speed:','$'
J DB 'Motor`s Current Speed:','$'
K DB 'Motor`s Rotation is Stopped !','$'
L DB 'You Exceed the Speed Limit !','$'
M DB ?
S DW ?
COUNT DB ?
SEGM DB ?
BUF DB 4,?,4 DUP(?)
CR EQU 0DH
LF EQU 0AH
.CODE
MAIN: MOV AX,@DATA
MOV DS,AX
MOV BH,0
MOV BL,0
AGAIN: CLRSCR
SETCUR 01,10
STRING A
SETCUR 03,05
STRING B
SETCUR 08,05
STRING F
SETCUR 12,05
STRING H
SETCUR 12,18
MOV AH,01
INT 21H
CMP AL,'E'
JE NEXT1
CMP AL,'e'
JE NEXT1
CMP AL,'Q'
JE OVER5
CMP AL,'q'
JE OVER5
JMP OVER4
NEXT1: SETCUR 14,05
STRING I
SETCUR 14,18
MOV AH,0AH
MOV DX,OFFSET BUF
INT 21H
MOV SI,OFFSET BUF
MOV CL,[SI+2]
CMP CL,'+'
JE OVER
CMP CL,'-'
JE OVER2
SETCUR 15,05
STRING G
SETCUR 16,05
OVER5: JMP EXIT
OVER: MOV SI,OFFSET BUF
MOV CL,[SI+3]
CMP CL,'-'
JE OVER3
CMP CL,'8'
JA OVER6
CMP CL,'0'
JB OVER6
MOV BL,CL ;
JMP NEXT2
OVER6: JMP AGAIN
OVER3: MOV SI,OFFSET BUF
MOV CL,[SI+4] ;
CMP CL,'8'
JA OVER6
CMP CL,'0'
JB OVER6
MOV BL,CL
JMP NEXT2
OVER2: MOV SI,OFFSET BUF
MOV CL,[SI+3]
CMP CL,'+'
JE OVER4
CMP CL,'8'
JA OVER6
CMP CL,'0'
JB OVER6
MOV BL,CL ;
JMP NEXT2
OVER4: SETCUR 18,05
STRING G
SETCUR 19,05
JMP EXIT
NEXT2: CLRSCR
SETCUR 01,10
STRING A
SETCUR 03,05
STRING C
SETCUR 04,05
STRING D
SETCUR 05,05
STRING E
SETCUR 06,05
STRING F
SETCUR 08,05
STRING J
SETCUR 08,28
CHAR BL
SETCUR 10,05
STRING H
SETCUR 10,18
MOV AL,99H
MOV M,AL
MOV SI,OFFSET BUF
MOV BL,[SI+3]
CMP BL,'-'
JE JUMPER
JMP GO
JUMPER: JMP CONTT1
GO: MOV AL,99H
MOV M,AL
CONT1: MOV SI,OFFSET BUF
MOV BL,[SI+3]
SPEED BL,S,SEGM
MOV AL,M
AND AL,00001111B
ADD AL,SEGM
CIK AL
MOV AL,M
DELAY S
MOV AL,M
MOV BH,[SI+2]
CMP BH,'-'
JE RROL
ROR AL,1
JMP RR
RROL: ROL AL,1
RR: MOV M,AL
MOV AH,01
INT 16H
JNZ BACK
JMP CONT1
BACK: MOV AH,00
INT 16H
CMP AL,'U'
JE NEXT3
CMP AL,'u'
JE NEXT3
CMP AL,'D'
JE NEXT4
CMP AL,'d'
JE NEXT4
CMP AL,'S'
JE NEXT5
CMP AL,'s'
JE NEXT5
CMP AL,'Q'
JE EXITT
CMP AL,'q'
JE EXITT
EXITT: JMP EXIT
JMP CONT1
NEXT3: MOV SI,OFFSET BUF
MOV BL,[SI+3]
INC BL
CMP BL,'8'
JA NEXT6
MOV [SI+3],BL
JMP NEXT2
NEXT4: MOV SI,OFFSET BUF
MOV BL,[SI+3]
DEC BL
CMP BL,'0'
JE NEXT5A
MOV [SI+3],BL
JMP NEXT2
NEXT5: MOV BL,0
JMP AGAIN
NEXT5A:SETCUR 12,05
STRING K
SETCUR 13,05
JMP EXIT
NEXT6: SETCUR 12,05
STRING L
SETCUR 13,05
JMP EXIT
CONTT1: MOV AL,99H
MOV M,AL
CONTT: MOV COUNT,30H
CONT2:
MOV SI,OFFSET BUF
MOV BL,[SI+4]
SPEED BL,S,SEGM
MOV AL,M
AND AL,00001111B
ADD AL,SEGM
CIK AL
MOV AL,M
DELAY S
MOV AL,M
ROR AL,1
MOV M,AL
MOV AH,01
INT 16H
JNZ BACK101
JMP GO10
BACK101:JMP BACK10
GO10: DEC COUNT
JNZ CONT22
JMP GO20
CONT22: JMP CONT2
GO20: MOV COUNT,30H
CONT3:
MOV SI,OFFSET BUF
MOV BL,[SI+4]
SPEED BL,S,SEGM
MOV AL,M
AND AL,00001111B
ADD AL,SEGM
CIK AL
MOV AL,M
DELAY S
MOV AL,M
ROL AL,1
MOV M,AL
MOV AH,01
INT 16H
JNZ BACK10
DEC COUNT
JNZ CONT33
JMP GO40
CONT33:JMP CONT3
GO40: JMP CONTT
BACK10:MOV AH,00
INT 16H
CMP AL,'U'
JE NEXT30
CMP AL,'u'
JE NEXT30
CMP AL,'D'
JE NEXT40
CMP AL,'d'
JE NEXT40
CMP AL,'S'
JE NEXT50
CMP AL,'s'
JE NEXT50
CMP AL,'Q'
JE EXIT
CMP AL,'q'
JE EXIT
JMP CONTT
NEXT30: MOV SI,OFFSET BUF
MOV BL,[SI+4]
INC BL
CMP BL,'8'
JA NEXT60
MOV [SI+4],BL
JMP NEXT2
NEXT40: MOV SI,OFFSET BUF
MOV BL,[SI+4]
DEC BL
CMP BL,'0'
JE NEXT50A
MOV [SI+4],BL
JMP NEXT2
NEXT50: MOV BL,0
JMP AGAIN
NEXT50A:SETCUR 12,05
STRING K
SETCUR 13,05
JMP EXIT
NEXT60:SETCUR 12,05
STRING L
SETCUR 13,05
EXIT: MOV AH,4CH
INT 21H
END MAIN