Hello,
I am a novice MSP430 user.
I am trying MSP430 launch pad with MSP430g2553 chip.
I am using code composer studio version 4.2.4.00033
As far as I understand C language when using IF-ELSE or a WHILE loop
the condition tested is checked for being true(non zero value) or false(zero value)
example: IF (condition is true or a value > 0){
do xyz;
}
ELSE (condition is false or zero){
do abc;
}
similarly
WHILE( condition is true / non zero)
{
do xyz....
}
But when I try the following code
while ((P1IN & 0x08) == 0);
The program gives me a compilation error stating ' expected an expression'.
This same construct compiles for a IF statement without an error.
Is there some thing wrong I am doing? or is this how any C compiler should behave?
I have put my code below for consideration:-
**************************************************************************
#include <msp430g2553.h>
#include <stdio.h>
volatile char test;
void InitializeSwitch(void);
void main(void) {
WDTCTL = WDTPW + WDTHOLD;
InitializeSwitch();
P1DIR |= BIT0; // this is for making LED as output pin
while( 1 ) {
if( (P1IN & 0x08) == 0)
{
P1OUT |= BIT0;
//while ((test=(P1IN & 0x08)) == 0); // this works !!!
while (P1IN & 0x08) == 0); // this doesn't work
}
else
P1OUT &= ~BIT0;
}
}
void InitializeSwitch(void)
{
P1DIR &= ~BIT3; // this is for making switch as input
P1REN |= BIT3; //ENABLES PULL UP RESISTOR
P1OUT |= BIT3;// PULLUP RESISTOR PULLED TO VDD
Hope I have expressed myself clearly!
Regards
Asimov