This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Error C213

Hello,

In trying to compile the C code with the C51
compiler [Keil µvision2], I received error c213 "left side of asn-op not an lvalue" -
" the address of a changeable object is required at the right side of the
assignment operator". But i don't know where is/are problems...

Code:
#include <Chipcon\srf04\regssrf04.h>
#include <Chipcon\srf04\halsrf04.h>
#include <Chipcon\srf04\ebsrf04.h>
#include <ctype.h>

#define TX_entree 0x80 //P0.4
#define RI0 0x98

BYTE idata txBuffer[8];
BYTE idata buffer[8];
int i = 0;
int taille_tab;

void main () {

#ifdef STAND_ALONE

CLOCK_INIT();
IO_PORT_INIT();

#endif

ebLcdInit();
ebLcdUpdate("Emission test v0.1", NULL);
halWait(3000);
ebLcdUpdate("Initialisation", NULL);
halWait(2000);
halUartSetup(UART_BAUDRATE_115200, DEFAULT_MODE);

SPI_INIT(SCLK_6_MHZ);
POWER_UP_RESET_CCxxx0(); FIRST ERROR
UART_RX_ENABLE();
ebLcdUpdate("Reception et stockage des données en cours", NULL);
halWait(3000);


if(RI0 == 1){
//stockage des données
taille_tab = sizeof(buffer);
for (i = 1; i < taille_tab; i++) {
UART_WAIT_AND_RECEIVE(buffer[i]); SECOND ERROR IF I COMMENT THE FIRST
}
}
ebLcdUpdate("Emission des données en cours", NULL);
halWait(2000);
SPI_ENABLE();
halRfSendPacket(buffer, sizeof(buffer));
ebLcdUpdate("Fin", NULL);
halWait(2000);
}

Any help or comments appreciated. I'm workin' on the CC2500DK, it's an tranceiver HF and many fonctions has already created by the constructor.

Thanks

John

Parents Reply Children
  • ....obfusciate the code."

    I don't know, the caps in the macro name scream 'MACRO!' to me.


    If you "scream" macro, the why use the do_while_0 which have no other purpose than to make it look like a function call?

    Erik

  • Many C programmers do not realize that you can declare local blocks inside functions. That is,

    void main (void)
        {
        int i;
    
        // code goes here
    
        { // local block
        int j;
    
        // some code
        } // end of local block
    
        // more code goes here
    
        } // main
    

    is perfectly legal syntax. I've often seen people wrap their macro body in a do-while(0) just to get a local block that executes once. Just the curly braces will do in most cases.

    Another place I find local blocks handy is in switch statements.

        switch (msg->type)
            {
            case MsgTypeA :
                {
                MsgA* msgA = (MsgA*)msg;
                // variables for handling msg A
    
                msgA->fieldA...
                }
                break;
    
            case MsgTypeB :
                {
                MsgB* msgB = (MsgB*)msg;
                // vars needed only for B
    
                msgB->fieldB...
                }
                break;
    
            default :
                break;
            }
    

    The example casts shown presume that each message type has its own structure definition for the contents of that message. The cast just cleans up syntax within the block. A good compiler will notice that there's really only one "msg" variable here, and that the difference is all source-level semantics.

    One caveat for this sort of usage is that C51 doesn't seem to handle variable declarations in local blocks well. It essentially promotes the variables outside the block, so they occupy "stack" space for the entire existence of the function, rather than existing just in the scope of the local block. The variables from two such local blocks do not get overlaid, even though they could be, and so "stack" usage is higher than it could be (but no higher than if you omitted the local blocks entirely and moved the declarations up to the enclosing block).

  • Another place I find local blocks handy is in switch statements.

    Well I guess we know Drew is among those of us with the misfortune to have written a Windows WndProc or two. :)