X2.1 My cheat sheet for  programming MSP430 in C language.

 
  Variables, prefix:

                unsigned char  x;              //8bit
                unsigned int  y;                //16bit (by default)
                unsigned long  z;              //32bit
                unsigned long long  y;       //64bit ("double", is same as "long long")

                unsigned char port_out [7]={1,2,4,8,6,9,15};

                volatile unsigned int i;      //volatile to prev. removal (see last paragraph)
                static unsigned int k;        //seen from everywhere

                char *flash_m;                 // pointer to 8bit
                char *Flash_n;                 // pointer, the same



  Constant, in code memory, to save RAM:

                const int   T1 = 0x1234;
                const char T2 = 0x12;
                const char T3 = 'k';
                const char T4[]="Text or so";

                #define T1 (0x1234);      //instead of  "const int T1 = 0x1234;"



  Volatile, or not?

   Any variable which might be modified by something external to the obvious control flow of the program
(such as an interrupt service routine) must be declared volatile. This tells the compiler that an interrupt
function might modify the value at any time, so the compiler should not perform optimizations which will
change the number or order of accesses of that variable. This is the primary purpose of the volatile
keyword. (slau132r.pdf, "MSP430 Optimizing C/C++ Compiler", p.94)





16.02.2020  SKootS

_

 
 

Make a free website with Yola