// * DATE: 1/21/2013
// * DESCRIPTION: Simple program to run 8 lead stepper motor at half-steps
#include "msp430g2452.h"
volatile unsigned short a = 1;
volatile unsigned short i = 1;
volatile unsigned short j = 2;
volatile unsigned short k = 3;
volatile unsigned short l = 4;
volatile unsigned short m = 5;
volatile unsigned short n = 6;
volatile unsigned short o = 7;
volatile unsigned short p = 8;
/* MAIN */
void main(void) {
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR &= ~BIT3;
P1IE |= BIT3;
P1DIR |= BIT0; // Set P1.0 to output direction
P1DIR |= BIT1; // Set P1.6 to output direction
P1DIR |= BIT2; // Set P1.1 to output direction
P1DIR |= BIT4; // Set P1.2 to output direction
TA0CCR0 = 15000; // Count limit (16 bit)
TA0CCTL0 = 0x10; // Enable counter interrupts, bit 4=1
TA0CTL = TASSEL_1 + MC_1; // Timer A 0 with ACLK @ 12KHz, count UP
_BIS_SR(LPM0_bits + GIE); // LPM0 (low power mode) interrupts enabled
}
#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer0_A0 (void) { // Timer0 A0 interrupt service routine
if (i == a)
{P1OUT ^= BIT0;
P1OUT = BIT0;
}
if (j == a)
{P1OUT ^= BIT0 + BIT1;
P1OUT = BIT0 + BIT1;
}
if (k == a)
{P1OUT ^= BIT1;
P1OUT = BIT1;
}
if (l == a)
{P1OUT ^= BIT1 + BIT2;
P1OUT = BIT1 + BIT2;
}
if (m == a)
{P1OUT ^= BIT2;
P1OUT = BIT2;
}
if (n == a)
{P1OUT ^= BIT2 + BIT4;
P1OUT = BIT2 + BIT4;
}
if (o == a)
{P1OUT ^= BIT4;
P1OUT = BIT4;
}
if (p == a)
{P1OUT ^= BIT4 + BIT0;
P1OUT = BIT4 + BIT0;
a = 0;
}
a = a+1;
}
#pragma vector = PORT1_VECTOR
__interrupt void button_push_isr(void) // Push Button Interrupt
{
P1IFG &= ~BIT3; // Clear P1.0 Button Flag
TA0CCTL0 = 0;
_BIS_SR(LPM0_bits + CPUOFF); // LPM0 (low power mode) interrupts enabled
}