Sample PROGRAMS
Sample PROGRAMS
Sample PROGRAMS
Sample PROGRAMS:
PROGRAM 1:
Program to rotate the stepper motor clockwise 90° and 180°
counter- clockwise using 8051.
P
TA
G
JA
ORG 0000H ; Start of program memory
D
START:
O
MOV DPTR, #DELAY_MS ; Load delay value into DPTR
CALL DELAY_MS
M
; Delay to stabilise
A
MOV A, #90 ; Set the rotation degree (90 degrees)
PR
counter-clockwise
A
PR
END:
SJMP END ; Infinite loop
)
59
DELAY_MS:
40
; Modify this subroutine based on your clock frequency and desired delay
; Adjust the value in R7 to control the delay duration
(2
Y
DELAY_OUTER:
MOV R6, #250 ; Initialize delay counter inner loop
DELAY_INNER:
DJNZ R6, DELAY_INNER ; Decrement inner loop counter
DJNZ R7, DELAY_OUTER ; Decrement outer loop counter
RET
1
STEPPER MOTOR INTERFACING USING 8051 MICROCONTROLLER
ROTATE_DEGREES:
; Subroutine to rotate the stepper motor at a certain degree
; Modify this subroutine based on your stepper motor driver and
configuration
RET
P
TA
G
JA
D
O
M
A
PR
AV
N
A
) PR
59
40
20
(2
Y
B
2
STEPPER MOTOR INTERFACING USING 8051 MICROCONTROLLER
PROGRAM 2:
Program to rotate the stepper motor clockwise 66° and 77°
counter- clockwise using 8051.
P
TA
ORG 0000H ; Start of program memory
G
START:
JA
MOV DPTR, #DELAY_MS ; Load delay value into DPTR
CALL DELAY_MS ; Delay to stabilise
D
MOV A, #60 ; Set the rotation degree (60 degrees)
O
CALL ROTATE_CLOCKWISE ; Rotate the motor 60 degrees clockwise
MOV A, #77
M
; Set the rotation degree (77 degrees)
A
CALL ROTATE_ANTICLOCKWISE ; Rotate the motor 77 degrees
PR
anticlockwise
AV
END:
N
DELAY_MS:
; Delay subroutine to stabilise motor before rotation
)
; Modify this subroutine based on your clock frequency and desired delay
59
DELAY_INNER:
B
ROTATE_CLOCKWISE:
; Subroutine to rotate the stepper motor clockwise by a certain degree
3
STEPPER MOTOR INTERFACING USING 8051 MICROCONTROLLER
RET
P
TA
ROTATE_ANTICLOCKWISE:
; Subroutine to rotate the stepper motor anticlockwise by a certain degree
G
; Modify this subroutine based on your stepper motor driver and
JA
configuration
D
; Your anticlockwise rotation logic here
O
; Implement the logic to rotate the stepper motor anticlockwise by the
specified degree
M
A
; You'll need to interface with your stepper motor driver and control pins
PR
RET
AV
N
A
) PR
59
40
20
(2
Y
B