ARM LPC2148 Training
Class - 1
Topic : Introduction to Pin’s,
PORTS and Configuring ARM
4/23/2020 Electrical Product Development 1
Lab
Topics
• PIN configuration
• PORTS
• Configuring PIN’s
• Simple LED blinking program
4/23/2020 Electrical Product Development 2
Lab
PIN Configuration
Fig : 1 PIN Diagram of LPC2148
4/23/2020 Electrical Product Development 3
Lab
PIN Configuration (Cont..)
LPC2148
PORT 0 PORT 1
P0.0 to P0.15 , P0.16 to P0.31 P1.0 to P1.15 , P1.16 to P1.31
Fig : 2 Distribution of PORT’s and PIN’s
4/23/2020 Electrical Product Development 4
Lab
PORTx
PORT 0:
• P0.0 to P0.15 → Lower 16 bit Pins
• P0.17 to P0.31 → Higher 16 bit Pins
PORT 1:
• P1.0 to P1.15 → Lower 16 bit Pins
• P1.17 to P1.31 → Higher 16 bit Pins
PORT 0 – Lower 16 bit and higher 16 bit
are used as GPIO pins
PORT 1 – Only higher 16 bit pins are used
as GPIO pins.
4/23/2020 Electrical Product Development 5
Lab
PORTx (Cont..)
• Pins of P1.0 to P1.15 of lower 16 bit pins
are not available for the user.
• Also P0.24, P0.26 and P0.27 are not
available for user.
• Out of 64 pins only user can use 45 Pins
of LPC2148.
4/23/2020 Electrical Product Development 6
Lab
Configuring PIN’s
• To use the 45 pins we must configure the pins by
configuring the following registers.
• IOxPIN/IOPINx → IO pin Status register
• IODIRx → Direction register
• IOSETx → State set register
• IOCLRx → PIN Clear register
• All the registers are 32 bit registers each bit
controls the each pin of LPC2148.
4/23/2020 Electrical Product Development 7
Lab
Configuring PIN’s
IOPINx – IO Pin Status register
Px.31 Px.27 Px.23 Px.19 Px.15 Px.11 Px.7 Px.3 Px.0
0000 0000 0000 0000 0000 0000 0000 0000
This can be written in the Hexa Decimal format
0x00000000
0x stands for hexa decimal deceleration
• Reading the values of pins can be done by
IOPINx
Ex: IOPIN0 = 0x0000000F
4/23/2020 Electrical Product Development 8
Lab
Configuring PIN’s (Cont…)
IODIRx - Direction register
• Assigning 0 → will make pin as INPUT
• Assigning 1 → will make pin as OUTPUT
• By default the pin value will be set as ‘0’
• If we want to change the pin P0.0 to P0.3
as OUTPUT pins then declaration will be
Ex: 0 x 0 0 0 0 0 0 0 F
4/23/2020 Electrical Product Development 9
Lab
Configuring PIN’s (Cont…)
IOSETx - State set register
Ex : 0 x 0 0 0 0 0 0 0 F // Px.0 to Px.3 as High
IOCLRx - PIN Clear register
Ex : 0 x 0 0 0 0 0 0 0 F // Px.0 to Px.3 satus will be
cleared
4/23/2020 Electrical Product Development 10
Lab
Configuring PIN’s (Cont…)
Table : 1 Selector Input and PIN State
GPIO x – 0 or 1 S1 S0 O/P
Ist Alternate Function y – 0 to 31
0 0 GPIO
2nd Alternate Function PSB Px.y
0 1 1st
Reserve
1 0 2nd
1 1 3rd
S1 S0
Fig : 3 General Block Diagram of single
S1 and S0 values are configured by associated register of PSB
4/23/2020 Electrical Product Development 11
Lab
Configuring PIN’s (Cont…)
• PSB – Pin Select Block has the following
registers
• PINSEL0 –Controls the pins from P0.0 to P0.15
• PINSEL1 –Controls the pins from P0.16 to P0.31
• PINSEL2 –Controls the pins from P1.16 to P1.31
• Each of the registers are 32 bit wide then how it
controls the 16 bit pins
4/23/2020 Electrical Product Development 12
Lab
Configuring PIN’s (Cont…)
• Lets take the example of PINSEL0 32 bit register
which controls the pins from P0.0 to P0.15.
S1 – S0 S1 – S0
00 00 00 00 00 00 00 00 00 00 00 00 00
P0.12 P0.11 P0.10 P0.9 P0.8 P0.7 P0.6 P0.5 P0.4 P0.3 P0.2 P0.1 P0.0
Fig : 4 Distribution of 32 bit registers to PINs of PORT 0
• Similarly the registers of PINSEL1 and PINSEL2
will be distributed to the remaining pins of
corresponding PORTs
4/23/2020 Electrical Product Development 13
Lab
Configuring PIN’s (Cont…)
Fig : 5 Datasheet shows the features of PORTO Pins
4/23/2020 Electrical Product Development 14
Lab
Configuring PIN’s (Cont…)
• Example for configuring P0.0 pin as a Tx Pin for
USART communication
GPIO
TxDo
PWM PSB P0.0
Reserve
S1 S0
Fig : 5 Features of P0.0 pin
• PINSEL0 = 0 x 0 0 0 0 0 0 0 1
P0.0 become as TxD0 by setting LSB values of P0.3
to P0.0 as 0001
4/23/2020 Electrical Product Development 15
Lab
Simple LED Blinking Program
• Blink the LED connected in PORT1
# include <lpc21xx.h> // Include header file
void delay(void);
int main(void)
{
PINSEL2 = 0x00000000; // Configure P1.16 as GPIO pin
IODIR1 = 0x00000000; // Configure P1.16 as OUTPT pin
while(1) {
IOSET1 = 0x00010000; // Turn ON LED at P1.16
delay(); // Wait for a while
IOCLR1 = 0x00010000; // Turn OFF LED at P1.16
delay(); // Wait for a while
}
}
4/23/2020 Electrical Product Development 16
Lab
Simple LED Blinking Program
void delay(void){
unsigned int j; // assign the variable j
for(j=0;j<1000000;j++) // Increment j till
} 1000000
4/23/2020 Electrical Product Development 17
Lab
Assignment
• Draw the circuit for the above program
• Write the program for blinking the LED from
P0.16 to P0.23.
4/23/2020 Electrical Product Development 18
Lab
Thank You
4/23/2020 Electrical Product Development 19
Lab