i am using the code below..i have a switch which connects the pin 1.3 to vcc. But it seems to be stuck in an infinite loop in the block after the if statement. When i changed the code to read logic low ( 0V) by replacing 1 in the if statement with 0. It works absolutely perfect.. Why there is then a problem with Logic High?
#include <msp430g2231.h>
#define LED BIT0
#define LED2 BIT6
#define SWC BIT3
void delayMS(unsigned int ms ) // MS delay function
{
unsigned int i;
for (i = 0; i<= ms; i++)
__delay_cycles(500);
}
void FaultRoutine()
{ P1DIR|=LED2;
P1OUT|=LED2;
}
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
P1DIR|=LED; //led output
P1OUT&=~LED; //turnoff led
if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
FaultRoutine(); // If calibration data is erased
// run FaultRoutine()
BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation
while(1)
{
if((P1IN & SWC))
{
P1OUT^=LED;
delayMS(500); //debounce Delay
}
}
}
Edit: (after 30 mins of posting) I tried to use the crystal pin as I/0 and used the same logic on it. Its works now. Does that mean that we cant use the same port as I and O?
I think i am missing some thing..
Thanks and Regards,
Rohit