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

Author: Thu N. (chutthu)
Posted on:

Rate this post
0 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(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;
 IO1CLR = 0x00FF0000L;


Author: Clifford S. (clifford)
Posted on:

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



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.