0% found this document useful (0 votes)
50 views

LPC2148 Intro

Uploaded by

Navami Sunil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

LPC2148 Intro

Uploaded by

Navami Sunil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 47

Introduction to LPC2148

LPC2148
Introduction
• ARM based microcontroller

• LPC2148 is a 32-bit Microcontroller based on the ARM7TDMI-S Family.

• It is manufactured by NXP (from Next eXPerience) Semiconductors (formerly Philips)

• It is one of the widely used and highly successful ARM7 based Microcontroller.

• Even though ARM7 family is considered obsolete with the introduction of many advanced

processors and controllers, it is one of the best and easiest microcontrollers to work around

for beginners in ARM based microcontrollers.

• Due to their tiny size and low power consumption, LPC2142/2148 are ideal for applications

where miniaturization is a key requirement, such as access control and point-of-sale


Specs of ARM 7 – LPC2148
• Architecture: 16 bit/32bit ARM7TDMI-S
• CPU Frequency: 60MHz
• Number of GPIO pins: 45 (5V-Tolerant)
• PWM Outputs:6
• ADC (AD0,AD1): Two 14 channel (10-bit)
• DAC: Single 10 bit DAC
• USART Peripherals:2
• I2C Peripherals:2 (40bit/s)
• SPI Peripherals:1
• SSP Peripherals:1
• Timers:2 (32bit)
• Flash Memory:512KB On chip flash m/y
• RAM: 40kB On-chip Static RAM
• Interrupt pins:21
• Input voltage: 4.5V~6.5V
GPIO-(General Purpose Input-Output)

• Input/output pins are the only way to interface with the microcontroller.

• To Make The Microcontroller More Marketable, Most Ports Can Be Software-


specified To Be Either Inputs Or Outputs.

• Microcontrollers Use The Concept Of A Direction Register To Determine Whether A


Pin Is An Input (Direction Register Bit Is 0) Or An Output (Direction Register Bit Is 1)

• Each Digital Port Pin Has A Direction Bit. The Digital Port Pins On Most
Microcontrollers Are Bidirectional.
PORT

• PORT means a register in Software sense.

• It’s a set of pins or legs of IC, in Hardware


sense !!!

• There could be multiple ports for the same


microcontroller.

• We can configure legs of the Same one port


as input or output Using a direction register.
Basic Concepts of Input and Output Ports

• The Parallel Port: The Simplest I/O Port on a Microcontroller.

• A Parallel I/O Port is a Simple Mechanism that allows the Software to interact with
external Devices. It is called Parallel because multiple signals can be accessed all at
once.

• An Input Port, which allows the Software to Read External Digital Signals, Is Read Only.

• That Means A Read Cycle Access From The Port Address Returns The Values Existing
On the Inputs at that time.
A read cycle access to an input port usually
produces no effect.
The digital values existing on the input pins are
copied into the microcontroller when the software
executes a read from the port address.

A write cycle to the port address will affect the


values on the output pins.
In particular, the microcontroller places
information on the data bus and that information
is clocked into the D flip-flops.
DIRECTION register :
• To define the direction of
Signal through a Pin.

• If DIR=0 - its an input pin


• If DIR=1 - its an output pin

• If the pin is configured as


output , both read and write
operation is possible;
where it can Read only the
previous value.
/are invisible pins, remaining 29 are visible PORTS of LPC2148 (1/2)

• LPC2148 has two IO Ports namely PORT0(P0) and PORT1(P1).

• These two ports are of 32-bit wide and are provided by the 64 pins of the microcontroller.

• Port 0 is a 32bit I/O port with individual direction controls for each bit.

• Total of 28 pins of Port 0 can be used as a general purpose bi directional digital I/O while
P0.31 provides digital output functions only.

• The operation of Port 0 pins depends upon the pin function selected via the pin connector

