EmbeddedRelated.com
Forums

call delay_ms

Started by msp430 nascimento February 17, 2007
I need that someone help me. I started to programmer msp this week in C using IAR. But I already problems with my first program.

#include "msp430x20x3.h"
void delay_ms(void);

void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
//P1DIR |= 0x01; // Set P1.0 to output direction

for (;;)
{

volatile unsigned short int i; // volatile to prevent optimization

// Toggle P1.0 using exclusive-OR

i = 6; // SW Delay
do i--;
while (i != 0);
delay_ms();
}
}

void delay_ms (void)

{
unsigned short int time;
P1OUT ^= 0x01;
time = 10;
do time--;
while (time !=0);
}

this program don`t#include "msp430x20x3.h"
void delay_ms(void);

void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog
timer
//P1DIR |= 0x01; // Set P1.0 to output direction

for (;;)
{

volatile unsigned short int i; // volatile to prevent optimization

// Toggle P1.0 using exclusive-OR

i = 6; // SW Delay
do i--;
while (i != 0);
delay_ms();
}
}

void delay_ms
(void)

{
unsigned short int time;
P1OUT ^= 0x01;
time = 10;
do time--;
while (time !=0);
}

work right. When I compile, the result is:

last line of file ends without a new line.

ASK: Do I need to make to correct this? And why do the subroutine no work ?

Thanks

__________________________________________________
Fale com seus amigos de gra com o novo Yahoo! Messenger
http://br.messenger.yahoo.com/

Beginning Microcontrollers with the MSP430

I think your original code was correct, more or less. You must
have tried it with P1DIR |= 0x01; and later decide to comment
that statement out. Well, that statement was correct and the
LED cannot be turned on without it.

What you may not know is, your code is turning the LED on and
off every ~160 usec and that is too fast for you to see.

Deleting the #include statement and the forward declaration
could not solve the problem. I do not know what you get in doing
so.

--- In m..., msp430 nascimento
wrote:
>
> I need that someone help me. I started to programmer msp this week
in C using IAR. But I already problems with my first program.
>
> #include "msp430x20x3.h"
> void delay_ms(void);
>
> void main(void)
> {
> WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
> //P1DIR |= 0x01; // Set P1.0 to output
direction
>
> for (;;)
> {
>
> volatile unsigned short int i; // volatile to
prevent optimization
>
>
> // Toggle P1.0 using exclusive-OR
>
> i = 6; // SW Delay
> do i--;
> while (i != 0);
> delay_ms();
> }
> }
>
> void delay_ms (void)
>
> {
> unsigned short int time;
> P1OUT ^= 0x01;
> time = 10;
> do time--;
> while (time !=0);
> }
>
> this program don`t#include "msp430x20x3.h"
> void delay_ms(void);
>
> void main(void)
> {
> WDTCTL = WDTPW + WDTHOLD; // Stop watchdog
> timer
> //P1DIR |= 0x01; // Set P1.0 to output
direction
>
> for (;;)
> {
>
> volatile unsigned short int i; // volatile to
prevent optimization
>
> // Toggle P1.0 using exclusive-OR
>
> i = 6; // SW Delay
> do i--;
> while (i != 0);
> delay_ms();
> }
> }
>
> void delay_ms
> (void)
>
> {
> unsigned short int time;
> P1OUT ^= 0x01;
> time = 10;
> do time--;
> while (time !=0);
> }
>
> work right. When I compile, the result is:
>
> last line of file ends without a new line.
>
> ASK: Do I need to make to correct this? And why do the subroutine
no work ?
>
> Thanks
>
> __________________________________________________
> Fale com seus amigos de gra com o novo Yahoo! Messenger
> http://br.messenger.yahoo.com/
>
>
>
msp430 wrote:
> I need that someone help me. I started to programmer msp this week in C
> using IAR. But I already problems with my first program.
>
> [...]
>
> work right. When I compile, the result is:
>
> last line of file ends without a new line.
>
> ASK: Do I need to make to correct this? And why do the subroutine no work ?

Hi nascimento!

Just a few comments on your code:

Fixing the problem with the final newline is easy -- just go to the last
line of your source code and press return. You don't have to do that but
if you don't you will 1) continue to get the warning and 2) run into
major problem the day you port the source code to another compiler. The
reason why the warning is issued is that there are several compilers on
the market that doesn't "see" the last line unless it ends in a newline.
Besides, the standard requires it...

In the source code I've noticed that you have several delay loops. I
would recommend that you replace them with calls to the intrinsic
function __delay_cycles. That way you can be sure that you will get a
deterministic behavior regardless of optimization level, compiler
version etc.

However, I can't help you with why your subroutines don't work since you
haven't told us what happens and what you expected to happened.

-- Anders Lindgren, IAR Systems
--
Disclaimer: Opinions expressed in this posting are strictly my own and
not necessarily those of my employer.