#include"iomsp430.h"
#define headup P4OUT_bit.P4OUT_O
#define photoint P4OUT_bit.P4OUT_5
void main (void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P4DIR_bit.P4DIR_0 = 1;
P4DIR_bit.P4DIR_5 = 1;
P1REN |= BIT2; // P1.2 Enable Pullup/Pulldown
P1OUT = BIT2; // P1.2 pullup
P1IE |= BIT2; // P1.2 interrupt enabled
P1IES |= BIT2; // P1.2 Hi/lo falling edge
P1IFG &= ~BIT2; // P1.2 IFG cleared just in case
_EINT();
if (headup==1)
{
if (photoint ==1)
{
steppermotor();
}
else
__bis_SR_register(LPM4_bits + GIE); // LPM4 with interrupts enabled
__no_operation();
}
void steppermotor(void)
P4DIR |= 0x40; // Set P4.5 to output direction
for (;;)
{
P4OUT ^ = 0x40; //
i = 500; // Delay
do (i--);
while (i ! = 0);
}
//
P1DIR |= 0x01; // Set P1.0 to output direction
P2IE |= 0x01; // P2.0 interrupt enabled
P2IES |= 0x01; // P2.0 Hi/lo edge
P2IFG &= ~0x01; // P2.0 IFG cleared
_BIS_SR(LPM4_bits + GIE); // Enter LPM4 w/interrupt
}
// Port 2 interrupt service routine
#pragma vector=PORT2_VECTOR
__interrupt void Port_2(void)
{
P1OUT ^= 0x01; // P1.0 = toggle
P2IFG &= ~0x01; // P2.0 IFG clearedf
}
//