EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

Enabling a pin to light an LED, newbie question

Started by Craig November 30, 2006
Hi all,

I have one of those newbie questions. I'm just getting into
developing with a dev board that I purchased from Spark Fun. I
bought the MSP430F149 board which contains an LED and a Push Button.

As a first project, I though I would tackle just lighting up the
LED. I looked at the schematic and the LED is on pin 6.0. After
reading some posts here about setting up pins, I came up with the
following code:

#include

/// Macro to set a bit y in variable x
#define SETB(x,y) (x |= (y))
/// Macro to reset a bit y in variable x
#define CLRB(x,y) (x &= ~(y))
/// Macro to toggle a bit y in variable x
#define INVB(x,y) (x ^= (y))
/**
Main function to light up LED
*/
int main(void) {
WDTCTL = WDTPW + WDTHOLD;
P6DIR = 0x01; //Set direction to out.
P6SEL = 0;
SETB(P6OUT, BIT0); //Set P6.0 to OUT.

while (1) { //main loop, never ends...
P6OUT = 0x01; //Set P6.0 to light LED.
}
}

This code doesn't light up the LED. Can anyone point me in the
right direction to lightup my LED?

Thanks for helping a newbie,

Craig

Beginning Microcontrollers with the MSP430

On 11/30/06, Craig wrote:
> Hi all,
>
> I have one of those newbie questions. I'm just getting into
> developing with a dev board that I purchased from Spark Fun. I
> bought the MSP430F149 board which contains an LED and a Push Button.
>
> As a first project, I though I would tackle just lighting up the
> LED. I looked at the schematic and the LED is on pin 6.0. After
> reading some posts here about setting up pins, I came up with the
> following code:
>
> #include /// Macro to set a bit y in variable x
> #define SETB(x,y) (x |= (y))
> /// Macro to reset a bit y in variable x
> #define CLRB(x,y) (x &= ~(y))
> /// Macro to toggle a bit y in variable x
> #define INVB(x,y) (x ^= (y))
> /**
> Main function to light up LED
> */
> int main(void) {
> WDTCTL = WDTPW + WDTHOLD;
> P6DIR = 0x01; //Set direction to out.
> P6SEL = 0;
> SETB(P6OUT, BIT0); //Set P6.0 to OUT.
>
> while (1) { //main loop, never ends...
> P6OUT = 0x01; //Set P6.0 to light LED.
> }
> }
>
> This code doesn't light up the LED. Can anyone point me in the
> right direction to lightup my LED?

Is the anode or the cathode of the LED connected to P6.0?
If the cathode is connected to P6.0 then you need to set P6OUT to 0 to get it
to light.

(* jcl *)

--
http://www.luciani.org
Look at the schematic again.
You should clear P6.0 in order to light the LED.

--- In m..., "Craig" wrote:
>
> Hi all,
>
> I have one of those newbie questions. I'm just getting into
> developing with a dev board that I purchased from Spark Fun. I
> bought the MSP430F149 board which contains an LED and a Push Button.
>
> As a first project, I though I would tackle just lighting up the
> LED. I looked at the schematic and the LED is on pin 6.0. After
> reading some posts here about setting up pins, I came up with the
> following code:
>
> #include /// Macro to set a bit y in variable x
> #define SETB(x,y) (x |= (y))
> /// Macro to reset a bit y in variable x
> #define CLRB(x,y) (x &= ~(y))
> /// Macro to toggle a bit y in variable x
> #define INVB(x,y) (x ^= (y))
> /**
> Main function to light up LED
> */
> int main(void) {
> WDTCTL = WDTPW + WDTHOLD;
> P6DIR = 0x01; //Set direction to out.
> P6SEL = 0;
> SETB(P6OUT, BIT0); //Set P6.0 to OUT.
>
> while (1) { //main loop, never ends...
> P6OUT = 0x01; //Set P6.0 to light LED.
> }
> }
>
> This code doesn't light up the LED. Can anyone point me in the
> right direction to lightup my LED?
>
> Thanks for helping a newbie,
>
> Craig
>
Wow, you guys have no idea how long I've been trying to get this to
work, thank you so much for your knowledge and quick response.

