문제

I am now doing a program for a MSP430 in C and I am using Port 1.6, 1.7, 2.0, 2.1, and 2.2 to drive some LEDs. Now, in order to turn ON all LEDs I simply have to write:

P1OUT |= 0xC0; 
P2OUT |= 0x07;

However, I would like to know if is possible to create an C structure (with the name LED_ACTIVATION) that points to bits 0, 1, and 2 of the P2OUT Register (0x0029) and to bits 6 and 7 from P1OUT Register (0x0021), that will allow me to write something like this:

LED_ACTIVATION = 0x2F;

where port 2.2 is the most significant bit (bit 5) and port 1.6 is the lowest significant bit(bit 0).

In the MSP we can do this assignment for each register like this:

__no_init volatile union
{
  unsigned char P1OUT;   /* Port 1 Output */

  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;

or like this:

#define P1OUT_              (0x0021u)  /* Port 1 Output */
DEFC(   P1OUT             , P1OUT_)

But is it possible to mix both register address?

Thanks.

도움이 되었습니까?

해결책

The MSP430 is not bit/pin addressable. So, no, you can't create a structure that contains individual pins from multiple ports.

In order to make:

LED_ACTIVATION = 0x2F;

You would need to use a function or a macro.

See also: Accessing individual I/O pin on MSP430

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top