EmbDev.net

Forum: ARM programming with GCC/GNU tools please take a look in my code


von Thu N. (chutthu)


Rate this post
useful
not useful
Hi alls,
I am starting with winarm for LPC2138. After compiling (no error), I run
for testing, but the output is not come. Please take a look on my code
to show where is my error.

#include "LPC21xx.H" // LPC2138 MPU Register
#include "nott.h"

void delay_ms(long int ms)
{
  long int i, j;
  for(i=0;i<ms;i++)
    for(j=0;j<6553;j++) IO1SET = 0x00;
}

 void main(void)
{


  PINSEL2 &= 0xFFFFFF00;  //Port P1.16- P1.23 to be GPIO
  IO1DIR = 0x00FF0000;   //set to be Output


while (1)

 {
 IO1SET = 0x00FF0000L;
 delay_ms(1000);
 IO1CLR = 0x00FF0000L;

 delay_ms(1000);
 }
}

von Clifford S. (clifford)


Rate this post
useful
not useful
The line:

PINSEL2 &= 0xFFFFFF00;  //Port P1.16- P1.23 to be GPIO

is incorrect. Take a look at section 7.4.3 of
http://www.nxp.com/acrobat/usermanuals/UM10120_1.pdf, especially with
respect to the warning regarding bits 4 and 5.

I believe the following is 'safe'.

PINSEL2 &= 0xFFFFFFF0;  //Port P1.16- P1.36 to be GPIO
IO1DIR = 0x00FF0000;    //set P1.16 - P1.23 to be Output

That's a very crude delay loop given that the part has hardware timers.
The timing of the loop will likely vary between compilers or compiler
optimisation levels and even so is clock rate dependent. The volatile
register access prevents the code from being optimised out altogether,
but it would be more straightforward to simply declare i and j volatile.

Clifford

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.