Professional Documents
Culture Documents
Memory-Mapped Peripherals (Ch.12)
Memory-Mapped Peripherals (Ch.12)
Memory-Mapped Peripherals (Ch.12)
Memory-Mapped Peripherals
(Ch.12)
Pin Diagram
LPC2377/78
lpc23xx user manual Rev4.1, page 104
Pin Diagram
Schematic
LPC2378
Functional Block Diagram
The LPC2378 has 104 GPIO
pins, most pins have multiple
functions. The default on reset
is GPIO (general-purpose
input/output)
Memory-mapped I/O
Memory-mapped I/O or memory-mapped peripheral uses
the same address bus to address both memory and I/O
devices (peripheral units).
The memory and registers of the I/O devices (peripheral units)
are mapped to (associated with) address values.
When CPU sends out an address, it may refer to a portion of
physical RAM/ROM, but it can also refer to memory/registers
associated with that I/O device.
For ARM, LDR and STR instructions can be used to read data
from an input device and send data to an output device,
respectively, given that the address of that I/O device is
known.
Memory Map
LPC2377/78
__main
LDR R0, =(PINSEL8)
MOV R1, #0 ; set port P4.15 .. P4.0 to GPIO (default behavior)
STR R1, [R0]
11 10 01 00
Function select bits PIN CONNECT
(from the PINSEL
register) BLOCK
__main
LDR R0, =(PINSEL8)
MOV R1, #0 ; set port P4.15 .. P4.0 to GPIO (default behavior)
STR R1, [R0]
__main
LDR R0, =(PINSEL8)
MOV R1, #0 ; set port P4.15 .. P4.0 to GPIO (default behavior)
STR R1, [R0]
Syntax in C language:
FIO2DIR = 0x00000000; // make ALL bits inputs (the default
after a reset)
FIO2DIR |= 0x000000400; // make bit 10 output
leave rest unchanged!
FIO2DIR &= ~0x00000400; // ?
FIO2DIR &= ~(1<<10); //
Example (continue)
...
LDR R0, =(FIO4SET)
MOV R2, #0x00000003
STR R2, [R0]
FIODIR Fast GPIO Port Direction control register. This register R/W 0x0 FIO0DIR - 0x3FFF C000
individually controls the direction of each port pin. FIO1DIR - 0x3FFF C020
FIO2DIR - 0x3FFF C040
FIO3DIR - 0x3FFF C060
FIO4DIR - 0x3FFF C080
FIOSET Fast Port Output Set register using FIOMASK. This R/W 0x0 FIO0SET - 0x3FFF C018
register controls the state of output pins. Writing 1s FIO1SET - 0x3FFF C038
produces highs at the corresponding port FIO2SET - 0x3FFF C058
pins. Writing 0s has no effect. Reading this register FIO3SET - 0x3FFF C078
returns the current contents of the port output register. FIO4SET - 0x3FFF C098
Only bits enabled by 0 in FIOMASK can be attered.
FIOCLR Fast Port Output Clear register using FIOMASK0. This WO 0x0 FIO0CLR - 0x3FFF C01C
register controls the state of output pins. Writing 1s FIO1CLR - 0x3FFF C03C
produces lows at the corresponding port FIO2CLR - 0x3FFF C05C
pins. Writing 0s has no effect. Only bits enabled by FIO3CLR - 0x3FFF C07C
0 in FIOMASK0 can be altered. FIO4CLR - 0x3FFF C09C
UM10211 – Chapter 10
Generic Description Access Reset Port Register name and
Name value address
FIOMASK Fast Mask register for port. Writes, sets, clears, and R/W 0x0 FIO0MASK - 0x3FFF C010
reads to port (done via writes to FIOPIN, FIOSET, and FIO1MASK - 0x3FFF C030
FIOCLR, and reads of FIOPIN) alter or return only the FIO2MASK - 0x3FFF C050
bits enabled by zeros in this register. FIO3MASK - 0x3FFF C070
FIO4MASK - 0x3FFF C090
FIOPIN Fast Port Pin value register using FIOMASK. The R/W 0x0 FIO0PIN - 0x3FFF C014
current state of digital port pins can be read from FIO1PIN - 0x3FFF C034
this register, regardless of pin direction or alternate FIO2PIN - 0x3FFF C054
function selection (as long as pins are not configured FIO3PIN - 0x3FFF C074
as an input to ADC). The value read is masked by FIO4PIN - 0x3FFF C094
ANDing with inverted FIOMASK. Writing to this
register places corresponding values in all bits
enabled
by zeros in FIOMASK.
Important: if a FIOPIN register is read, its bit(s)
masked with 1 in the FIOMASK register will be set to 0
regardless of the physical pin state.
LPC2378 GPIO
• The PORTS are accessed through specific registers.
(These registers are memory locations that are defined in
the LPC23xx.inc file)
• All the ports are accessible through FIO registers - these
uses a fast internal bus operation.
• Each Port has its own set of FIO registers to setup, control
and access the port.
• To maintain backwards compatibility with previous
devices PORT0 and PORT1 are also accessible by an
alternate set of registers - using a slower internal bus.
• We should use always use the FIO registers not the slower
ones!
The FIO Register
FIOxDIR: allow direction control of individual bits.
FIOxPIN: An entire port value can be read or written in
one instruction.
FIOxSET and FIOxCLR: Bit-level set and clear registers
allow a single instruction set or clear of any number of
bits in one port.
FIOxMASK: Mask registers allow treating sets of port
bits as a group, leaving other bits unchanged
Note: x can be from 0 to 4
all I/O pins default to input after reset.
Examples
Describe what the following code segment does
LDR R0, =(PINSEL8)
MOV R1, #1
STR R1, [R0]
Examples
LDR R0, =(PINSEL0)
LDR R2, [R0]
MOV R1, #0x50
ORR R2, R2, R1
STR R2, [R0]
Examples
LDR R0, =(PINMODE9)
LDR R1, =0xFFFF
STR R1, [R0]
Examples
LDR R0, =(PINMODE4)
LDR R1, =0x2A
STR R1, [R0]
Examples
LDR R0, =(FIO3DIR)
MOV R1, #0x0F
STR R1, [R0]
Examples
LDR R0, =(FIO0DIR0)
LDR R1, [R0]
MOV R2, #0xC3
ORR R2, R2, R1
STR R2, [R0]
Examples
LDR R0, =(FIO3CLR)
4
Input A P2.3 .. P2.0
1. Set Input A, Input B, and Sum as
GPIO 4
Input B P2.11 .. P2.8
2. Configure each pin as neither pull-
up or pull-down resistor
3. Set Input A, Input B as an input 4
Sum P3.3 .. P3.0
4. Set Sum as an output