Other Parts Discussed in Thread: MSP430G2231, MSP430G2452
I am fairly new to the MSP430 and i am having trouble figuring out how to accomplish what i would like to do with my program. What i would like to do is when i press a button the corresponding LED would light up and when i let go the LED would turn off. however right now all my program does is light the LED and then stay in its state and not return to the main program loop. Any help would be appreciated.
Thank you.
Pierre
// this is to test out some of the functions of the elvis model using an MSP430 micro.
#include <msp430g2231.h>
#define LED1 BIT0 //Red LED on the borad
#define LED2 BIT6 //Green LED on the board
#define HSR BIT1 //Head Shift Right connects to Pin 2 on J47
#define HSL BIT2 //Head Shift Left connects to Pin 3 on J47
#define BTNL BIT4 //button to move left
#define BTNR BIT5 //button to move right
/* Global Variables */
char i=0; // char values are used to preserve memory
char bcs_vals[3] = {7,9,2};
char dco_vals[3] = {3,5,6};
/* Function Declarations */
void delay(void);
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
P1OUT = 0x42;
P1DIR = LED1+LED2+HSR+HSL;
P1IES |= BIT3+BTNL+BTNR; //high -> low is selected with IES.x = 1
P1IFG &= ~BIT3+BTNL+BTNR; //to prevent an immediate interrupt, clear the flag for P1.3 before enabling the interrupt.
P1IE |= BIT3+BTNL+BTNR; //enable interrupts for P1.3
_enable_interrupt();
for (;;)
{ // Note the change in method; rather than flashing 5
P1OUT ^= LED1|LED2;//+LED2; // times, this program flashes the LED continuously.
//P1OUT ^= LED2;
//P1OUT ^= HSR;
//P1OUT ^= HSL;
delay();
}
} // main
void delay(void)
{
unsigned int n;
for (n=0; n<60000; n++);
} // delay
#pragma vector = PORT1_VECTOR
__interrupt void P1_ISR(void)
{
switch(P1IFG& (BIT3|BTNL|BTNR))
{
case BIT3:
P1IFG &= ~BIT3; //clear the interrupt flag
BCSCTL1 = bcs_vals[i];
DCOCTL = dco_vals[i];
if (++i ==3)
i = 0;
return;
case BTNL:
P1IFG &= ~HSL; //clear the interrupt flag
P1OUT = HSL;
return;
case BTNR:
P1IFG &= ~HSR; //clear the interrupt flag
P1OUT = HSR;
return;
default:
P1IFG = 0; //probley unnecessary, but if another flag occurs in p1, this will clear it.
//no error handling is provided this way, though
return;
}//switch
}//P1_ISR