My question is that when using any microcontroller, the example MSP430
You are not using a microcontroller, you are using an MSP430. It has an IO memory with memory mapping (which is very nice to use for us programmers). The display of memory varies by device. Answers to any questions related to the address can be found in the user guide for your specific device. TI makes a very good user guide. Find it for your specific device and read it carefully.
My question is how he writes to this address, for example. in this case 0x0021. IDE - IAR.
Compiler glue code. Your compiler’s provider will provide you with the necessary headers, macros, and functions to write to your device’s addresses. Use the code of the compiler provider if you can’t absolutely prove that it doesn’t work for your business (with IAR I would assume that 99.9% of this works, you get what you pay for. Perhaps there are implementation errors with a completely new device but probably not if you cannot prove it).
Also let me know what u means in 0x0021u?
From what you posted, this is the base address for port 1. It looks like you have 8 contacts on port 1 that you can control.
#pragma language=extended
From now on, you should assume that there are all kinds of “magic” (aka non-standard C) things that will happen. You can conclude what, in your opinion, the compiler does (and, for the most part, it is quite clear), however, this implementation is defined, which means that only the IAR compiler supports what comes next. Look at the compiler documents for specific commands and values. In particular, the characters __no_init and @ are not standard. __no_init will not initialize the variable when starting C (i.e. before starting main ()). @ Looks like an absolute address instruction to be provided to the linker (I may be wrong here).
__no_init volatile union { unsigned char P1OUT; struct { unsigned char P0 : 1; unsigned char P1 : 1; unsigned char P2 : 1; unsigned char P3 : 1; unsigned char P4 : 1; unsigned char P5 : 1; unsigned char P6 : 1; unsigned char P7 : 1; }P1OUT_bit; } @0x0021;
This determines how to get specific byte bits for port 1. This allows you to manipulate IO pins. Some would say that OMG bitcodes are portable, implementation defined! Yes, they are right, but IAR is a developer, so in this case, just trust them to do the right thing.
Finally, you probably just want to use IAR macros as defined. You paid them a lot of money (unless you are using the free kickstart version). You can focus on writing your application and not manipulate bits this way. IAR does a good job of standardizing its names, so you can also use the same code (or very similar) for related parts. If you switch to another compiler, all of this will exit the window, and you will need to do this in a new compiler way. Good and bad points to this approach, there is probably no “right” answer.