Hello World LPC21xx / 32-bit Programming – ARM7

Lets begin with practical aspect of interfacing, programming with LPC21xx family. As every other Microcontroller Hello World program here too is, LED blink program, or GPIO program.This program also gives you an idea of assigning 32 bit values to registers. Most of us (at this stage, when you are learning about ARM7) are familiar to programming for 8 bit architecture, this is your opportunity to try your hands on 32 bit handelling, which looks a little odd initially, by time you will get used to it, so move on…


I will be following standard MCB2100 compatible hardware for most of the projects, will notify otherwise.

As shown in the schematic above 8 LEDs are connected to PORT1 pin number 16 to 23.

Here comes the C Receipe (available to download at the end of page, below is an image)

Step by Step explanation of the above receipe…

Line 1 : All register definitions, mapping to corresponding memory addresses are done in this header file, its a standard header source, it is added to the include path at the time of installing Keil MDK.

Line 3-12 : Its a 1 second delay function, used to generate processor delay using inbuilt Timer0 processing. As of now you can skip the actual working of this functional abstraction. I will explain the working of Timers and also of this functional abstraction in the timer section.

Line 16 : Instruction IODIR1 = 0x00FF0000 instructs the CPU that the current application will be using pin number 16 to 23 as generel purpose DIGITAL OUTPUT pin (IODIR => Input Output Direction Register).

Line 18 : Instruction IOSET1 = 0x00FF0000 instructs the CPU to write a Digital HIGH logic on pin number 16 to 23 of PORT1. (IOSET => Input Output Port SET Register).

Line 20 : Instruction IOCLR1 = 0x00FF0000 instructs the CPU to write a Digital LOW logic on pin number 16 to 23 of PORT1. (IOCLR => Input Output Port CLEAR Register).

Overall, above program blinks LEDs connected to PORT1 pin 16-23 at a rate defined by argument in function call delay_sec(integer argument).

Download Source code/ Project

  • renu

    i did not understand the logic of IODIR1 = 0x00FF0000

    what if i am using port 0 and pins 0 to 7???

    i know AVR coding and in AVR i would write

    DDRD=0xFF; //define as O/P port
    PORTD=0×00; //initialize to 0

    in AVR upper nibble n then lower nibble is written isnt the same in ARM?
    m not able to understand in code…
    plz help…

    thank you in advance
    (if my que is complicated then let me know will ask again)
    :P

  • mallikarjun

    in port1 we have 32 pins and count starts from zero from lsb.
    so in IODIR1 = 0x00FF0000;
    first zero(0) refers to nibble(4 bits)ie,P1.0 to P1.3, similarly for second third and forth.
    now we have F (4bits) ie,P1.16 to P1.19.
    and we have another F (4bits) ie,P1.20 to P1.23.
    remaining are zero, anyway we dont need them.
    i guess you got it, otherwise give me comments, so that i can explain you in another way.