►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

Fri Dec 19 2014, 11:31 AM
1
-1'
Fri Dec 19 2014, 11:30 AM
1
1
ajay_bhargav
Fri Dec 12 2014, 04:38 AM
@Abdul BAsit, Post in forum please. We will help you.
Wed Dec 10 2014, 06:41 PM
Abdul BAsit
I am working on smoke detector using AT89S52 and dont know how its wors..kindly send me circuit diagram and code for its hardware & software implementation
Tue Dec 09 2014, 11:30 AM
Irinel
Please send me the content of that cd-rom (embedded c - michael j pont. Thank you.
Tue Dec 09 2014, 02:45 AM
kmyo
please give me the operation of 12v trickle charger
Sun Dec 07 2014, 07:50 AM
hidawi
we need the circuit diagrom of the remote control of iduction motor by android appliction
PsySc0rpi0n
Tue Dec 02 2014, 10:30 AM
I have no idea... I'm new to micro controllers
Tue Dec 02 2014, 08:35 AM
samarnath dev
how can usb key bord interfasing to dot matrx led moving, by asm51 ?
Tue Dec 02 2014, 08:32 AM
samarnath dev
how can usb key bord interfasing to 8051 by asm code?

Downloads

Comments

naimish324
Wed Dec 17 2014, 04:48 AM
sathish177
Tue Dec 16 2014, 06:43 PM
djnokey
Sat Dec 13 2014, 12:12 PM
sai9113
Tue Dec 09 2014, 07:23 AM
alexlomol
Fri Dec 05 2014, 12:06 AM
chandujonty
Thu Dec 04 2014, 10:11 AM
fantasy1214
Mon Dec 01 2014, 01:45 PM
vumbelino
Sat Nov 29 2014, 04:43 PM

Online

Guests: 66, Members: 0 ...

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

Members: 37560
Newest member: naimish324
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Dec 19 2014, 09:58 PM
For what you want,it is easier to not use interrup...
sankalp_s Avatar
Posted By sankalp_s
Fri Dec 19 2014, 06:04 PM
This version works.Edit it to use either method. ...
muhibraza Avatar
Posted By muhibraza
Fri Dec 19 2014, 08:05 AM
software_developer Avatar
Posted By software_developer
Fri Dec 19 2014, 04:54 AM
Which files i have to use?Please give me .zip fold...
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Dec 19 2014, 12:21 AM
This version works.Edit it to use either method. ...
sankalp_s Avatar
Posted By sankalp_s
Thu Dec 18 2014, 08:40 PM
SIR THIS CODE IS NOT WORKING.. ORG 000H ; starting...
sankalp_s Avatar
Posted By sankalp_s
Thu Dec 18 2014, 08:36 PM
i've tried this code but faced a syntax error on l...
sankalp_s Avatar
Posted By sankalp_s
Thu Dec 18 2014, 08:32 PM
SIR THIS CODE IS NOT WORKING.. ORG 000H ; starting...
ajay_bhargav Avatar
Posted By ajay_bhargav
Thu Dec 18 2014, 04:24 AM
Code is all ok.. just change EXT0 to EX0... By mis...
ExperimenterUK Avatar
Posted By ExperimenterUK
Wed Dec 17 2014, 11:21 PM
i've tried this code but faced a syntax error on l...