EmbDev.net

Forum: ARM programming with GCC/GNU tools this simple code does not work in keil program


Author: Hossein Heidari (hosein47)
Posted on:

Rate this post
0 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?

Author: helmi1 (Guest)
Posted on:

Rate this post
0 useful
not useful
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();
}

Author: avr (Guest)
Posted on:

Rate this post
0 useful
not useful
You define
unsigned int n;
then:
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
for(n=0;n<7372800;n++);
because it is empty!

avr

Author: helmi1 (Guest)
Posted on:

Rate this post
0 useful
not useful
@ avr

It runs on a 32 Bit machine. ARM AT91SAM7S64
there ist "int" = 32 bit

Author: thorstendb (Guest)
Posted on:

Rate this post
0 useful
not useful
> unsigned int range from 0 to 65335

ARM is 32Bit, so it ranges to 4G.

Author: thorstendb (Guest)
Posted on:

Rate this post
0 useful
not useful
helmi1: Hey, why didn't I see your post before? :-)

Author: Clifford Slocombe (clifford)
Posted on:

Rate this post
0 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

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.