this simple code does not work in keil program

OP #1517703
Rate this post
useful
not useful
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 #1517724
Rate this post
useful
not useful
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
#1518129
Rate this post
useful
not useful
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

Please log in before posting.

or

Log in with Google account

Registration is free and takes only a minute.

Register now