• Pins P0.24, P0.26 and P0.27 are not available /are invisible pins, remaining 29 are visible i/o
pins
PORTS of LPC2148 (2/2)
• Port 1 is a 32 bit bidirectional i/o port with individual direction controls for each
bit.
• The operation of Port 1 depends upon the pin function selected via to pin select.
Pin 0 through 15 of port1 are not available/not visible and 16 to 31 pins are
visible.
• port 0 and port 1 are controlled by groups of registers.
LPC2148 has two IO ports namely PORT0 (P0) and PORT1 (P1). These two IO ports are of 32-bit wide and
are provided by the 64 pins of the microcontroller.

The naming convention of the


I/O pins on the LPC2148
Microcontroller is Pa.bc where
‘a’ is the number of the port i.e.
0 or 1 (as LPC2148 has only
two ports) and ‘bc’ is the
number of the pin in the port a.
For example, P0.1 indicates pin
number 1 of PORT0 and P1.10
indicates pin number 10 of
PORT1.

[Refer the naming given in each


pin to identify the corresponding
port of LPC2148]
PORT0 is a 32-bit wide input/output port with dedicated direction control bits for each physical pin. Out of
the 32 pins, 28 pins can be used as general purpose bidirectional I/O pins. Pin P0.31 is an output only pin. Pins
P0.24, P0.26 and P0.27 of PORT0 are not available.

Figure shows pins of


PORT 0
Are non available pins
are not represented.
PORT1 is also a 32-bit wide input/output port. In PORT1, pins P1.0 to P1.15 are not available and pins
P1.16 to P1.31 are the available general purpose input/output pins.

Find the pins for


PORT1 yourself!!
Most of the pins in both the I/O ports of the LPC2148 have more than one function i.e. they are
multiplexed with different functions. For example, Pin 19 of the LPC2148 has three functions namely P0.0,
a general purpose I/O pin, TXD0, the transmitter O/P for UART0 and PWM1, the pulse width
modulator O/P 1.

At any point of operation, each


pin can have a single function
Pin Function Select Registers
At any point of operation, each pin can have a single function and the function can be selected
with the help of three Configuration Registers which control the multiplexers to allow connection
between the external pin and the on-chip peripheral.

The configuration register is called PINSEL


classified in to three registers: PINSEL0, PINSEL1 and PINSEL2
These configuration registers are of 32-bit wide
Any pin on the LPC2148 can have a maximum of 4 functions.

Hence in order to select one of the four functions, two corresponding bits of the PINSEL register
are needed.

For example: pins 13, 14, 15 of LPC2148


Any pin on the LPC2148 can have a maximum of 4 functions.
Hence in order to select one of the four functions, two corresponding bits of the PINSEL
register are needed.

For example: pins 13, 14, 15 of LPC2148

So, a 32-bit PINSEL register can control 16 pins with 2-bits to control
each pin.

PINSEL0 controls PORT0 pins P0.0 to P0.15, Refer page 14 to 18 for


PINSEL1 controls PORT0 pins P0.16 to P0.31 and more details of Pin
PINSEL2 controls PORT1 pins P1.16 to P1.31. function select register
The following table shows the PINSEL0 and corresponding functions on the PORT0.
Refer page 14 to 18 for more details of PINSEL1
Fast and Slow GPIO Registers

There are 5 Fast (also called Enhanced GPIO Features Registers) GPIO Registers and 4 Slow
(also called Legacy GPIO Registers) GPIO Registers available to control PORT0 and PORT1.

The default function of all the Pins is GPIO. But it is a good programming practice to
mention “PINSEL0=0” in order to select the GPIO function of the Pins.

GPIO function is the most frequently used functionality of the microcontroller.

Slow GPIO Registers


The GPIO function in both the Ports are controlled by a set of 4 registers:
a) IOPIN,
b) IODIR,
c) IOSET and
d) IOCLR.
GPIO Register map (1/3)
• IOPIN: This 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

• IODIR: This is GPIO Port Direction control register. This register individually Controls the direction of
each port pin

• IOCLR: This is 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.

