This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

trouble

Other Parts Discussed in Thread: MSP430G2231

i'am begining with MCU, and i wrote the code by C language for MSP430g2231, i don't know how to define for a bit. for example, using bit_3 of port1 for input(a button), and bit_0 of port 1 for output(light Led). when i press the button the output=1(turn on/off the led). when i compile the code, there is an erro at the first line. i don't know how to define for (in/out)bit. please help me!

quyenanh1@gmail.com

thank you!

#include<io430gxxxx.h>
#include  <msp430g2231.h>
#define buton P1IN_bit.P1IN_3
#define led   P1OUT_bit.P1OUT_0
void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
  P1DIR |= 0x01;                            // Set P1.0 to output direction
  led=1;
  for(; ;){
    if(buton){
    led=~led;
    }
 
  }
 
}

  • Your defines aren't quite right.

    Try something like

    #define button (P1IN & 0x04)

    #define led (P1OUT & 0x01)

    The way you are turning your LED on and off isn't correct either.

    #define led_on  (P1OUT |= 0x01)

    #define led_off  (P1OUT &= ~(0x01))

     

    Good luck...

     

  • The IO430xxx.h headers did include bitfield definitions for many registers. But an error on the firs tline seems to indicate that this header file is not (no longer) available on the used compiler version.

    Unfortunately the information 'there is an error' doesn't say much. A quote of the exact error message would have been useful.

**Attention** This is a public forum