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

 
  Set/Reset/Toggle


 while(1)
  {
    P1OUT |= 0x02;
          // P1.1 = 1
    P1OUT &= ~BIT1;      // P1.1 = 0
    P1OUT ^= 0x01;         // Toggle P1.0
  }



  Bitwise Operators

 k = i & j ;          //  AND: 0010 & 0110 =  0010  ( 1 if the bits match )
 k = i  |  j ;          //   OR:   0010  |  0110 =  0110  ( 1 if there or there )
 k = i  ^  j ;         //  XOR: 0010  ^ 0110 =  0100  ( 1 if bits do not match )

 m = k >> 4;
 n = k << 2 ;


  Shorthand notations in C.


    a++;         //    a=a+1
    c --;          //    c=c-1
    c *= 2;     //    c=c*2
    c+=4;       //   c=c+4
    a + = b;   //   a=a+b
    a<<=b;    //   a=a<<b
    a&=b;     //    a=a&b
    a^=2;       //   a=a^2  (XOR)










16.02.2020  SKootS

_

 
 

Make a free website with Yola