Quantcast
Channel: MSP low-power microcontroller forum - Recent Threads
Viewing all articles
Browse latest Browse all 21936

CCS/MSP430FR5969: Control LED With Switch | Software | Pull up Register

$
0
0

Part Number:MSP430FR5969

Tool/software: Code Composer Studio

I am trying to control led with the help of switch. Here's the code

#include <msp430.h> 
#define switch_state (P1IN & 0x02)

void main(void) {

    WDTCTL = WDTPW | WDTHOLD;		// Stop watchdog timer
    PM5CTL0 &= ~LOCKLPM5;

/************	Configure CS Registers  **************/
      	CSCTL0_H = 0xA5;			//UNLOCK CS Registers
      	CSCTL1_H = 0x00;			//Set DCO to 8Mhz
      	CSCTL1_L = 0x0c;
      	CSCTL2   = 0x0003 | 0x0100 | 0x0030;	//setting DCO = SMCLK = MCLK
      	CSCTL3   = 0x0000 | 0x0000 | 0x0000;	// for now setting the divider value to 1
      	CSCTL0_H = 0x00;			// lock the CS registers
/****************************************************/

      	P1DIR |=  0x01;
      	P1OUT |=  0x01;					//Initally led is on P1.0

    	P1DIR |=  0x02;
     	P1OUT |=  0x02;					//P1.1 is initial high

     	P1DIR &=  0xFD;					//P1.1 set at input pin

     	while(1) {

      		if ((switch_state)==0x00) { 		//if switch pressed, turn led on
      			P1OUT |=  0x01; 		//Do I require a pull up register ?
      		       while((switch_state)==0x00); 	//keep led on until switch released
      		}

      		P1OUT &=  ~0x01;
      	}//end of while(1)

}

During debugging, I found out that once 2nd bit of Port1 is becoming low, it's never going to get back to high. It enters the if() and gets stuck at

while((switch_state)==0x00);

 Is there any software/code change that could help correct this problem? 


Viewing all articles
Browse latest Browse all 21936

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>