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).