MPMC Part 11
MPMC Part 11
Interfacing
Stepper Motor
Interfacing
Stepper Motor Interfacing
MOV A,#66H
BACK: MOV P1,A
RR A
ACALL DELAY
SJMP BACK
DELAY: MOV R1,#100
UP1: MOV R2,#50
UP: DJNZ R2,UP
DJNZ R1,UP1
RET
Note: motor to rotate in anticlockwise use instruction RL A instead of RR A
: A switch is connected to pin P2.7. Write an ALP to monitor the status of the SW. If SW = 0,
motor moves clockwise and if SW = 1, motor moves anticlockwise.
ORG 0000H
SETB P2.7
MOV A, #66H
MOV P1,A
TURN: JNB P2.7, CW
RL A
ACALL DELAY
MOV P1,A
SJMP TURN
CW: RR A
ACALL DELAY
MOV P1,A
SJMP TURN
• Write an ALP to rotate a motor 90° clockwise. Step angle of motor is 2°.
• Step angle = 2°
• Steps per revolution = 180
• For 90° rotation the no of steps is 45
• ORG 0000H
• MOV A, #66H
• MOV R0, #45
• BACK: RR A
• MOV P1, A
• ACALL DELAY
• DJNZ R0, BACK
• END
Programming stepper motor in ‘c’
• #include <reg51.h>
• void main ()
• {
• while (1)
• {
• P1=0x66;
• MSDELAY (200);
• P1=0x33;
• MSDELAY (200);
• P1=0x99;
• MSDELAY (200);
• P1=0xCC;
• MSDELAY (200);
• }
• }
• void MSDELAY (unsigned char value)
• {
• unsigned int x,y;
• for(x=0;x<1275;x++)
• for(y=0;y<value;y++);
• }
#include <REG51xD2.H>
void delay(unsigned int x) /* Delay Routine */
{ for(;x>0;x--);}
main(){
unsigned char Val,i;
while(1) {
Val = 0x88;
for(i=0;i<4;i++) {
P0 = Val;
Val = Val>>1;
delay(575); }}}