Thread: CCS gave he a #29 expected an expression error, can anyone help fix it?

  1. #1
    Registered User
    Join Date
    Jul 2019
    Posts
    3

    CCS gave he a #29 expected an expression error, can anyone help fix it?

    in line 49, int i=0, i got the error
    Code:
    #include <msp430g2553.h>
    #include <stdio.h>
    
    
    #define OTROWS  P1OUT
    #define ROW1    BIT0
    #define ROW2    BIT1
    #define ROW3    BIT2
    #define ROW4    BIT3
    #define ALLROWS (ROW4 | ROW3 |ROW2 |ROW1)
    
    
    #define INCOLS  P1IN
    #define COL1    BIT4
    #define COL2    BIT5
    #define COL3    BIT6
    #define COL4    BIT7
    #define ALLCOLS (COL4 | COL3 | COL2 |COL1)
    
    
    // Declarations
    int rownum, keynum, ROWS;
    
    
    int main()
    {
        WDTCTL =  WDTPW + WDTHOLD; // Stop Watch Dog Timer
        P1DIR  =  0x00;            // Set port 1 all inputs
        P1DIR |=  ALLROWS;         // Set all rows as output
        P1REN |=  ALLCOLS;         // Enable resistors for all columns
        P1OUT |=  ALLCOLS;         // Make those resistors pullups
        P1IES |=  ALLCOLS;         // Interrupt edge selec, hi to lo
        P1IE  |=  ALLCOLS;         // Enable interrupt on all columns
        P1IFG &= ~ALLCOLS;         // Clear all interrupt flags on the columns
    
    
        P2DIR |= BIT5;
        int i=0;
        __enable_interrupt();      //enable interrupts
        OTROWS &= ~(ALLROWS);      //Assert low on all rows low to detect any key stroke interrup
        __delay_cycles(200);
    
    
        while(1) {// main loop empty
    
    
         P2OUT ^=BIT5,
        // call the following delay keynum number of times
                 int i=0;
                 for(i=0;i<=keynum;i++);
         {
            if (i==keynum)break; //this tell the loop to stop after the flash reaches the number entered
           __delay_cycles(200000);
         }
    
                 }
    
    }
    
    
    // Port 1 interrupt service routine
    #pragma vector=PORT1_VECTOR
    __interrupt void Port_1(void)
    {
        __delay_cycles(200);
        OTROWS |= ALLROWS;//Make all rows high
        __delay_cycles(200);
        keynum=0;
        for(rownum=0; rownum<=4; rownum++)          //Start scanning the KP
            {
                //start a 1 in first roww and shift left rownum times, and XOR
                OTROWS = ((ROW1<<rownum) ^ ALLROWS); __delay_cycles(200);
                if(!(INCOLS & COL1)) {keynum=4*rownum +1;}
                if(!(INCOLS & COL2)) {keynum=4*rownum +2;}
                if(!(INCOLS & COL3)) {keynum=4*rownum +3;}
                if(!(INCOLS & COL4)) {keynum=4*rownum +4;}
    
    
        OTROWS &= ~ALLROWS;  __delay_cycles(200);   //Make all rows low to for next key stroke interrupt
        P1IFG  &= ~ALLCOLS;  __delay_cycles(200);   //Clear the interrupt flags
        __delay_cycles(200);
    
    
    }
    }
    can anyone give me tips on how to fix this?

  2. #2
    Registered User
    Join Date
    Feb 2019
    Posts
    1,078
    Probably a very old compiler, pre C99 standard (don't allow for "inplace" identifiers declarations).

  3. #3
    Registered User
    Join Date
    Jul 2019
    Posts
    3
    Quote Originally Posted by flp1969 View Post
    Probably a very old compiler, pre C99 standard (don't allow for "inplace" identifiers declarations).

    I have version 9.0.1

  4. #4
    Registered User
    Join Date
    May 2019
    Posts
    214
    To my eye:

    Code:
      P2OUT ^=BIT5,    // call the following delay keynum number of times
    
                 int i=0;
    
                 for(i=0;i<=keynum;i++);
    
         {
    
            if (i==keynum)break; //this tell the loop to stop after the flash reaches the number entered
    
           __delay_cycles(200000);
    
         }
    The first line ends in a ",", when I am fairly sure it should end in a ";", but then I'm not sure I see what a P2OUT is.

  5. #5
    Registered User
    Join Date
    Jul 2002
    Posts
    33
    i is declared twice also.

  6. #6
    Registered User
    Join Date
    Jul 2019
    Posts
    3
    I got it working, thank you all for the advice

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > for(i=0;i<=keynum;i++);
    The ; at the end of this line makes your loop do nothing.

    In particular, this block of code will only run once (with an out of range value for i), rather than keynum+1 times.
    Code:
       {
          if (i==keynum)break; //this tell the loop to stop after the flash reaches the number entered
         __delay_cycles(200000);
       }
    It also means the break exits your while(1) loop, not your for loop.

    Beware of weird behaviour caused by writing to keynum in an ISR and reading it in main.
    Your compiler might believe keynum is invariant in main, and optimise accordingly.

    Consider making keynum volatile.

    Also, calling any kind of delay in an ISR is usually a sign of bad design.
    Across all the delays, you have the equivalent of __delay_cycles(2000);
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. HELP - error: expected expression before â=â token
    By capitalCORN in forum C Programming
    Replies: 4
    Last Post: 11-14-2014, 09:13 AM
  2. Expected expression error
    By Peter Barnett in forum C Programming
    Replies: 3
    Last Post: 09-10-2013, 11:16 AM
  3. Error: expected primary expression and ; before else
    By dragonfly22 in forum C++ Programming
    Replies: 5
    Last Post: 09-17-2012, 04:24 PM
  4. error: expected an expression
    By cdmstr in forum C++ Programming
    Replies: 3
    Last Post: 02-12-2011, 02:00 PM
  5. Error: expected an expression!
    By bobthebullet990 in forum C Programming
    Replies: 2
    Last Post: 01-05-2007, 09:05 AM

Tags for this Thread