Yes, please use the (CODE) and (/CODE) tags around your code! (use SQUARE brackets)
Your code seems badly designed.
The typical way to drive a stepper motor is to debounce the input "step" pin (very important!) and then sequence the 4 steps based on the state of the direction pin.
something like this;
Code:
// PORBT.0 = STEP pin input
// PORTB.1 = DIRECTION pin input
// PORTD = stepper motor 4 outputs (3-0)
while(1)
{
while(PINB.0 == 1) continue; // wait here for STEP pin to go lo \
delay_ms(10); // debounce delay
while(PINB.0 == 0) continue; // now wait here for STEP pin to go hi /
delay_ms(10); // debounce delay
// now step forward or backward 1 step
if(PINB.1 == 0) // DIR input pin is forward
{
mask = (mask >> 1);
if(mask == 0) mask = 0b00001000;
}
else // else DIR pin is backward
{
mask = (mask << 1);
if(mask == 0b00010000) mask = 0b00000001;
}
// finally put the mask to PORTD for stepper motor pins
PORTD = mask;
}
Is easier to read and to understand.