I have to honestly say that this is a lot harder than I anticipated.

Thanks again,

Craig

--- In m..., "old_cow_yellow"
wrote:
> Look at the schematic again.
> You should clear P6.0 in order to light the LED.
>
> --- In m..., "Craig" wrote:
> >
> > Hi all,
> >
> > I have one of those newbie questions. I'm just getting into
> > developing with a dev board that I purchased from Spark Fun. I
> > bought the MSP430F149 board which contains an LED and a Push
Button.
> >
> > As a first project, I though I would tackle just lighting up the
> > LED. I looked at the schematic and the LED is on pin 6.0.
After
> > reading some posts here about setting up pins, I came up with
the
> > following code:
> >
> > #include
> >
> > /// Macro to set a bit y in variable x
> > #define SETB(x,y) (x |= (y))
> > /// Macro to reset a bit y in variable x
> > #define CLRB(x,y) (x &= ~(y))
> > /// Macro to toggle a bit y in variable x
> > #define INVB(x,y) (x ^= (y))
> >
> >
> > /**
> > Main function to light up LED
> > */
> > int main(void) {
> > WDTCTL = WDTPW + WDTHOLD;
> > P6DIR = 0x01; //Set direction to out.
> > P6SEL = 0;
> > SETB(P6OUT, BIT0); //Set P6.0 to OUT.
> >
> > while (1) { //main loop, never ends...
> > P6OUT = 0x01; //Set P6.0 to light LED.
> > }
> > }
> >
> > This code doesn't light up the LED. Can anyone point me in the
> > right direction to lightup my LED?
> >
> > Thanks for helping a newbie,
> >
> > Craig
>
Craig wrote:
> Hi all,
>
> I have one of those newbie questions. I'm just getting into
> developing with a dev board that I purchased from Spark Fun. I
> bought the MSP430F149 board which contains an LED and a Push Button.
>
> As a first project, I though I would tackle just lighting up the
> LED. I looked at the schematic and the LED is on pin 6.0. After
> reading some posts here about setting up pins, I came up with the
> following code:
>
> #include /// Macro to set a bit y in variable x
> #define SETB(x,y) (x |= (y))
> /// Macro to reset a bit y in variable x
> #define CLRB(x,y) (x &= ~(y))
> /// Macro to toggle a bit y in variable x
> #define INVB(x,y) (x ^= (y))
>
> /**
> Main function to light up LED
> */
> int main(void) {
> WDTCTL = WDTPW + WDTHOLD;
> P6DIR = 0x01; //Set direction to out.
> P6SEL = 0;
> SETB(P6OUT, BIT0); //Set P6.0 to OUT.
>
> while (1) { //main loop, never ends...
> P6OUT = 0x01; //Set P6.0 to light LED.
> }
> }
>
> This code doesn't light up the LED. Can anyone point me in the
> right direction to lightup my LED?
>
> Thanks for helping a newbie,
>
> Craig
>

Craig,

It looks like you may be using the Olimex MSP-P149 board. If you look at
the schematic, the P6.0 is connected to the cathode of the LED via a 330
ohm resistor and the anode is tied to the positive supply rail. This
means that you need to bring the pin low to light the LED. Change your
statement from

P6OUT = 0x01;

to

P6OUT = 0x00;

and it should light up.

Hope this helps,

Greg Maki
> I have to honestly say that this is a lot harder than I anticipated.

Hang in there, it gets easier. Sooner or later, something will
just "click" and you'll start to get it. I suggest looking at
the assembly code for your little program, and even get an
assembly listing and go through the *binary* code for your
function, correlating each opcode against the instruction set
table, and each memory address against the device registers
and the program's memory map.

It's hard, slow work for a beginner, but it'll leave you with a
very clear idea of what your C program gets translated to, and
pretty-much exactly how the machine executes your program.

Clifford Heath.

The 2024 Embedded Online Conference