• IOSET: This is 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.
1. IOxPIN (GPIO Port Pin value register):
This is a 32-bit wide register. This register is used to read/write the value on Port (PORT0/PORT1). But care
should be taken while writing. Masking should be used to ensure write to the desired pin.

IOPIN: It is a GPIO Port Pin Value register and can be used to read or write values directly to the
pin. The status of the Pins that are configured as GPIO can always be read from this
register irrespective of the direction set on the pin (Input or Output)

The syntax for this register is IOxPIN, where ‘x’ is the port number i.e. IO0PIN for PORT0 and
IO1PIN for PORT1.

Examples :
a) Writing 1 to P0.4 using IO0PIN
IO0PIN = IO0PIN | (1<<4)
b) Writing 0 to P0.4 using IO0PIN
IO0PIN = IO0PIN & (~(1<<4) )
c) Writing F to P0.7-P0.4
IO0PIN = IO0PIN | (0x000000F0)
2. IOxSET (GPIO Port Output Set register) :
IOSET: It is a GPIO Port Output Set Register and can be used to set the value of a GPIO pin
that is configured as output to High (Logic 1). When a bit in the IOSET register is set to ‘1’, the
corresponding pin is set to Logic 1. Setting a bit ‘0’ in this register has no effect on the pin.
The syntax for this register is IOxSET, where ‘x’ is the port number i.e. IO0SET for PORT0 and
IO1SET for PORT1.

3. IOxDIR (GPIO Port Direction control register)


IODIR: It is a GPIO Port Direction Control register and is used to set the direction i.e. either
input or output of individual pins. When a bit in this register is set to ‘0’, the corresponding pin in
the microcontroller is configured as Input. Similarly, when a bit is set as ‘1’, the corresponding pin
is configured as Output.
The syntax for this register is IOxDIR, where ‘x’ is the port number i.e. IO0DIR for PORT0 and
IO1DIR for PORT1.
4. IOxCLR (GPIO Port Output Clear register)
IOCLR: It is a GPIO Port Output Clear Register and can be used to set the value of a GPIO pin that is
configured as output to Low (Logic 0). When a bit in the IOCLR register is set to ‘1’, the corresponding pin
in the respective Port is set to Logic 0 and at the same time clears the corresponding bit in the IOSET
register. Setting ‘0’ in the IOCLR has no effect on the pin.
The syntax for this register is IOxCLR, where ‘x’ is the port number i.e. IO0CLR for PORT0 and IO1CLR for
PORT1.

Examples :
a) Configure pin P0.0 to P0.3 as input pins and P0.4 to P0.7 as
output pins.
IO0DIR = 0x000000F0;
b) Configure pin P0.4 as an output. Then set that pin HIGH.
IO0DIR = 0x00000010; OR IO0DIR = (1<<4);
IO0SET = (1<<4);
c) Configure pin P0.4 as an output. Then set that pin LOW.
IO0DIR = 0x00000010; OR IO0DIR = (1<<4);
IO0CLR = (1<<4);
GPIO Register map (2/3)
• 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 PO.15 are configured as output pins and P0.16 to
P0.31 are configured as input pins.

• IO1DIR
• It is used to configure pins of Port 1- P1 as input or output pins
1= Output Pin, 0= Input Pin
Example: IO1DIR=0xAAAAAAAA means even pins(P1.0, p1.2 etc.) are configured as i/p pins and odd
pins (P1.1, P1.3 etc.) are configured as o/p pins.
GPIO Register map (3/3)

• IO0SET
• It is used to set pins of Port0 – P0 to logic 1.
Example: IO0SET= 0x0000FFFFwill set pins P0.0 to P0.15 at logic 1. It will not affect other pins.
• IO0CLR
• It is used to set pins of Port0 – P0 to logic 0.
Example: IO0CLR=0x0000FFFFwill set pins P0.0 to P0.15 at logic 0. It will not affect other pins.
An important note to remember is that since the LPC2148 is a 32-bit microcontroller, the length
of all the registers mentioned is also 32-bits. Each bit in the above mentioned registers is
directly linked to the corresponding pin in the microcontroller i.e. bit ‘a’ in IO0SET
corresponds to Pin ‘a’ in the PORT0.

