this simple code does not work in keil program

OP #1517703
hello All,
please help me.
my code is these:

#include <AT91SAM7S64.H>
#include <lib_AT91SAM7S64.h>
void wait(void);

int main (void){
AT91F_PIO_CfgOutput(AT91C_BASE_PIOA,AT91C_PIO_PA0);
AT91F_PIO_SetOutput(AT91C_BASE_PIOA,AT91C_PIO_PA0);
wait();

AT91F_PIO_ClearOutput(AT91C_BASE_PIOA,AT91C_PIO_PA0);
wait();
}
void wait(void){
unsigned int n;
for(n=0;n<7372800;n++);
}



where is my problem?
Guest
You must make a endless loop in your programm.

while(1)
{
   AT91F_PIO_SetOutput(AT91C_BASE_PIOA,AT91C_PIO_PA0);
   wait();

   AT91F_PIO_ClearOutput(AT91C_BASE_PIOA,AT91C_PIO_PA0);
   wait();
}
Guest
You define
1
unsigned int n;
then:
1
for(n=0;n<7372800;n++);

unsigned int range from 0 to 65335

You need unsigned long (or unsigned long int) rangng 0 to
4294967295.

Its possible the Optimicer will remove the loop
1
for(n=0;n<7372800;n++);
because it is empty!

avr
Hossein Heidari wrote:
> where is my problem?

How can we tell if you don't tell us the manner of the failure.  You 
have simply said that it does not work, but in what way?  Does it fail 
to compile or link; does it crash, make smoke, not behave in the way you 
expect?  What do you expect it to do?

Either way an empty loop is a really bad way to implement a time delay; 
the device has timer hardware, you should use that.  Even if you do use 
a loop, it is likely to get removed by the compiler optimiser when it 
notices that it does nothing.  To solve that you must at least declare 
the counter variable as volatile.

Reply

A question of your own? This thread is over 16 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.