0% found this document useful (0 votes)
40 views4 pages

Sample PROGRAMS

The document describes two programs that rotate a stepper motor connected to an 8051 microcontroller. Program 1 rotates the motor 90 degrees clockwise and 180 degrees counter-clockwise. Program 2 rotates the motor 66 degrees clockwise and 77 degrees counter-clockwise. Both programs use delay subroutines to stabilize the motor before rotation and call rotation subroutines to rotate the motor the specified degrees through motor driver control pins.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views4 pages

Sample PROGRAMS

The document describes two programs that rotate a stepper motor connected to an 8051 microcontroller. Program 1 rotates the motor 90 degrees clockwise and 180 degrees counter-clockwise. Program 2 rotates the motor 66 degrees clockwise and 77 degrees counter-clockwise. Both programs use delay subroutines to stabilize the motor before rotation and call rotation subroutines to rotate the motor the specified degrees through motor driver control pins.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

STEPPER MOTOR INTERFACING USING 8051 MICROCONTROLLER

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

CALL ROTATE_DEGREES ; Rotate the motor 90 degrees clockwise


MOV A, #180 ; Set the rotation degree (180 degrees)
AV

CALL ROTATE_DEGREES ; Rotate the motor 180 degrees


N

counter-clockwise
A
PR

END:
SJMP END ; Infinite loop
)
59

DELAY_MS:
40

; Delay subroutine to stabilise motor before rotation


20

; Modify this subroutine based on your clock frequency and desired delay
; Adjust the value in R7 to control the delay duration
(2
Y

MOV R7, #100 ; Initialize delay counter outer loop


B

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

; Your stepper motor rotation code here


; Implement the logic to rotate the stepper motor at the specified degree
; You'll need to interface with your stepper motor driver and control pins

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

SJMP END ; Infinite loop


A
PR

DELAY_MS:
; Delay subroutine to stabilise motor before rotation
)

; Modify this subroutine based on your clock frequency and desired delay
59

; Adjust the value in R7 to control the delay duration


40
20

MOV R7, #100 ; Initialize delay counter outer loop


DELAY_OUTER:
(2

MOV R6, #250 ; Initialize delay counter inner loop


Y

DELAY_INNER:
B

DJNZ R6, DELAY_INNER ; Decrement inner loop counter


DJNZ R7, DELAY_OUTER ; Decrement outer loop counter
RET

ROTATE_CLOCKWISE:
; Subroutine to rotate the stepper motor clockwise by a certain degree

3
STEPPER MOTOR INTERFACING USING 8051 MICROCONTROLLER

; Modify this subroutine based on your stepper motor driver and


configuration

; Your clockwise rotation logic here


; Implement the logic to rotate the stepper motor clockwise by the specified
degree
; You'll need to interface with your stepper motor driver and control pins

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

You might also like