This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/MSP432P401R: #664 Expected an integer constant error

Part Number: MSP432P401R

Tool/software: Code Composer Studio

For context I am taking the last 3 digits of someones ID# and then using that as a way to control the delay time of the onboard LED's blinking where I am having issues with the __delay_cycles(); function with it saying that it expected an integer constant even though I am supplying it an integer where not even making my integer name Red_light a const int seems to fix the issue, what suggestions would you give me as a way of fixing this problem? 

#include "msp.h"

void main(void)
{
WDT_A->CTL = WDT_A_CTL_PW | WDT_A_CTL_HOLD; // stop watchdog timer

char ID[2];
printf("Please enter in the last 3 digits of your school ID \n"); //this part of the code has the user enter in a number as a string of characters
scanf("%s", &ID); //that will then be converting to integers down below

int n1 = ID[0] - '0'; //These three lines succusfully convert the char's back into int's just follow the
int n2 = ID[1] - '0'; // int n1 = some number - '0' formula;
int n3 = ID[2] - '0';

const int Red_light = (n1 * 10) * 1000; //constant integer values meant to go inside of the
const int Green_light = (n2 * 10) * 1000;// __delay_cycles() function;
const int Blue_light = (n3 * 10) * 1000;

while(1){
P1DIR = P1DIR | 0x09; //P2.0 to logic one
__delay_cycles(Red_light);//Delay before turning off
P1DIR = 0x00;

P2DIR = P2DIR | 0x02;//GREEN light
P2OUT &= 0xFE; //P2.0 to logic zero
P2OUT |= 0x02; //P2.1 to logic one
P2OUT &= 0xFB; //P2.2 to logic zero
__delay_cycles(Green_light);//Delay

P2DIR |= 0x04; //BLUE
P2OUT &= 0xFE; //P2.0 to logic zero //BLUE light
P2OUT &= 0xFD; //P2.1 to logic zero
P2OUT |= 0x04; //P2.2 to logic one
__delay_cycles(Blue_light);//Delay before turning off
P2DIR = 0x00;

}
}

  • Seastian Garcia said:
    I am having issues with the __delay_cycles(); function with it saying that it expected an integer constant even though I am supplying it an integer

    As explained in the documentation for the  __delay_cycle Intrinsic:

    The number of cycles delayed must be a compile-time constant.

    Whereas the Red_light, Green_light and Blue_light are not compile-time constants because they depend on the value of ID read at run-time.