Lvalue Required As Left Operand Of Assignment Avr Studio 5

  • 14th May 2015, 09:13#1

    Member level 2

    AVR code not working on Atmel Studio 6

    Hey there champions,
    I am back with another jug of problems.
    I have just started working on AVR Atmega16 microcontroller.
    And I am using Atmel Studio 6.
    I am very well familiar with the programming of PIC microcontroller on Microchip.
    And i find it quite easy to build.
    But i tried to program AVR in the same way of building logic as that of PIC and I it didn't work.
    Here is the code that I tried.

    PURPOSE OF CODE:
    To on an LED with a Button for ten seconds

    Here is the group of instructions that I wrote considering it complete code:
    """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

    Code:

    #include
    """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    When I tried it on proteus, nothing happens no matter how many times i press the button.
    Plus there is an error of internal exception on proteus and it crashes.
    Any help would be greatly appreciated. It is urgent for me.
    So please someone look for it.
    Eagerly waiting for the reply.
    Thanks in advance.

    Last edited by bigdogguru; 15th May 2015 at 13:36. Reason: Added CODE or SYNTAX Tags


    •   14th May 2015, 09:13


  • 14th May 2015, 13:51#2


    Re: AVR code not working on Atmel Studio 6

    Hi, LeoStar

    Code:

    #define SW1 PA0 //pin must be input (PINA.0 in CVAVR) #define LED1 PA1 void main() { DDRA=0xFE; PORTA=0x01; LED1<
  • 14th May 2015, 14:05#3

    Banned

    Re: AVR code not working on Atmel Studio 6

    See if ADC has to be disabled to make the pins digital IO. For input PINA0 has to be used.

    I don't use Atmel Studio much. I use mikroC PRO AVR Compiler. Here I am attaching a working project. You can test it in hardware. It is compiled for 4 MHz external oscillator.

    I have tested this in Proteus and it works fine. You can download and install demo version of mikroC PRO AVR Compiler and open the .mcpav file.

    Last edited by milan.rajik; 14th May 2015 at 14:29.


  • 15th May 2015, 05:45#4

    Member level 2

    Re: AVR code not working on Atmel Studio 6

    Thank you so much for replying guys.
    DeepOne i tried your way and got the following error:

    for the following line:
    Please tell me how to resolve this.
    And the pin is already configured as input pin(DDRA=0xFE;).
    And Milan thanks for advicing regarding the ADC, I will disable them and try it once again.

    And I don't want to quit working on Atmel Studio 6 as it is new for me and adds variety to my software list.
    I will find some other way of programming but wont quit working on it.
    I will set it as my last resort to work with MIKRO C PRO AVR.
    Thanks a lot for your precious time guys.
    Looking forward to hear from you soon again.
    Error 3 lvalue required as left operand of assignment

    Last edited by bigdogguru; 15th May 2015 at 13:38. Reason: Added CODE or SYNTAX Tags and QUOTE Tags for readability


  • 15th May 2015, 09:54#5


    Re: AVR code not working on Atmel Studio 6

    LED1=1< pin is already configured as input pin //of course, but it is necessary to address it as input register (PINA.0 in CVAVR)
    // ADC is already disabled after power on reset, according to datasheet

    •   15th May 2015, 09:54


  • 15th May 2015, 18:11#6


    Re: AVR code not working on Atmel Studio 6

    seems construction like PORTA.1 or PINA.0 is not work in Atmel Studio. So you may use equation like PORTA |= 1<

    Code:

    typedef unsigned int uint8_t; typedef struct Bits_t { uint8_t Bit0 :1; uint8_t Bit1 :1; uint8_t Bit2 :1; uint8_t Bit3 :1; uint8_t Bit4 :1; uint8_t Bit5 :1; uint8_t Bit6 :1; uint8_t Bit7 :1; }Bits; #define PortaBits (*((volatile Bits*)&PORTA)) #define PinaBits (*((volatile Bits*)&PINA)) #define LED1 PortaBits.Bit1 #define SW1 PinaBits.Bit0 void main() { DDRA=0xFE; PORTA=0x01; while(1) { if(SW1==0) { LED1=1; _delay_ms(10000); } else { LED1=0; } } }
  • 5th June 2015, 06:01#7

    Member level 2

    Re: AVR code not working on Atmel Studio 6

    Hello everyone,
    Long time no see.
    I have started working on MIKRO C PRO FOR AVR. I use it for pic as well and I consider it the best among the compilers.
    Here is the code that i am trying on it. It gets compiled without errors but when i try it on proteus the pin that is connected to led is low and the pin with the switch is high as well but when I push the button it doesnt work.
    Here is the code:
    *******************
    sbit SW1 at PinA.B0;
    sbit LED at PORTa.B1;
    void main()
    {
    DDRA=0xFE;
    PORTA.B0=1;
    if(!SW1)
    {
    LED=1;
    delay_ms(5000);
    }
    else
    LED=0;
    }
    +++++++++++++++++++++++++++
    And the attachment shows that the led doesn't glow even if the switch is pressed.

    Any help will be appreciated.

    And whenever I try it out on proteus there is an error and proteus crashes. I am attaching a snapshot of the error as well.

    Last edited by LeoStar; 5th June 2015 at 06:08. Reason: Updation regarding an erro


  • 5th June 2015, 06:59#8

    Banned

    Re: AVR code not working on Atmel Studio 6

    Try this project. It toggles LED on button press and release.


    Code C - [expand]
    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 sbit SW at PINA.B0; sbit LED at PORTA.B1;   void main(){       DDRA =0xFE;     PORTA =0x00;         while(1){         if(!SW){            Delay_ms(50);            if(!SW);               LED =1;         }         elseif(SW){              Delay_ms(50);              if(SW)                LED =0;         }     }}

    Last edited by milan.rajik; 5th June 2015 at 07:13.


    •   5th June 2015, 06:59


  • 5th June 2015, 12:22#9

    Member level 2

    Re: AVR code not working on Atmel Studio 6

    Thank you for your reply Milan, my code worked on proteus as well and now I have learned programming for AVR as well. As i told before I was very comfortable working with MICRO C so I made it to work.
    Thanks a lot for your precious time.


  • 23rd October 2015, 07:30#10

    Newbie level 3

    Re: AVR code not working on Atmel Studio 6

    You may still interested to try once more with Atmel Studio 6. Here is a great post with video and description:
    http://www.binaryupdates.com/learn-p...crocontroller/

    Happy Programming

    Good Luck


  • 28th October 2015, 13:18#11

    Newbie level 5

    Re: AVR code not working on Atmel Studio 6

    If you want to learn more about different keywords used to define data types please refer here.

    http://embeddedcubes.blogspot.in/201...6t-int32t.html


    1. Registered User
      Join Date
      Feb 2010
      Posts
      58

      lvalue required as left operand of assignment

      i get this error message for each of these lines when i try to run the program. i have no idea what it means. what am i doing wrong? there is a data file elsewhere in the program, and i'm reading info from that, and one column is numbers from 0-6. each of those corresponds to a name, which is what this function is supposed to do, equate the number to the family name. here's the portion of the code that's getting error
      string familyName( int familyCode ) { int n; inFile>>n; switch (n) { case 0: 0=Drake; break; case 1: 1=Spencer; break; case 2: 2=Morgan; break; case 3: 3=Corinthos; break; case 4: 4=Webber; break; case 5: 5=Quatermaine; break; case 6: 6=Davis; break; } }

    2. and the Hat of Guessing
      Join Date
      Nov 2007
      Posts
      14,185
      = is not symmetric in C++. The value on the right is placed in the variable on the left. Since 0, 1, ..., 6 are not variables, but constants, the assignment cannot happen.

    3. Registered User
      Join Date
      Feb 2010
      Posts
      58
      so i'd have to make each of the numbers variables in order for it to work? but that's not possible, is it?

    4. and the Hat of Guessing
      Join Date
      Nov 2007
      Posts
      14,185
      Last edited by tabstop; 03-26-2010 at 05:01 PM.
      The problem here is your belief, which I'm not sure where it came from, that somehow you want the number 0 to be assigned the value Drake. That's not what your English text at the top of your original post says you want to do, and it's not what anybody thinking about what your problem would want to do.

      (Hint: Your English text says that, for example, if familyCode is 0 you want some string to be "Drake".

    5. Registered User
      Join Date
      Apr 2006
      Posts
      2,146
      It is too clear and so it is hard to see.
      A dunce once searched for fire with a lighted lantern.
      Had he known what fire was,
      He could have cooked his rice much sooner.
      "equate" does not mean assign. It means create a logical mapping.

    6. Registered User
      Join Date
      Feb 2010
      Posts
      58
      bear with me here, i'm not knowledgeable at all in c++. i appreciate the help so far. so would declaring the family names as int solve the problem?


    7. Registered User
      Join Date
      Feb 2010
      Posts
      58
      ok, how do i set a number equal to the name? i need this program to read 0 from the text file and display drake. i have no idea whatsoever how to do this, i've declared them as strings and ints, i don't know what to do.


    8. Registered User
      Join Date
      Mar 2010
      Location
      Texas
      Posts
      4
      When you use the = operator, it takes the value on the right, and assigns it to a variable on the left. A value can be a number, a letter, a string of text, or another variable among other things.

      This statement:

      Won't work because '0' is not a variable (which is causing the "lvalue required as left operand of assignment" error). Another thing to remember is that a string must be put in "quotes", so unless Drake is a variable, that would also be a problem.

      Now, if I understand what you're trying to do, this should fix your problem:

      string familyName( int familyCode ) { int n; inFile>>n; switch (n) { case 0: cout<<"Drake"; break; case 1: cout<<"Spencer"; break; case 2: cout<<"Morgan"; break; case 3: cout<<"Corinthos"; break; case 4: cout<<"Webber"; break; case 5: cout<<"Quatermaine"; break; case 6: cout<<"Davis"; break; } }
      I'm new to coding myself, so lemme know if I got something wrong, but this should help.

    9. Registered User
      Join Date
      Feb 2010
      Posts
      58

      oh christ, cout<<... why on earth did i not think of that. thank you much, kind sir. thanks to everyone else as well. it's been a long day , ha

    10. Registered User
      Join Date
      Mar 2010
      Location
      Texas
      Posts
      4



    One thought on “Lvalue Required As Left Operand Of Assignment Avr Studio 5

    Leave a Reply

    Your email address will not be published. Required fields are marked *