Aim:
To write a C program to run a stepper motor in clockwise/anti clockwise motion with different step pattern. 

Clock Wise Direction Rotation
Algorithm:
Step 1. Declare porta and control register as external data which are at the address of
0xe000 and 0xe003 of IC8255.
Step 2. Write the delay function using pointers.
Step 3. Set the control mode as output i.e 0x80
Step 4. Write a for loop starting with i=0x88 to 0x11 .
Step 5. Assign the values of i to porta where the stepper motor is connected.
Step 6. Call the delay function with a value corresponding to the required speed of the
motor rotation.
Step 7. Repeat from the step 3 to get continuous rotation of the motor.
Program for Clockwise Rotation
#include<stdio.h>
#include <AT89X51.H>
unsigned char xdata control _at_ 0xe003;
unsigned char xdata porta _at_ 0xe000;
void delay(int *k)
{
int *p;
for(p=0;p<=k;p++);
}
void main()
{
int i;
control = 0x80;
while(1)
{
for(i=0x88;i>=0x11;i>>=1)
{
porta = i;
P1=i;
delay(2500);
}}}

Anti-Clock Wise Direction Rotation
Algorithm:
Step 1. Declare porta and control register as external data which are at the address of
0xe000 and 0xe003 of IC8255.
Step 2. Write the delay function using pointers.
Step 3. Set the control mode as output i.e 0x80
Step 4. Write a for loop starting with i=0x11 to 0x88 .
Step 5. Assign the values of i to porta where the stepper motor is connected.
Step 6. Call the delay function with a value corresponding to the required speed of the
motor rotation.
Step 7. Repeat from the step 3 to get continuous rotation of the motor.
Program for Clockwise Rotation
#include<stdio.h>
#include <AT89X51.H>
unsigned char xdata control _at_ 0xe003;
unsigned char xdata porta _at_ 0xe000;
void delay(int *k)
{
int *p;
for(p=0;p<=k;p++);
}
void main()
{
int i;
control = 0x80;
while(1)
{
for(i=0x11;i>=0x88;i<<=1)
{
porta = i;
P1=i;
delay(2500);
}}}