►Programming Full step Sequence

►C Programming
I am assuming that stepper motor is connected at Port 1.0 to Port 1.3. Adjusting the delay will increase or decrease the speed of the motor. Here just for demonstration i have taken some delay, you can change it as you want.

[Tip: Do testing.. ]




#include <REG2051.H>
.
#define stepper P1
void delay();

void main(){
	while(1){
		stepper = 0x0C;
		delay();
		stepper = 0x06;
		delay();
		stepper = 0x03;
		delay();
		stepper = 0x09;
		delay();
	}
}

void delay(){
	unsigned char i,j,k;
	for(i=0;i<6;i++)
		for(j=0;j<255;j++)
			for(k=0;k<255;k++);
}



►Assembly Programming

	org 0H

stepper equ P1

main:
	mov stepper, #0CH
	acall delay
	mov stepper, #06H
	acall delay
	mov stepper, #03H
	acall delay
	mov stepper, #09H
	acall delay
	sjmp main

delay:
	mov r7,#4
wait2:
	mov r6,#0FFH
wait1:
	mov r5,#0FFH
wait:
	djnz r5,wait
	djnz r6,wait1
	djnz r7,wait2
	ret
	end


The working of the above code can be seen in the demo animation below.

unipolar stepper motor in full step sequence


►Programming Half step Sequence

►C Programming
Just the main routine changes rest everything remains same, i mean same delay routine.


void main(){
	while(1){
		stepper = 0x08;
		delay();
		stepper = 0x0C;
		delay();
		stepper = 0x04;
		delay();
		stepper = 0x06;
		delay();
		stepper = 0x02;
		delay();
		stepper = 0x03;
		delay();
		stepper = 0x01;
		delay();
		stepper = 0x09;
		delay();
	}
}



►Assembly Programming
Here also the main routine changes rest everything remains same.


main:
	mov stepper, #08H
	acall delay
	mov stepper, #0CH
	acall delay
	mov stepper, #04H
	acall delay
	mov stepper, #06H
	acall delay
	mov stepper, #02H
	acall delay
	mov stepper, #03H
	acall delay
	mov stepper, #01H
	acall delay
	mov stepper, #09H
	acall delay
	sjmp main


The working of the above code can be seen in the demo animation below.

unipolar stepper motor in half step sequence


►Programming for 2-wire connection of Unipolar Stepper Motor

►C Programming
void main(){
	while(1){
		stepper = 0x03;
		delay();
		stepper = 0x01;
		delay();
		stepper = 0x00;
		delay();
		stepper = 0x02;
		delay();
	}
}



►Assembly Programming
main:
	mov stepper, #03H
	acall delay
	mov stepper, #01H
	acall delay
	mov stepper, #00H
	acall delay
	mov stepper, #02H
	acall delay
	sjmp main


The working of the above code can be seen in the demo animation below.

unipolar stepper motor in 2-wire connection mode


►Programming for Bipolar Stepper Motor

►C Programming
void main(){
	while(1){
		stepper = 0x08;
		delay();
		stepper = 0x02;
		delay();
		stepper = 0x04;
		delay();
		stepper = 0x01;
		delay();
	}
}



►Assembly Programming
main:
	mov stepper, #08H
	acall delay
	mov stepper, #02H
	acall delay
	mov stepper, #04H
	acall delay
	mov stepper, #01H
	acall delay
	sjmp main



Now you're ready to use stepper motors. If you have any doubts, please post in the forum.

◄ Previous Page  |  Next Page ►

Back to main


DC Motor Tutorial Index
Introduction to Stepper Motors
Stepper Motor Connections
Step Sequence of Stepper Motors
Programming for Stepper Motor

Conversation

ajay_bhargav
Mon Oct 20 2014, 11:22 AM
@skrishna, please post in forum so we can help you better.
Tue Oct 14 2014, 01:45 PM
skrishna
how do i write an ALP equivalent 7segment display interfacing embedded c program (both 8051 microcontroller)
Sat Oct 11 2014, 06:41 PM
vaidehi
want details of seven segment LED display common cathode ( IC CD 4026)
Fri Oct 03 2014, 12:52 PM
Narsim
Rickey you inspired me a lot ... I am also planing like you ...
ExperimenterUK
Wed Oct 01 2014, 09:33 PM
We're back.. we had a bug, but posting is back to normal
ExperimenterUK
Sat Sep 13 2014, 04:34 PM
jaimin1212,Pimpalkhare Create a thread for your question
jaimin1212
Sat Sep 13 2014, 06:35 AM
i want to make self balancing robot using MPU6050 using atmega8.. please help to get data of gyro and accelerometer from this sensor through atmega8.
Thu Sep 11 2014, 01:00 PM
Sunil Pimpalkhare
Hello sir, I am trying to make Wearfin project https://www.youtube.com/watch?v=iZ6PVBvQf-g so can u help me in teaching how to built the program???
Thu Sep 11 2014, 06:21 AM
hariom panday
plz hlp me in my project
iec.naga
Tue Sep 09 2014, 05:19 AM
spi

Downloads

Comments

pddung93
Sun Oct 19 2014, 01:56 PM
msideal
Thu Oct 16 2014, 08:48 AM
robotgirl
Tue Oct 14 2014, 06:23 PM
BRV64
Mon Oct 13 2014, 05:48 AM
menadjelia
Mon Oct 13 2014, 02:47 AM
kulbhushan
Sun Oct 12 2014, 12:20 PM
HarrySid
Fri Oct 10 2014, 05:15 AM
pphamtuan
Thu Oct 09 2014, 03:58 AM

Online

Guests: 43, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 37531
Newest member: pddung93
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Wed Oct 22 2014, 03:22 AM
Okay, it seems to be a simple serial connection.Th...
jona Avatar
Posted By jona
Tue Oct 21 2014, 10:29 PM
I found this slightly different data sheet on a pu...
majoka Avatar
Posted By majoka
Tue Oct 21 2014, 06:35 PM
after this Accept-language:en-us\r\n...
majoka Avatar
Posted By majoka
Tue Oct 21 2014, 06:33 PM
@ aksharAT89C51AC3 can bebut the final decision wi...
majoka Avatar
Posted By majoka
Tue Oct 21 2014, 06:29 PM
@ Okechukwubefore starting this project you should...
majoka Avatar
Posted By majoka
Tue Oct 21 2014, 06:18 PM
@ kirangowleyou have to set the microphone level a...
majoka Avatar
Posted By majoka
Tue Oct 21 2014, 06:08 PM
i didnt understand the error where is error is th...
majoka Avatar
Posted By majoka
Tue Oct 21 2014, 06:04 PM
@ msidealMicrochip MCP23008 I2C 8-bit I/O expander...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Oct 21 2014, 05:21 PM
I found this slightly different data sheet on a pu...
msideal Avatar
Posted By msideal
Tue Oct 21 2014, 04:56 PM
Coding on Assembly Language is attached hereCODE:....