EmbeddedRelated.com
Forums

LED Blink

Started by josef104 August 9, 2004
I just bought the MSP430F413STK2 kit from Olimex.  I am trying to run 
a program to blink the LED on the kit. The documentation says the LCD 
is connected to P6.2. Can someone tell me if there's something wrong 
with this code? I am able to compile, make and download the program 
successfully from IAR kickstart IDE, but the LED is not blinking. 

#include <msp430x41x.h> 
void main(void) 
{ 
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer 
P6DIR |= 0x03; // Set P6.2 to output direction 

for (; 
{ 
volatile unsigned int i; 

P6OUT ^= 0x03; // Toggle P6.2 using exclusive-OR 

i = 50000; // Delay 
do (i--); 
while (i != 0); 
} 
}



Beginning Microcontrollers with the MSP430

Paul, I think this is toggling the wrong port. Try P1DIR= 0x04; and also
change the XOR correspondingly.

 

Also not sure if the email was mangled but this statement should be on a
newline.

 

Jed

 

  _____  

From: Paul Curtis [mailto:plc@plc@...] 
Sent: Monday, August 09, 2004 11:22 AM
To: msp430@msp4...
Subject: RE: [msp430] LED Blink

 

Hi, 

> I just bought the MSP430F413STK2 kit from Olimex. 
I am 
> trying to run a program to blink the LED on the kit. The 
> documentation says the LCD is connected to P6.2. Can someone 
> tell me if there's something wrong with this code? I am able 
> to compile, make and download the program successfully from 
> IAR kickstart IDE, but the LED is not blinking. 
> 
> #include <msp430x41x.h>
> void main(void)
> {
> WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer P6DIR |> 0x03; // Set
P6.2 to output direction 
> 
> for (;
> {
> volatile unsigned int i; 
> 
> P6OUT ^= 0x03; // Toggle P6.2 using exclusive-OR 
> 
> i = 50000; // Delay
> do (i--);
> while (i != 0);
> }
> }

You're toggling P6.0 and P6.1 (the 0x03 is bits 0 and 1).  Try P6OUT ^0x04.
 You might want to use P6DIR |= 0x04 as well, to set the port bit
as output.

--
Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
CrossWorks for MSP430, ARM, and (soon) Atmel AVR processors 


.









 
<http://us.ard.yahoo.com/SIG906s5ha/M)8184.5285298.6392945.3001176/D=gr
oups/S05005378:HM/EXP92151812/A!64331/R=0/SIGeaelai9/*http:/www.n
etflix.com/Default?mqso`183351> click here


 
<http://us.adserver.yahoo.com/l?M)8184.5285298.6392945.3001176/D=groups/S=
:HM/A!64331/rand74536852> 

 

  _____  

> . 







--- In msp430@msp4..., "Paul Curtis" <plc@r...> wrote:
> Hi, 
> 
> > I just bought the MSP430F413STK2 kit from Olimex.  I am 
> > trying to run a program to blink the LED on the kit. The 
> > documentation says the LCD is connected to P6.2. Can someone 
> > tell me if there's something wrong with this code? I am able 
> > to compile, make and download the program successfully from 
> > IAR kickstart IDE, but the LED is not blinking. 
> > 
> > #include <msp430x41x.h>
> > void main(void)
> > {
> > WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer P6DIR |> >
0x03; // Set P6.2 to output direction 
> > 
> > for (;
> > {
> > volatile unsigned int i; 
> > 
> > P6OUT ^= 0x03; // Toggle P6.2 using exclusive-OR 
> > 
> > i = 50000; // Delay
> > do (i--);
> > while (i != 0);
> > }
> > }
> 
> You're toggling P6.0 and P6.1 (the 0x03 is bits 0 and 1).  Try 
P6OUT ^> 0x04.  You might want to use P6DIR |= 0x04 as well, to set
the port 
bit
> as output.
> 
> --
> Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
> CrossWorks for MSP430, ARM, and (soon) Atmel AVR processors

Thanks! It works!!!!!!


Paul Curtis wrote:

> Hi, 
> 
> 
>>I just bought the MSP430F413STK2 kit from Olimex.  I am 
>>trying to run a program to blink the LED on the kit. The 
>>documentation says the LCD is connected to P6.2. Can someone 
>>tell me if there's something wrong with this code? I am able 
>>to compile, make and download the program successfully from 
>>IAR kickstart IDE, but the LED is not blinking. 
>>
>>#include <msp430x41x.h>
>>void main(void)
>>{
>>WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer P6DIR |>>0x03; //
Set P6.2 to output direction 
>>
>>for (;
>>{
>>volatile unsigned int i; 
>>
>>P6OUT ^= 0x03; // Toggle P6.2 using exclusive-OR 
>>
>>i = 50000; // Delay
>>do (i--);
>>while (i != 0);
>>}
>>}
> 
> 
> You're toggling P6.0 and P6.1 (the 0x03 is bits 0 and 1).  Try P6OUT
^> 0x04.  You might want to use P6DIR |= 0x04 as well, to set the port bit
> as output.

Tee Hee, and there are those who call assembler hard. gimme bis/bic anyday.

;^}

Al


> You're toggling P6.0 and P6.1 (the 0x03 is bits 0 and 1).  Try
P6OUT ^> 0x04.  You might want to use P6DIR |= 0x04 as well, to set the port
bit
> as output.

                           Pins
           | 7 | 6 | 5 | 4 |  | 3 | 2 | 1 | 0 |
           |---------------|  |---------------|
           | 8 + 4 + 2 + 1 |  | 8 + 4 + 2 + 1 |
PxOUT = 0x         _                  _

            10:A, 11:B, 12:C, 13:D, 14:E, 15:F


Until decimal-binary-hex becomes second nature, new coders should draw
something like this to remember how to encode the two digits. Simply
look at the port pins you want to activate and add up the
corresponding numbers below, converting to the appropriate letter if
above 9. That can help avoid these frustrating little errors that are
so easy to make.


Robert, 

> I understand that when C was invented, it was an
advantage to 
> have very small source code as storage space was at  such a 
> premium, but it's totally unnecessary now. C should be 
> updated and modernised with sensible syntax. You could call 
> it, I dunno, say C++. ;-) 

You should all be programming in Modula-2.  M2 even has generics and OO
extensions now.

-- Paul.


Al lit the blue touch paper thus:

>> > You're toggling P6.0 and P6.1 (the
0x03 is bits 0 and 1). Try P6OUT ^> 0x04. You might want to use P6DIR |=
0x04 as well, to set the port bit
> as output.

Tee Hee, and there are those who call assembler hard. gimme bis/bic anyday.

;^} <<

I *so* agree with you here, Al. (On the assumption that I understand your 
point! ;-) 

When I first started learning C I could not believe the arcane syntax that was 
involved. I really couldn't believe, for example, that writing assembler
was 
any more difficult than C for writing to hardware registers. I still think 
that bit manipulation in C is a load of old tosh and much poorer than 
assembler. 

I understand that when C was invented, it was an advantage to have very small 
source code as storage space was at  such a premium, but it's totally 
unnecessary now. C should be updated and modernised with sensible syntax. You 
could call it, I dunno, say C++. ;-) 

Cheers,

Rob - deputy antagoniser in chief. :-) 





I see the LED on P6.2, and it's reported to work.  P1.2 is connected
to
the buzzer.

-- Paul. 

> -----Original Message-----
> From: Jed Hammond [mailto:jed@jed@...] 
> Sent: 09 August 2004 15:52
> To: msp430@msp4...
> Subject: RE: [msp430] LED Blink
> 
> Paul, I think this is toggling the wrong port. Try P1DIR> 0x04; and also
change the XOR correspondingly.
> 
>  
> 
> Also not sure if the email was mangled but this statement 
> should be on a newline.
> 
>  
> 
> Jed
> 
>  
> 
>   _____  
> 
> From: Paul Curtis [mailto:plc@plc@...]
> Sent: Monday, August 09, 2004 11:22 AM
> To: msp430@msp4...
> Subject: RE: [msp430] LED Blink
> 
>  
> 
> Hi, 
> 
> > I just bought the MSP430F413STK2 kit from Olimex.  I am 
> trying to run 
> > a program to blink the LED on the kit. The documentation 
> says the LCD 
> > is connected to P6.2. Can someone tell me if there's 
> something wrong 
> > with this code? I am able to compile, make and download the program 
> > successfully from IAR kickstart IDE, but the LED is not blinking.
> > 
> > #include <msp430x41x.h>
> > void main(void)
> > {
> > WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer P6DIR |> 0x03; //
Set 
> > P6.2 to output direction
> > 
> > for (;
> > {
> > volatile unsigned int i;
> > 
> > P6OUT ^= 0x03; // Toggle P6.2 using exclusive-OR
> > 
> > i = 50000; // Delay
> > do (i--);
> > while (i != 0);
> > }
> > }
> 
> You're toggling P6.0 and P6.1 (the 0x03 is bits 0 and 1).  
> Try P6OUT ^= 0x04.  You might want to use P6DIR |= 0x04 as 
> well, to set the port bit as output.
> 
> --
> Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk 
> CrossWorks for MSP430, ARM, and (soon) Atmel AVR processors 
> 
> 
> .
> 
> 
> 
> 
> 
> 
> 
> 
> 
>  
> <http://us.ard.yahoo.com/SIG906s5ha/M)8184.5285298.639294
> 5.3001176/D=gr
> oups/S05005378:HM/EXP92151812/A!64331/R=0/SIGeaelai
> 9/*http:/www.n
> etflix.com/Default?mqso`183351> click here
> 
> 
>  
> <http://us.adserver.yahoo.com/l?M)8184.5285298.6392945.30011
> 76/D=groups/S> :HM/A!64331/rand74536852> 
> 
>  
> 
>   _____  
> 
> > . 
> 
> 
> 
> 
> 
> 
> 
> 
> ------------------------ Yahoo! Groups Sponsor 
> --------------------~--> Yahoo! Domains - Claim yours for 
> only $14.70 http://us.click.yahoo.com/Z1wmxD/DREIAA/yQLSAA/CFFolB/TM
> --------------------------
> ------~-> 
> 
> .
> 
>  
> Yahoo! Groups Links
> 
> 
> 
>  
> 
> 
> 

Or just use the standard BITx defs in the TI header files:  

P6OUT ^= BIT2;

--Bruce



> > You're toggling P6.0 and P6.1 (the 0x03
is bits 0 and 1).  Try P6OUT ^> > 0x04.  You might want to use P6DIR |=
0x04 as well, to set the port bit
> > as output.
> 
>                            Pins
>            | 7 | 6 | 5 | 4 |  | 3 | 2 | 1 | 0 |
>            |---------------|  |---------------|
>            | 8 + 4 + 2 + 1 |  | 8 + 4 + 2 + 1 |
> PxOUT = 0x         _                  _
> 
>             10:A, 11:B, 12:C, 13:D, 14:E, 15:F
> 
> 
> Until decimal-binary-hex becomes second nature, new coders should draw
> something like this to remember how to encode the two digits. Simply
> look at the port pins you want to activate and add up the
> corresponding numbers below, converting to the appropriate letter if
> above 9. That can help avoid these frustrating little errors that are
> so easy to make.



On Mon, 9 Aug 2004 17:24:05 +0100, Paul wrote:

>You should all be programming in Modula-2.  M2 even
has generics and OO
>extensions now.

What's wrong with M3, instead?

Jon