How to Start Programming for ARM7 Based LPC2148 Microcontroller
[nextpage title=”Description” ]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.
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. Serialbuilt-in JTAG interface
2. Using In System Programming (ISP) and UART0or
3. By means of InApplication 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 labelled 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 mustconfigure 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.
Total of 30 input/output and asingle output only pin out of 32 pins are available on PORT0. PORT1 has up to 16 pinsavailable for GPIO functions. PORT0 and PORT1 are controlled via two groups of registers explained below.
1. IOPIN
It is GPIO Port Pin value register. The current state of the GPIO configured port pins can always be read from this register, regardless of pin direction.
2.IODIR
GPIO Port Direction control register. This register individually controls the direction of each port pin.
3.IOCLR
GPIO Port Output Clear registers. This register controls the state of output pins. Writing ones produces lows at the corresponding port pins and clears the corresponding bits in the IOSET register. Writing zeroes has no effect.
4.IOSET
GPIO Port Output Set registers. This register controls the state of output pins in conjunction with the IOCLR register. Writing ones produces highs at the corresponding port pins. Writing zeroes has no effect.
This is the set of register used to configure I/O Pins. Now let’s move to individual registers in deep.
REGISTERS FOR C PROGRAMMING
1. IOSEL0
Port 0 has 32 pins (P0.0 to P0.31). Each pin can have multiple functions. On RESET, all pins are configured as GPIO pins. However we can re-configure using the registers IOSEL0 and IOSEL1.
IOSEL0 is used to select function of P0.0 to P0.15. Each pin has up to 4 functions so 2 bits/pin in IOSEL0 is provided for selecting function.
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.
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.[/nextpage]