Chapter 6 Notes - QA
Chapter 6 Notes - QA
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.
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 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.
Example-PINSELO REGISTER
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.
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.
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.
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.
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.
Timer Registers
Prescale Register: The 32-bit register which hold the maximum value of
prescale counter after which it reset
Load desired count in Match register.( LPC2148 has match registers that
contain count value which is continuously compared with the value of the
Timer register.
The timer counter register starts increasing for every tick of PCLK
When the value in the Timer register matches the value in the match
register, specific action (timer reset, or timer stop, or generate an interrupt)
is taken.
Also, LPC2148 has capture registers which can be used to capture the timer
value on a specific external event on capture pins. For information about
LPC2148 capture operation refer Input Capture Mode
#include <LPC210x.H>
delay()
{
int i,j;
for(i = 1;i<= 500;i++)
for(j = 1; j<= 500;j++)
;
}
int main()
{
IODIR = 0x00000700;
while(1)
{
IOCLR = 0x00000700;
delay(); //delay
IOSET = 0x00000700;
delay(); //delay
}
}
To write a program to blink LED or to generate square wave as an
output using ARM processor use Timer of 2148
To write a program to interface Seven Segment LED with ARM and display the
numbers from 0-9 sequentially.
Algorithm:
1. Port 0 of ARM is used as an output port (P 0.0 – P 0.7).
2. Provide a code 00000003F to display ‘0’ on segment display.
3. Call delay.
4. Provide a code 00000006 to display ‘1’.
5. Call delay.
6. Provide a code 0000005B to display ‘2’.
7. Call delay.
8. Provide a code 00004F to display ‘3’.
9. Call delay.
10.Provide a code 0000066 to display ‘4’.
11.Call delay.
12.Provide a code 000006D to display ‘5’.
13.Call delay.
14.Provide a code 000007D to display ‘6’.
15.Call delay.
16.Provide a code 00000007 to display ‘7’.
17.Call delay.
18.Provide a code 000007F to display ‘8’.
19.Call delay.
20.Provide a code 000006F to display ‘9’.
21.Call delay.
22. Repeat step from 2 to 21 to display numbers continuously.
Program:
#include <LPC210x.H>
delay()
{ int i,j;
for(i = 1;i<= 300;i++)
for(j = 1; j<= 300;j++);
}
int main()
{ IODIR = 0x000000ff;
while(1)
{ IOSET = 0x0000003f;
delay(); //delay
IOCLR = 0x0000003f;
delay(); //delay
IOSET = 0x00000006;
delay(); //delay
IOCLR = 0x00000006;
delay(); //delay
IOSET = 0x0000005b;
delay(); //delay
IOCLR = 0x0000005b;
delay(); //delay
IOSET = 0x0000004f;
delay(); //delay
IOCLR = 0x0000004f;
delay(); //delay
IOSET = 0x00000066;
delay(); //delay
IOCLR = 0x00000066;
delay(); //delay
IOSET = 0x0000006d;
delay(); //delay
IOCLR = 0x0000006d;
delay(); //delay
IOSET = 0x0000007d;
delay(); //delay
IOCLR = 0x0000007d;
delay(); //delay
IOSET = 0x00000007;
delay(); //delay
IOCLR = 0x00000007;
delay(); //delay
IOSET = 0x0000007f;
delay(); //delay
IOCLR = 0x0000007f;
delay(); //delay
IOSET = 0x0000006f;
delay(); //delay
IOCLR = 0x0000006f;
delay(); //delay
}
}
Circuit Diagram: