/* p10_2.c: Stepper motor control * * This program controls a unipolar stepper motor * using P4.3, P4.2, P4.1, P4.0. * * Tested with Keil 5.20 and MSP432 Device Family Pack V2.2.0. */ #include "msp.h" void delayMs(int n); int delay = 10; int direction = 0; int main(void) { const char steps[ ] = {0x9, 0x3, 0x6, 0xC}; int i = 0; P4->SEL1 &= ~0xF; /* configure P4.0 as simple I/O */ P4->SEL0 &= ~0xF; P4->DIR |= 0xF; /* P4.0 set as output pin */ while (1) { if (direction) P4->OUT = (steps[i++ & 3]); else P4->OUT = (steps[i-- & 3]); delayMs(delay); } } /* delay milliseconds when system clock is at 3 MHz */ void delayMs(int n) { int i, j; for (j = 0; j < n; j++) for (i = 250; i > 0; i--); /* delay 1 ms */ }