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.

#138 expression must be a modifiable lvalue

Other Parts Discussed in Thread: TMS570LS1224

Hi friends,

Currently I am using TMS570LS1224 and trying to display number on display. Here I written some code and getting ERROR (expression must be modified lvalue) .


void Display_Speed(int data)
{
// int value_digit[4],num = data,d0,d1,d2,d3,digit_count = 0;

int value_digit[4],num,d0,d1,d2,d3,digit_count,a;
num = data;                           // ERROR: expression must be a modifiable lvalue
digit_count = 0;

while(num > 0)
{
value_digit[digit_count] = num % 10;
num = num/10;                   // ERROR: expression must be a modifiable lvalue
digit_count++;
}

d0 = value_digit[0];
d1 = value_digit[1];
d2 = value_digit[2];
d3 = value_digit[3];
i2cSendByte(i2cREG1,d0); // Clear Digit

}

regards,

arvind

  • I cannot reproduce this error ...

    Arvind Upadhyay said:
    num = data;                           // ERROR: expression must be a modifiable lvalue

    Please submit a more complete test case.  Preprocess the source file which contains this function, and attach it to your next post.  Indicate the version of the compiler you use.  And show the build options exactly as the compiler sees them.

    Thanks and regards,

    -George

  • Hi George,

    Here I attched my sys_main.c file. I am using TI v5.2.6 compiler version , and also when I am using number instead of num it is not showing any ERROR.

    Regards,

    Arvind.

    sys_main.c
    /** @file sys_main.c 
    *   @brief Application main file
    *   @date 28.Aug.2015
    *   @version 04.05.01
    *
    *   This file contains an empty main function,
    *   which can be used for the application.
    */
    
    /* 
    * Copyright (C) 2009-2015 Texas Instruments Incorporated - www.ti.com 
    * 
    * 
    *  Redistribution and use in source and binary forms, with or without 
    *  modification, are permitted provided that the following conditions 
    *  are met:
    *
    *    Redistributions of source code must retain the above copyright 
    *    notice, this list of conditions and the following disclaimer.
    *
    *    Redistributions in binary form must reproduce the above copyright
    *    notice, this list of conditions and the following disclaimer in the 
    *    documentation and/or other materials provided with the   
    *    distribution.
    *
    *    Neither the name of Texas Instruments Incorporated nor the names of
    *    its contributors may be used to endorse or promote products derived
    *    from this software without specific prior written permission.
    *
    *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
    *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
    *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
    *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
    *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
    *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
    *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
    *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    *
    */
    
    
    /* USER CODE BEGIN (0) */
    /* USER CODE END */
    
    /* Include Files */
    
    #include "sys_common.h"
    
    /* USER CODE BEGIN (1) */
    #include "i2c.h"
    #include "system.h"
    #include "sys_core.h"
    /* USER CODE END */
    
    /** @fn void main(void)
    *   @brief Application main function
    *   @note This function is empty by default.
    *
    *   This function is called after startup.
    *   The user can use this function to implement the application.
    */
    
    /* USER CODE BEGIN (2) */
    #define DATA_COUNT  2
    
    #define Master_Address 0x26
    #define Slave_Address  0b0111000
    #define num 0x0F
    uint8_t TX_Data_Slave[10] = { 0x01,0x07,0x02,0x20,0x03,0x03,0x04,0x01,0x20,0x01};
    
    void Display_Speed(int data)
    {
    //  int value_digit[4],num = data,d0,d1,d2,d3,digit_count = 0;
    
      int value_digit[4],number;
      uint8_t d0,d1,d2,d3,digit_count;
      num = data;
      digit_count = 0;
    
      while(number > 0)
      {
    	value_digit[digit_count] = num % 10;
    	num /= 10;
    	digit_count++;
      }
    
      d0 = value_digit[0];
      d1 = value_digit[1];
      d2 = value_digit[2];
      d3 = value_digit[3];
    
      i2cSetStart(i2cREG1);
      i2cSendByte(i2cREG1,0x20);   //digit 0
      while((i2cREG1->STR>>1)&1 == 1);
      i2cSendByte(i2cREG1,d3);    //Normal Mode,Global Data Clear,Device Read back
      while((i2cREG1->STR>>1)&1 == 1);
      i2cSetStop(i2cREG1);
    
      i2cSetStart(i2cREG1);
      i2cSendByte(i2cREG1,0x21);   //digit 1
      while((i2cREG1->STR>>1)&1 == 1);
      i2cSendByte(i2cREG1,d2);    //Normal Mode,Global Data Clear,Device Read back
      while((i2cREG1->STR>>1)&1 == 1);
      i2cSetStop(i2cREG1);
    
      i2cSetStart(i2cREG1);
      i2cSendByte(i2cREG1,0x22);   //digit 2
      while((i2cREG1->STR>>1)&1 == 1);
      i2cSendByte(i2cREG1,d1);    //Normal Mode,Global Data Clear,Device Read back
      while((i2cREG1->STR>>1)&1 == 1);
      i2cSetStop(i2cREG1);
    
      i2cSetStart(i2cREG1);
      i2cSendByte(i2cREG1,0x23);   //digit 3
      while((i2cREG1->STR>>1)&1 == 1);
      i2cSendByte(i2cREG1,d0);    //Normal Mode,Global Data Clear,Device Read back
      while((i2cREG1->STR>>1)&1 == 1);
      i2cSetStop(i2cREG1);
    
    }
    
    void DisplayT_Speed(int data)
    {
    
     // i2cREG1->DXR = (uint32)0x00;
      i2cSetStart(i2cREG1);
      i2cSendByte(i2cREG1,0x20);   //digit 3
      i2cSendByte(i2cREG1,data);    //Normal Mode,Global Data Clear,Device Read back
      i2cSetStop(i2cREG1);
     // Delay_ms(30);
    }
    
    void Init_Display()
    {
    	 i2cInit();
    
    	 /* Configure address of Slave to talk to */
    	 i2cSetSlaveAdd(i2cREG1, Slave_Address);
    
    	 /* Set direction to Transmitter */
    	 /* Note: Optional - It is done in Init */
    	 i2cSetDirection(i2cREG1, I2C_TRANSMITTER);
    
    	 i2cSetMode(i2cREG1, I2C_MASTER);
    
    	 /* Set Stop after programmed Count */
    	 i2cSetStop(i2cREG1);
    
    	 i2cSetStart(i2cREG1);
         i2cSendByte(i2cREG1,0x04);  //Configure register
    	 while((i2cREG1->STR>>1)&1 == 1);
    	 i2cSendByte(i2cREG1,0x21);  // Clear Digit
    	 while((i2cREG1->STR>>1)&1 == 1);
    	 i2cSetStop(i2cREG1);
    
    	 i2cSetStart(i2cREG1);
      	 i2cSendByte(i2cREG1,0x01);    //Decode Mode
    	 while((i2cREG1->STR>>1)&1 == 1);
    	 i2cSendByte(i2cREG1,0x0F);    //Decode for 4 digit 0-3
    	 while((i2cREG1->STR>>1)&1 == 1);
    	 i2cSetStop(i2cREG1);
    
    	 i2cSetStart(i2cREG1);
    	 i2cSendByte(i2cREG1,0x02);  // Intensity Control
    	 while((i2cREG1->STR>>1)&1 == 1);
    	 i2cSendByte(i2cREG1,0x20);  // 0.72 mA
    	 while((i2cREG1->STR>>1)&1 == 1);
    	 i2cSetStop(i2cREG1);
    
    	 i2cSetStart(i2cREG1);
    	 i2cSendByte(i2cREG1,0x03);  //Scan Register
    	 while((i2cREG1->STR>>1)&1 == 1);
    	 i2cSendByte(i2cREG1,0x03);  //Scan 4 digit
    	 while((i2cREG1->STR>>1)&1 == 1);
    	 i2cSetStop(i2cREG1);
    
    	i2cSetStart(i2cREG1);
    	i2cSendByte(i2cREG1,0x20);   //Digit 0
    	while((i2cREG1->STR>>1)&1 == 1);
    	i2cSendByte(i2cREG1,0);  // display 0
    	while((i2cREG1->STR>>1)&1 == 1);
    	i2cSetStop(i2cREG1);
    
    	i2cSetStart(i2cREG1);
    	i2cSendByte(i2cREG1,0x21);   //digit 1
    	while((i2cREG1->STR>>1)&1 == 1);
    	i2cSendByte(i2cREG1,0);  // display 0
    	while((i2cREG1->STR>>1)&1 == 1);
    	i2cSetStop(i2cREG1);
    
    	i2cSetStart(i2cREG1);
    	i2cSendByte(i2cREG1,0x22);   //Digit 2
    	while((i2cREG1->STR>>1)&1 == 1);
    	i2cSendByte(i2cREG1,0);  // display 0
    	while((i2cREG1->STR>>1)&1 == 1);
    	i2cSetStop(i2cREG1);
    
    	i2cSetStart(i2cREG1);
    	i2cSendByte(i2cREG1,0x23);   //digit 3
    	while((i2cREG1->STR>>1)&1 == 1);
    	i2cSendByte(i2cREG1,0);  // display 0
    	while((i2cREG1->STR>>1)&1 == 1);
    	i2cSetStop(i2cREG1);
    
    }
    
    void Delay_ms( int delay)
    {
    	int count1,count2;
    	for( count1 = 0; count1 < delay ; count1++)
    	{
    		for( count2 = 0; count2 < 11000 ; count2++);
    	}
    
    }
    /* USER CODE END */
    
    void main(void)
    {
    /* USER CODE BEGIN (3) */
            int data = 4;
    
            Delay_ms(500);
    
    ///////////////////////////////////////////////////////////////
    //        Master Transfer Functionality                      //
    ///////////////////////////////////////////////////////////////
            /* I2C Init as per GUI
             *  Mode = Master - Transmitter
             *  baud rate = 100KHz
             *  Count = 10
             *  Bit Count = 8bit
             */
    
            Init_Display();
            while(1)
            {
              DisplayT_Speed(data++);
              Delay_ms(300);
              i2cSetStart(i2cREG1);
    		  i2cSendByte(i2cREG1,0x40);   //digit 3
    		  i2cSendByte(i2cREG1,0x21);    //Normal Mode,Global Data Clear,Device Read back
    		  i2cSetStop(i2cREG1);
              Delay_ms(2);
            }
           // while(1);
    /* USER CODE END */
    }
    
    /* USER CODE BEGIN (4) */
    /* USER CODE END */
    

  • You are trying to assign a value (i.e. data) to a constant (i.e. #define num 0x0F).
  • Thank you stevenh.