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

different notation

Hello guys,

just a silly question,
is it possible to modify code to a different notation:

//**************************************************************************
void SPI_send_8(unsigned int a)
{
        SPITX = a;
        while(!(SPISTA & 0x04)){}
}
//**************************************************************************

to:

//**************************************************************************
void SPI_send_8(unsigned int SPITX)
{
        while(!(SPISTA & 0x04)){}
}
//**************************************************************************


SPITX is the SPI TX.

  • void SPI_send_8(unsigned int SPITX)
    

    will likely have space on the stack utilized for the SPITX parameter. so this is not the same as the original expression which addresses the global. your piece of code will hide the global memory mapped variable SPITX and replace it this the stack/register allocated one, having no effect on the peripheral.

  • Georg,
    I have corrected the spelling mistakes:

    will likely have space on the stack utilized or a register assigned for the SPITX parameter. so this is not the same as the original expression which addresses the global. your piece of code will hide the global memory mapped variable SPITX and replace it with the stack/register allocated one, having no effect on the peripheral.

  • The "SPITX" variable you want to work with is a SFR, i.e. a magic global variable that maps to the hardware. Because of this, you can not do any rewrites and create own variables with the same name and still get the intended behaviour.

    Some compilers may declare SFR (Special Function Registers) as external variables at fixed location, and some compilers will have an include file that uses the preprocessor to convert the SFR name into direct pointer manipulation to access the relevant address.

    If the compiler uses external variables, you will be able to create local variables with the same name - but obviously with different behaviour. If the compiler uses the preprocessor, your code will be completely garbled when the preprocessor performs the same replace operations even where the syntax can't be accepted. Your parameter name may be expanded into *(unsigned int*)(0xabcd1234) which is obviously not an allowed parameter name.