#include <msp430fr5739.h>
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
_delay_cycles(1000000);
// Initialization of the port pins of MSP430G2553 - P1.5 is connected to PIR sensor and the P1.6 and P1.7 are connected to the L293D motor driver
P1DIR |= 0xC1; // Set P1.0 for LED output, P1.6 and P1.7 L293D motor pins to output direction
P1OUT = 0X00;
P2IE |= 0x01; // P2.0 interrupt enabled
P2IES |= 0x01; // P2.0 High/low edge
P2IFG &= ~0x01; // P2.0 IFG cleared
_BIS_SR(LPM4_bits + GIE); // Enter LPM4 w/interrupt
}
// Port 1 interrupt service routine
#pragma <span id="IL_AD7" class="IL_AD">vector</span>=PORT2_VECTOR
__interrupt void Port_2(void)
{
P1OUT ^= 0x01; // P1.0 = toggle
// P1.6 and P1.7 are Enable pins of the L293D (EN1 = 1, EN2 = 0 -- motor rotate in Forward direction)
if(P1OUT & 0x01 == 0x01)
{
P1OUT |= 0x80;
_delay_cycles(1000000);
P1OUT &= ~0xC0; // disable the enable pins to stop the motor
}
// P1.6 and P1.7 are Enable pins of the L293D (EN1 = 0, EN2 = 1 -- motor rotate in Forward direction)
else
{
P1OUT |= 0x40;
_delay_cycles(1000000);
P1OUT &= ~0xC0; // disable the enable pins to stop the motor
}
_delay_cycles(10000);
P2IFG &= ~0x01; // P2.0 IFG cleared
}