How To Start Programming For ARM7 Based LPC2148 Microcontroller
How To Start Programming For ARM7 Based LPC2148 Microcontroller
This article is about how to start programming for LPC 2148 micro-controller. For
the new reader, it is more important to have basic knowledge of pin configuration,
memory, I/O ports and basic registers. Here is the pin diagram of LPC 2148.
LPC2148 PIN Diagram
MEMORY
LPC2148 has 32kB on chip SRAM and 512 kB on chip FLASH memory. It has inbuilt
support up to 2kB end point USB RAM also. This huge amount of memory is well suited
for almost all the applications.
We will explain the basic functions of above memory.
1. On chip FLASH memory system
The LPC2148 incorporates a 512 KB Flash memory system. This memory may be used
for both code and data storage. The FLASH memory can be programmed by means of
1. Serial built-in JTAG interface
ARM LPC 2148
2. Using In System Programming (ISP) and UART0or
3. By means of In Application Programming (IAP) capabilities.
The application program, using the IAP functions, may also erase and/or program the
Flash while the application is running, allowing a great degree of flexibility for data
storage field firmware upgrades, etc. When the LPC2148 on-chip boot loader is used,
500 kB of Flash memory is available for user code.
The LPC2148 Flash memory provides minimum of 100,000 erase/write cycles and 20
years of data-retention.
2. On chip SRAM
The LPC2148 provides 32 kB of static RAM which may be used for code and/or data
storage. It may be accessed as 8-bits, 16-bits, and 32-bits.
I/O Ports
LPC 2148 has two I/O Ports each of 32 bit wide giving us total 64 I/O Pins. Ports are
named as P0 and P1.
Pins of each port are labeled as PX.Y where X stands for port number, 0 or 1 where else
Y stands for pin number 0 to 31.
Each pin can perform alternate functions also. For eg. P0.8 serves as GPIO as well as
transmitter pin of UART1, PWM4 and AD1.1.
On RESET, each pin is configured as GPIO. For any of the other use, programmer must
configure it properly.
DEVELOP THE SKILL- START WITH PROGRAMMING
The first step towards programming is HOW TO CONFIGURE GPIO Pins. Let’s start with
the associated concepts and registers.
2 . IOSEL1
IOSEL1 is used to select function of pins P0.16 to P0.31
3. IOSEL2
IOSEL2 is used to select function of pins P1.16 to P1.31
4. IO0DIR
IO0DIR is used to configure pins of port 0-P0 as input or output pins.
1= output pin
0= input pin
Example: IO0DIR=0x0000ffff means P0.0 to P0.15 are configured as output pins and
P0.16 to P0.31 are configured as input pins.
5. IO1DIR
IO1DIR is used to configure pins of port 1-P1 as input or output pins.
1= output pin
0= input pin
Example: IO0DIR=0xaaaaaaaa means even pins (P1.0, P1.2, P1.4 etc.) are configured as
input pins and odd pins (P1.1, P1.3, P1.5 etc.) are configured as input pins.
6. IO0SET
It is used to set pins of Port0-P0 to logic 1.
Example: IO0SET=0x0000ffff will set pins P0.0 to P0.15 at logic 1. It will not affect other
pins.
7. IO0CLR
It is used to set pins of Port0-P0 to logic 0.
Example: IO0SET=0x0000ffff will set pins P0.0 to P0.15 at logic 0. It will not affect other
pins.
8. IO1SET
It is used to set pins of Port1-P1 to logic 1.
Example: IO1SET=0x0000ffff will set pins P1.0 to P1.15 at logic 1. It will not affect other
pins.
9. IO1CLR
It is used to set pins of Port1-P1 to logic 0.
Example: IO1SET=0x0000ffff will set pins P1.0 to P1.15 at logic 0. It will not affect other
pins.
ARM LPC 2148
Once the use of above all registers is perfectly understood, you are good to go with
programming.
Example: Blink LEDs connected on pins P1.16-P1.23
Step-1: Specify the direction of pins as output using IO1DIR.
Step-2: Set pins P1.16-P1.23 using IO1SET.
Step-3: Clear pins P1.16-P1.23 using IO1CLR.
Step-4: Go to step-2.
Now, using the steps given here, try to program on your own and once it is done,
compare with the basic program given here. You can write this program using various
techniques. We have given the most basic option for you.
Yuppie, you have successfully written a program for LED Blinking.