CSE321 Embedded Systems Design Lab
Exp 7: Interfacing an unipolar Stepper motor to LPC2148, to
rotate in clockwise/anti-clockwise directions
2023BCD0005
Albin John
Code (anticlockwise):
#include <LPC214x.h>
unsigned char step_sequence[4] = {0x03, 0x06, 0x0C, 0x09};
void delay(void)
{
unsigned int i;
for(i=0;i<50000;i++); // Adjust for speed
}
int main()
{
int i;
IO0DIR |= 0x0F; // P0.0–P0.3 as output
while(1){
for(i=0;i<4;i++){
IO0CLR = 0x0F; // Clear previous step
IO0SET = step_sequence[i]; // Energize coils
delay();
}
}
}
Output:
Code (clockwise)
#include <LPC214x.h>
unsigned char step_sequence[4] = {0x03, 0x06, 0x0C, 0x09}; // Clockwise
sequence
void delay(void)
{
unsigned int i;
for(i = 0; i < 50000; i++); // Delay for speed control
}
int main()
{
int i;
IO0DIR |= 0x0F; // Set P0.0–P0.3 as output
while(1)
{
for(i = 0; i < 4; i++)
{
IO0CLR = 0x0F; // Clear previous step
IO0SET = step_sequence[i]; // Energize next coil
delay();
}
}
}
Output: