►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
Sat Aug 30 2014, 12:15 PM
@sufiyan, You can use solenoid lock in place of LED.
Fri Aug 29 2014, 12:17 AM
sufiyan
please can you tell me which type of lock activator should i connect in place of LED? can i use selenoid lock actuator
ajay_bhargav
Thu Aug 28 2014, 06:34 AM
Please post questions in forum
Thu Aug 28 2014, 01:44 AM
yednekachew
can you give a project made bay proteus software
Mon Aug 25 2014, 07:12 AM
Vinod Soni
Hi Sir, How can i make this RFID with ATMega16/32 controller
pavanjain
Sat Aug 23 2014, 05:10 AM
Sir i want to download the hex file in P89v51rd2 microcontroller using max232 IC but we not load the program in IC
Tue Aug 19 2014, 04:51 PM
allen ndumu
please i will like to know if the problem of speed control of dc motor using keypad and l298 was if yes can i have the complete project send it to the address i really need to see it
Tue Aug 19 2014, 10:47 AM
Amit Bisht
sir i want to have some trending projects on which i could work related to ATmega 16 microcontroller
ExperimenterUK
Sat Aug 16 2014, 04:16 PM
@diligent . create a thread
Sat Aug 16 2014, 03:17 PM
diligent
in assembly langauage programming..

Downloads

Comments

bobparihar
Mon Sep 01 2014, 06:19 AM
vijit
Sun Aug 31 2014, 08:33 AM
[email protected]
Sat Aug 30 2014, 04:45 PM
enisi
Wed Aug 27 2014, 06:08 AM
sadalakshmi
Wed Aug 27 2014, 12:39 AM
Paecake
Sun Aug 24 2014, 04:07 PM
pavanjain
Sat Aug 23 2014, 02:33 AM
samchovatiya
Thu Aug 21 2014, 02:30 PM

Online

Guests: 45, Members: 0 ...

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

Members: 37504
Newest member: bobparihar
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Mon Sep 01 2014, 10:59 PM
What is your graph displaying ?I'm assuming it is ...
Peter_Parker Avatar
Posted By Peter_Parker
Mon Sep 01 2014, 06:19 PM
Just to add to this,I've connected this now to a C...
ajay_bhargav Avatar
Posted By ajay_bhargav
Mon Sep 01 2014, 07:28 AM
Which RFID module are you using? Post link to the ...
ajay_bhargav Avatar
Posted By ajay_bhargav
Mon Sep 01 2014, 07:28 AM
We prefer to use English language on our forums. B...
bobparihar Avatar
Posted By bobparihar
Mon Sep 01 2014, 06:33 AM
i am using a RFID module, i want to connect reader...
ajay_bhargav Avatar
Posted By ajay_bhargav
Sat Aug 30 2014, 12:03 PM
Forgot to attach files. This has source for both R...
ajay_bhargav Avatar
Posted By ajay_bhargav
Sat Aug 30 2014, 11:56 AM
I found a very good working source but its for PIC...
siddique Avatar
Posted By siddique
Sat Aug 30 2014, 03:34 AM
Have you tried using the TX setup to receive and v...