Quantcast
Channel: MSP430 Technical Forums
Viewing all articles
Browse latest Browse all 2077

Help please!

$
0
0
I have been banging my head against the desk for 3 days trying to figure out interrupts on the MSP430... but no joy. 
 
What I want to do is:
 
When a input is detected on PIN1.5 activate output on PIN1.2 for a specified time. Then Enter LPM2. 
Next time an input is detected on PIN1.5, wake up, activate PIN1.2 for the specified time, then re-enter LPM2. 
Do this forever. 
 
The code below i have left 1.3 (switch 2 on the launch pad) as the interrupt just while testing. However I cannot get it to work...
 
Can anyone tell me what i'm doing wrong?
 
Thanks
 
#include "msp430g2211.h"
long int i;
main()
{
 WDTCTL=WDTPW+WDTHOLD;        //STOP WATCHDOG TIMER
 P1SEL = 0x00;
P1DIR=BIT2+BIT6;              // MAKE PIN 2 AND PIN 3 AS OUTPUTS.
 
P1IN =0x04;    // Set P1.2 to LOW
P1OUT =0x20;  // Set P1.5 to LOW
 
P1IE=BIT3;                    //ENABLE THE INTERRUPT FOR THE PIN 3
P1IES&=~BIT3;                 // TRIGGER INTERRUPT FOR RISING EDGE
_EINT();                      //ENABLE GLOBAL INTERRUPT ; SET GIE BIT IN SR
 
while(1)
{
if ((0x20 & P1IN)) // check if P1.5 is high
 
        {
        P1OUT |= 0x04;       // set P1.2 high
        i=1000000;
         do(i--);
         while (i !=0);
        P1OUT &= ~0x04; // set P1.2 to low
        _BIS_SR(LPM2_bits + GIE);
        }
};
}
 
#pragma vector=PORT1_VECTOR     //ISR FOR PORT1
__interrupt void P1(void)
{
P1OUT^= BIT3;            //TOGGLE
P1IFG&=~BIT3;                   //CLEAR THE INTERRUPT FLAG FOR PIN3
__bic_SR_register_on_exit(LPM2_bits);
 
}
 

Viewing all articles
Browse latest Browse all 2077

Trending Articles