Registers in LPC2148 follow Big Endian format i.e. bit 0 is the LSB on the extreme
right of the register and bit 31 is the MSB on the extreme left of the register.

Another important note is that when reset, all the pins are set as GPIO pins and
the direction of each pin is set as Input.
Now, we’ll see how to use the above mentioned registers in programming. First, is to set the direction
of a pin. For example, if we want to set 4th pin of PORT0 i.e. P0.3 as output, then it can be set in
various ways as shown below.

Method 1: IO0DIR = (1<<3);


This is a direct assignment method where the binary value (1) is set directly on the pin. All the other
pins are set to 0. This method should be avoided as the value is directly being assigned in the
register and while P0.3 is assigned as ‘1’, all the other pins are forced to be assigned ‘0’.
An alternative to this method is ORing the register and then assigning the value. This can be done in
two ways.

Method 2: IO0DIR | = 0x00000008;


In this method, the hexadecimal value of the register is assigned after OR-ing the register with
desired hexadecimal number. In this way, the other pins other than the desired pin (P0.3 in this
case) are not affected. This method is useful if we want to assign many pins without affecting the
other pins.

(equivalent to IO0DIR = IO0DIR | 0x00000008)


Method 3: IO0DIR | = (1<<3);
This is similar to the above method except that only a single pin is affected.
Other registers can also be set using the same methods. Now, we’ll see an example of setting pin
15 of PORT0 i.e. P0.15 as output and drive the pin High.
For this we need to use two registers: IODIR and IOSET.
IO0DIR | = (1<<15); // Configuring P0.15 as output.
IO0SET | = (1<<15); // Make the O/P pin P0.15 as High

We’ll see another example where pin 11 of PORT0 is set as output and the output of this pin is set
to logic 1 and then to logic 0.
For this we need to use three registers: IODIR, IOSET and IOCLR.
IO0DIR | = (1<<11); // Configuring P0.11 as output.
IO0SET | = (1<<11); // Make the O/P pin P0.11 as High.
IO0CLR | = (1<<11); // Make the O/P pin P0.11 as Low.

Now, we’ll see an example where more than one pin has to be set as output and the value of that
pin must be HIGH. Consider pins 7 and 14 of PORT0 (P0.7 and P0.14).
IO0DIR | = (1<<7) | (1<<14); // Configuring pins P0.7 and P0.14 as output.
IO0SET | = (1<<7) | (1<<14); // Make the O/P of pins P0.7 and P0.14 as High.
Examples
• 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.
• Example: IO1DIR=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.
• IO0CLR=0x0000FFFF will set pins P0.0 to P0.15 at logic 0. It will not
affect other pins.
Once we have seen how to set the direction of pins, setting the pin as High or
Low, now we’ll jump into real time embedded programming. Similar to “Hello,
World” program in C Language, blinking an LED is the basic program in
embedded system.
Example: Blink LEDs connected on pins

• Step-1: Select the GPIO PORT Pins using PINSEL1.


• Step-2: Specify the direction of pins as output
using IO1DIR.
• Step-3: Set desired pins using IO1SET.
• Step-4: Clear desired pins using IO1CLR.
• Step-5: Go to step-2.
Example: Blink LEDs connected on pins
Experiment
Connect 16 from pin 16
to pin 31 of port 1
Chinmayi R , ECE, ASE,
Amritapuri
Example1
Example 2: Turn on the LED based on the
switch input
Example3
:
Exercise
• Blink five LEDs in ascending and descending order: Write a code to turn on
• one LED at a time, starting from LED0, then LED1, until you reach LED5. Then, you should turn on LED4,
then LED3, and so on until you reach LED0. Each LED should be on for 100ms. Repeat this pattern in an
infinite loop.
Thank
You
• C batch-1,3,11,14,25,28,31,33,41,42,47,50,53,54,59,65,69,76,
• A Batch – 8,10,29,64,65,76,80

You might also like