You are on page 1of 89

J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 1

JX-2148
LPC2148 ARM7-32 bit Microcontroller Education board
1. Kit Conte nts
In standard package of J X-2148 board include :
1. J X-2148 Education board x 1
2. CX-232 serial port cable x 1
3. AWG#22 wire jumper, 7cm. length x 10
4. Documentation x 1
5. CD-ROM x 1
6. GLCD5110 graphic LCD module x 1
To run this education board youll need: DC adaptor +6Vdc 500mA (maximum
+9Vdc)
2. JX- 2148 boa rd fe a ture s
LPC2148 microcontrollers are based on a 32-bit ARM7TDMI-S CPU with real-time
emulation and embedded trace support, that combine microcontroller with embedded
high-speed flash memory 512 kB. A 128-bit wide memory interface and a unique accelerator
architecture enable 32-bit code execution at the maximum clock rate
Standard J TAG connector
USB 2.0 Full Speed Interface (USB connector type B). J X-2148 board provides a
USB interface connector that interfaces ot the on-chip USB peripheral of the LPC2148
device. You may configure the board as self-powered or USB powered device.
Dual Serial Ports. J X-2148 provides standard DB9 connectors for both of the
LPC214xs serial ports. UART-0 for communication and support In-System Programming (ISP),
UART-1 for serial communication and select to connect ESD-200 Bluetooth module (optional)
by jumpers.
SD/MMC socket. The J X-2148 provides one SPI module to interface SD/MMC
memory socket.
A PS/2 jack for interface Keyboard or Mouse.
2 of push-button switches with resistor pull-up.
2 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
2 of LED indicators
Analog Voltage Control for ADC Input. J X-2148 provides an adjustable analog
voltage source for testing the A/D converter feature of the LPC2148.
A small buzzer for sound experiment
Mini-breadboard 170 points contact.
32kHz crytal and +3V battery backup for real-time clock system within MCU.
+3.3V on-board regulator for MCU and +5V for PS/2 circuit.
Polarity voltage protection.
3. Syste m re quire me nts
To use the J X-2148 Education Board, the following item must be prepared :
An IBM-compatible PC with port of the following:
- one unused USB ports to test USB experiment
- at least one unused RS-232 port for In-System Flash Programming via
Serial Interface. If have two better, because can download and test communication both.
Install Windows XP Operating System
Install Keil ARM tool kit evaluation version. Download at www.keil.com
Install Sourcery G++ Lite Edition - free C compiler for ARM Download at
www.codesourcery.com
Install LPC2000 In-system programming utility software from NXP. Download
at www.nxp.com and search by keyword Microcontroller ARM7 or Flash Magic ;
download at www.flashmagictool.com
USB to RS-232 serial port converter. In case the computer does not provide RS-
232 port. (Suggest UCON-232S. See detail at www.inexglobal.com)
DC adaptor +9V 500mA recommended.
A serial cable, 9-pin male to 9-pin female, 1.8 m length, wired one-to-one. In
case using both UART in same time. CX-232 cable from INEX recommended
ESD-200 Bluetooth module if need to make wireless communication.
PS/2 Keyboard if need to make PS/2 keyboard interface experiment.
PS/2 Mouse if need to make PS/2 mouse interface experiment.
USB cable, AB type not over 3m. length for testing USB interface.
ULINKUSB-J TAG adaptor. Direct contact to www.keil.com.
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 3
4. JX- 2148 boa rd la yout
The figure 1 illustration shows the important interface and hardware components
of the J X-2148 board.
ON
USB
ON
OFF
+
++.5-9v
JTAGJDEBUG port
RESET
SDJMMC
BLUETOOTH
ESD-02
STATUS
R
x
D
T
x
D
R
T
S
C
T
S
UART CH.1
LITIUM
BATTERY 3V
+3v BATT
12NHz
32.768kHz
+3.3v
GND
REF
DEBUG EN.
U
A
R
T

C
H
0
!SP
SW!TCH
0.28 0.29
0.21 0.22
0.30 (AfD)
PSJ2
DAT 0.15
CLK 0.16
PIEZO
0.12-0.13
PORT
1.20
1.21
1.22
1.23
S
P
I
-
0
G0
.
0
+
0
.
0
5
0
.
0
6
0
.
0
7
+
T
W
I
-
0
G0
.
0
2
0
.
0
3
+
LPC21+8
P
O
R
T
P
1
.
1
9
P
1
.
1
8
P
1
.
1
7
P
1
.
1
6
0.25
(DfA)
G
USB
:"&
ARM7-LPC214S
Education board
Figure 1 : The JX-21+8 board layout
v
c
c
T
R
S
T
T
D
I
T
N
S
T
C
L
K
R
T
C
K
T
D
O
R
E
S
E
T
N
f
C
N
f
C
v
c
c
G
N
D
G
N
D
G
N
D
G
N
D
G
N
D
G
N
D
G
N
D
G
N
D
G
N
D
CP
WP
& % $ # " ! '
CS
NOSI
CND
+3.3v
SCK
CND
NISO FE & =@ '
J KIA@
6F LEAM
)6-)
4N,
8,,
56)675
/,
/,
6N,
465
+65
E
S
D
-
0
2
J TAG pin assignment ESD-200 Bluetooth
module connector
pin assignment
4 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
5. JX- 2148 ope ra tion
The operation of J X-2148 board has 3 main sections following :
(1) LPC2148 microcontroller unit
(2) Power supply
(3) Input/Output circuit
M ic roc ontrolle r unit consist of NXPs LPC2148 and 2 of Clock oscillator circuit; 12MHz
main clock oscillator and 32.768kHz for real-time clock. The full schematic can see in the
figure 2.
Powe r supply of J X-2148 has 2 regulator. One is +3.3V. It receives +6 to +16V from
external DC adaptor. The 3.3V regulated circuit supplies to the microccontroller unit and
many I/O devices. Another one is +5V for supply PS/2 circuit.
M a ny I/ O d e vic e s are installed on the J X-2148 board. Includes LED, Push-button
switches, Variable resistor for A/D converter circuit, Two of RS-232 serial port interface, PS/
2 jack, MMC/SD socket, USB port interface, J TAG interface for many debugger such as
ULINK from Keil or Olimex JTAG adaptor or Wiggler from Macraigor, ESD-02 Bluetooth
connector, Free I/O microcontroller port and a Mini-breadboard 180 points for construction
the experimental circuit.
6. JX- 2148 c irc uit de sc ription
The complete shcematic of the J X-2148 board shows in the figure 2. The main device
is NXPs LPC2148 ARM7 microcontroller. LPC2148 is assigned to connect many I/O devices
as :
P0.00/TxD0 and P0.01/RxD0 are connected to RS-232 serial port inteface at UART0
P0.02/SCL0 and P0.03/SDA0 are connected with I
2
C bus or Two wire interface
(TWI)
P0.04 to P0.07 are connected SPI bus
P0.08/TxD1, P0.09/RxD1, P0.10 and P0.11 are connected with serial port interface
circuit; UART1 and ESD-02 Bluetooth module connector. User can select by jumpers. P0.10
pin is connected with CTS pin and P0.11 is connected with RTS pin. See the figure 3.
P0.12 and P0.13 are connected to buzzer.
P0.15 and P0.16 are connected with PS/2 jack. P0.15 is data pin and P0.16 is
clock pin.
P0.17 to P0.20 are SSP module port. They are connected with MMC/SD socket.
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 5
P
1
.
2
0
P
1
.
2
1
P
1
.
2
2
P
1
.
2
3
+
8
+
+
+
0
3
6
1
6
1
2
8+
+
8
+
+
+
0
3
6
P
1
.
2
+
P
1
.
2
5
P
1
.
2
6
f
R
T
C
K
P
1
.
2
7
f
T
D
O
P
1
.
2
8
f
T
D
I
P
1
.
2
9
f
T
C
K
P
1
.
3
0
f
T
N
S
P
1
.
3
1
f
T
R
S
T
1
2
3579
1
1
1
3
1
5
+681
0
1
2
1
+
1
6
1
7
1
8
1
9
2
0
T
R
S
T
T
D
I
T
N
S
T
C
K
R
T
C
K
T
D
O
R
S
T
+
3
.
3
v
R
1
6
1
0
k

*
+
R
1
7
1
0
k
R
1
8
1
0
k
J
P
1
D
B
G
_
E
N
K
5
J
T
A
G
35
R
T
C
X
1
R
T
C
X
2
C
+
1
5
p
F
C
5
1
5
p
F
X
T
A
L
1
3
2
.
7
6
8
k
H
z
6
2
6
1
X
1
X
2
C
6
3
3
p
F
C
7
3
3
p
F
X
T
A
L
2
1
2
N
H
z
+
9
D
2
1
N
5
8
1
9
+
3
.
3
v
v
b
a
t
2
3
+
3
5
1
v
d
d
3
-
1
(
I
f
O
)
v
d
d
3
-
2
(
I
f
O
)
v
d
d
3
-
3
(
I
f
O
)
D
3
1
N
5
8
1
9
B
A
T
T
1
+
3
v
C
8
C
8
-
C
1
0
0
.
1

F

x
3
C
9
7
v
d
d
3
(
A
)
5
9
v
s
s
A
C
1
0
6 v
s
s
1
1
8
2
5
1
2
+
3
.
3
v
6
3
v
r
e
f
+
3
.
3
v
G
N
D
D
I
S
E
N
J
P
2
V
r
e
f
I
C
1
7
8
R
3
3
J
1
D
C
.
i
n
p
u
t
+
.
5
-
1
2
v
C
1
2
2
0
f
2
5
v
C
2
1
0
0
0

F
6
.
3
v
+
3
.
3
v
S
W
1
P
O
W
E
R
B
D
1
1
A
5
0
v
K
2
D
C
.
i
n
p
u
t
+
.
5
-
1
2
v
/,
S
H
D
U
S
B
D
+
U
S
B
D
-
+
5
v
U
S
B
U
S
B
D
-
U
S
B
D
+
K
1
U
S
B
1
0
1
1
R
5
2
7
R
6
2
7
5
8
R
7
1
0
k
P
0
.
2
3
v
B
U
S
2
P
0
.
2
2
+
3
.
3
v1
P
0
.
2
1 L
E
D
+
0
.
2
1
L
E
D
3
0
.
2
2
P
0
.
2
0
S
S
E
L
1
P
0
.
1
9
N
O
S
I
1
P
0
.
1
8
N
I
S
O
1
P
0
.
1
7
S
C
K
1
P
0
.
1
6
P
0
.
1
5
C S
D I
S C K
D O
+
3
.
3
v
+
3
.
3
v
v
s
s
1
v
s
s
2
R
E
S
R
E
S
C
P
1
W
P
1
v
d
d
R
2
2
2
k
R
3
2
2
k
R
1
0
1
0
k
R
1
1
1
0
k
+
v
I
C
2
2
9
3
1
-
5
.
0
O
U
T
+
5
v
C L K
D A T
R
1
2
1
0
k
R
1
+
1
5
0
R
1
3
1
5
0
R
8
5
1
0
R
9
5
1
0
P
0
.
1
3
P
0
.
1
2
5
5
5
+
5
3
+
7
+
6
+
5
+
1
3
9
R
1
9
2
2
0
+
3
.
3
v
I
N
G
N
D
+
v
+
3
.
3
v
L
E
D
5
B
T
-
S
T
A
T
U
S R
1
5
1
0
k
N
O
D
1
E
S
D
-
0
2
P
0
.
1
1
P
0
.
1
0
P
0
.
0
9
f
R
x
D
1
P
0
.
0
8
f
T
x
D
1
R x D
T x D
C T S
R T S
123+5
9 8 7 6
3
7
3
5
3
+
3
3
J
P
+
R
T
S
1
_
S
E
L
E
C
T
J
P
5
C
T
S
1
_
S
E
L
E
C
T
J
P
6
R
x
D
1
_
S
E
L
E
C
T
J
P
7
T
x
D
1
_
S
E
L
E
C
T
R T S _ B l u e t o o t h
C T S _ B l u e t o o t h
R x D _ B l u e t o o t h
T x D _ B l u e t o o t h
R
T
S
U
A
R
T
C
T
S
_
U
A
R
T
R
x
D
_
U
A
R
T
T
x
D
_
U
A
R
T
T
1
I
T
1
O
1
09
1
2
1
1
1
+
1
3
8 7 6 2 1
5
1
6
R
1
O
R
1
I
R
2
O
R
2
I
T
2
I
T
2
O
v
+
v
-
C
1
+
C
1
-
13
+
v
d
d
C
1
1
0
.
1

F
C
1
2
,

C
1
3
0
.
1

F


x
2
C
1
5
0
.
1

F
K
6
U
A
R
T
1
R
S
-
2
3
2
C
2
+
C
2
-
5
C
1
+
0
.
1

F
P
1
.
1
6
P
1
.
1
7
P
1
.
1
8
P
1
.
1
9
1
6
1
2
8+
3
1
3
0
2
9
2
7
P
0
.
0
7
f
S
S
E
L
0
P
0
.
0
6
f
N
O
S
I
0
P
0
.
0
5
f
N
I
S
O
0
P
0
.
0
+
f
S
C
K
0
P
0
.
0
7
J
S
S
E
L
0
P
0
.
0
6
J
M
O
S
I
0
P
0
.
0
5
J
M
I
S
O
0
P
0
.
0
4
J
S
C
K
0
S
P
I
-
0
P
1
.
1
6
P
1
.
1
7
P
1
.
1
S
P
1
.
1
9
P
1
.
2
0
P
1
.
2
1
P
1
.
2
2
P
1
.
2
3
P
O
R
T
1
G
N
D
2
6
2
2
P
0
.
0
3
f
S
D
A
0
P
0
.
0
2
f
S
C
L
0
P
0
.
0
3
J
S
D
A
0
P
0
.
0
2
J
S
C
L
0
T
W
I
{
I
2
C
)
G
N
D
+
3
.
3
v
+
3
.
3
V
+
3
.
3
v
123+5
9 8 7 6
T
1
I
T
1
O
1
3
8 7 6 2 1
5
1
6
R
1
O
R
1
I
R
2
O
R
2
I
v
+
v
-
v
d
d
C
1
6
0
.
1

F
C
1
9
,

C
2
0
0
.
1

F


x
2K
7
U
A
R
T
0
R
S
-
2
3
2
I
S
P
P
0
.
0
1
f
R
x
D
0
P
0
.
0
0
f
T
x
D
0
1
C
1
+
C
1
-
3
C
1
7
0
.
1

F
+
C
2
+
C
2
-
5
C
1
8
0
.
1

F
S
W
2
R
E
S
E
T
+
3
.
3
v
+
3
.
3
v
R
2
0
1
k
R
2
2
2
2
k
R
2
1
1
0
k
R
2
3
+
7
1
0
9
1
2
P
0
.
1
+
f
B
S
L
R
S
T
2
1
1
9
+
1
5
7
I
C
6
K
I
A
7
0
3
1
+
3
.
3
v
R
S
T
+
v
G
N
D
+
3
.
3
v
Q
1
D
T
A
1
1
+
R
+
5
1
0
L
E
D
2
U
S
B
P
0
.
3
1
f
U
P
_
L
E
D
1
7
P
0
.
2
9
P
0
.
2
8
+
3
.
3
v
P
0
.
3
0
9
P
0
.
2
5
f
A
D
0
.
+
f
A
O
U
T
P
0
.
2
S
J
D
A
G
N
D
R
2
+
1
0
k
R
2
5
1
0
k
v
R
1
-
1
0
k
A
D
C
0
.
3
0
S
1
P
0
.
2
S
S
2
P
0
.
2
9
S
W
3
I
S
P
O
U
T
I
N
K
3
S
D
J
M
M
C
K
+
P
S
2
I
C
3
L
P
C
2
1
+
8
D
1
1
N
5
8
1
9
L
E
D
1
O
N
R
1
5
1
0
C
3
0
.
1

F
v
s
s
2
v
s
s
3
v
s
s
+
S
P
1
P
I
E
Z
O
I
C
+
N
A
X
3
2
3
2
I
C
5
N
A
X
3
2
3
2
R
2
6
1
.
5
k
Figure 2 JX-21+8 board schematic diagram
6 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
P0.21 and P0.22 are connected with LED in active low.
P0.25 is D/A output of D/A converter module in LPC2148.
P0.28 and P0.29 are connected push-button switches with pull-up resistors.
P0.30 is connected with 10kW variable resistor for testing A/D converter module.
P0.31 is used to control USB port interfacing and connected with REDY
connection indicator circuit.
P1.16 to P1.23 are free port.
P1.24 and P1.25 are connected MMC/SD socket to testing card insertion.
P1.26 to P1.31 are assigned as J TAG interface.
In- syste m fla sh progra mming of JX- 2148 will work via UART0 module . SW3 is ISP mode
switc h. M ust pe ss this switc h to e nte r ISP mode .
LPC2148 has each of SPI (Serial Peripheral Interface) and SSP (Synchronous Serial
Port) module. THe SSP module can work in SPI mode.On J X-2148 board define SSP to
connect with MMC/ SD card interface. The SPI module (SPI0) will reserve to connect
addition SPI peripheral.
BLUETOOTH
ESD-200
STATUS
R
x
D
T
x
D
R
T
S
C
T
S
UART CH.1
Select jumpers to define UART1
module of LPC21+8 connected
with RS-232 serial port
BLUETOOTH
ESD-200
STATUS
R
x
D
T
x
D
R
T
S
C
T
S
UART CH.1
A
N
T
E
N
N
A
ESD-200
!nstall ESD-20 module
on female connector
Select jumpers to define UART1
module of LPC21+8 connected
with ESD-200 Bluetooth module
Figure 3 Shows the step of select UART1 to connect RS-232 port and ESD-200
Bluetooth module (ESD-200 is optional device)
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 7
In A/D converter demonstration, on J X-2148 board provides one POT or variable
resistor is connected at P0.30 ready to test with programming.
In testing simple I/O port, the J X-2148 board provides 2 of LED that connected with
P0.21 and P0.22. About input device, provides 2 of push-button switch to connect with
P0.28 and P0.29. Two port pins P0.12 and P0.13 are connected with buzzer to sound
generator.
PS/2 interface need +5V. LM2931-5.0 IC is regulator +5V IC. It receive input voltage
from main DC adaptor.
USB interface use USBD+ and USBD- pin. They are connected limited current
protection resistor. Port 0.23/VBUS is connected with +5V from USB port connector. Interface
controlling port is function of P0.31 port pin. In connection must control this pin to logic
0. Thus, user can control the USB connections via software.
REF jumpe r : use to select the reference voltage of A/D converter module. Normally
connected with +3.3V. If need to use external reference voltage, user can do very easy
step. Remove jumper out and connect the external reference voltage with middle pin of
REF jumper.
DEBUG EN. jumpe r : Select to enable degugging via J TAG connector.
8 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
7. Softwa re De ve lopme t tools :
We suggest the free of charge development tools for LPC2148 microcontroller. It
includes 3 mainly tools as Re a lVie w M ic roc ontrolle r De ve lopme nt Kit or Ke il ARM tool kit
evaluation version, Sourc e ry G++ Lite (its C compiler) and ISP Downloa ding softwa re
(LPC2000 Flash Utility and Flash Magic)
7.1 Softwa re insta lla tion
7.1.1 Sourc e ry G++ Lite : C c ompile r for 32- bit ARM mic roc ontrolle r
CodeSourcery, in partnership with ARM, Ltd., develops improvements to the GNU
Toolchain for ARM processors and provides regular, validated releases of the GNU
Toolchain. Sourcery G++Lite Edition supports ARM, Thumb, and Thumb-2 compilation for
all architectures in active use, including Version 7 of the ARM Architecture.
Sourcery G++Lite Edition is a free. It contains command-line tools, including the
GNU C and C++compilers, the GNU assembler and linker, C and C++runtime libraries,
and the GNU debugger. Download free of charge at http :/ / www.c od e sourc e ry.c om/
g nu_to o lc ha ins/ a rm / p o rta l/ re le a se 323. For Windows platform ; select IA32 Windows
Installer to get file arm-2008q1-126-none-eabi.exe
Installation step is as follows :
(1) After downlaod the setup file already, double-click at .exe file. The installtion
window is appeared. Click on the Ne xt button.
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 9
(2) The License Agreement window is appeared. Select option I a c c e pt the te rms
of Lic e nse Agre e me nt and click on the Ne xt button.
(3) Click OK or Next button to accept all step until to Choose Insta ll Se t window.
Select type of installation as Typic a l. Click on the Ne xt button.
(4) Choose Insta ll Folde r window is appeared. Select drive and folder as C:\ Progra m
File s\ Code Sourc e ry\ Sourc e ry G++ Lite . Click on the Ne xt button.
10 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
(5) Add produc t to the PATH? window is appeared for changing installation path.
Select M od ify PATH for c urre nt use r heder for adding installtion path for speific user or
select M odify PATH for a ll use rs. header for adding path for everyone. Click on the Ne xt
button.
(6) The Choose Shortc ut Folde r is appeared next. Click on othe r header and Ne xt
button.
(7) Software shows installation summary. Click on the Ne xt button until software is
installed successfully. Click on Done button to finish.
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 11
7.1.2 Re a lvie w M ic roc ontrolle r De ve lopme nt Kit
Realview Microcontroller Development Kit is completely micrcocontroller
development tool from Keil (www.keil.com) It includes Text editor for creating the C code,
C compiler (limit 32KB) and Debugger. In this manual use this tool for creating the code
only.
(1) Start instllation by double-clicking on the setup file (MDK322a .e xe ). The installation
window is appeared. Click on the Ne xt button.
(2) The License Agreement window is appeared. Select option I a c c e pt the te rms
of Lic e nse Agre e me nt and click on the Ne xt button.
(3) Folde r Se le c tion window is appeared. Selecte drive and folder for installtion.
For example is C:\ Ke il . Click on the Ne xt button.
12 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
(4) Enter the C ustome r Informa tion window. Type your information and e-mail
address. After that the Ne xt button will be active. Click this button to next step.
(5) Installtion is proceed. Wait until installation is completed.
(6) The Ke il uVision3 Se tup Comple te d will be appeared. Click the box following
the picture below and Finish button. The installation is finished.
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 13
7.1.3 LPC 2000 Fla sh utility
The LPC2000 Flash utility provides In-System Flash Programming (ISP) support
for Intel HEX files. The Philips LPC2000 Flash Utility connects the PCs COM port to
the serial port UART0 of the J X-2148 Education board. The installation program for
this utility is included on the INEX J X-2148 CD-ROM or may be downloaded from the
Philips Web Site. The LPC2000 Flash Utility may be run as a stand-alone utility or as an
external tool from within the mVision IDE. The version of LPC2000 Flah utility that
support LPC2148 is V2.2.3 or higher.
The normal installation file name of Philips LPC2000 Flash utility is Philips Flash
Utility Installation.exe. Double-click that file. Accept all confirmation until installation
complete.
7.1.4 Fla sh Ma gic
Another ISP software tools for LPC2148 is Flash Magic. This software is newer and also
supported by NXP. User can download free of charge at http:/ / www.flashmagictool.com.
The version of Flash Magic that support LPC2148 is V4.13 or higher.
Installation is simple. Double-click at setup (.exe) file. Accept all confirmation until
installation is completed.
14 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
8. How to de ve lop c ode with Ke il Vision3
a nd Sourc e ry G++ Lite c ompile r
This sections introduce you to the Keil development tools, and take you through
the process using them with the J X-2148 board. Youll learn how to create the C code,
compile, download and run a program on this board.
Developing programs for the J X-2148 board is easy. The process is:
(1) Create code using the Vision IDE. Compile with Sourcery G++Lite compiler.
(2) Download the program to the on-chip Flash of the J X-2148 Board by using
LPC2000 Flash Utility or Flash Magic.
8.1 How to use Sourc e ry G++ Lite with Ke il Vision3
(1) After insall RVMDK 3.22a and Sourcery G++Lite already, open Keil Vision3. If
any project file still open, need to close by clicking menu Proje c t C lose Proje c t....
(2) After that select menu Proje c t, M a na ge me nt, Compone nt, Environme nt, Book.
The Compone nt, Environme nt a nd Book window is appeared.
(2.1) At Se le c t ARM De ve lopme nt Tools , select Use c Compile r
(2.2) Set the new compiler at GNU- Tool- Prefix box as arm-none-eabi-
(2.3) At Cygnus Folde r box, select the code location. Normally it is in C:\ Progra m
File s\ Code Sourc e ry\ Sourc e ry G++ Lite \ folder. Click on the OK button.
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 15
8.2 Cre a te the e xa mple proje c t file
(1) Create the new project fle. Select menu Proje c t Ne w Proje c t. Set the project
name and folder location.
This example is set name as Te st in C:\ NXP2148 folder. Click on the Sa ve button.
(2) Select target chip on the Se le c t De vic e for Ta rge t Ta rge t 1 window
16 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
(3) At Da ta b a se box, select Microcontroller manufacturer as NXP ( found e d b y
Philips) and select device as LPC2148. Click on the OK button.
(4) Select menu Proje c t Option for Ta rge t Ta rge t1 . The Option for Ta rge t Ta rge t1
is appeared. Select Ta rge t tab. At Xta l ( M Hz) : box, set clock frequency as 12.0. It s mean
12MHz clock frequency.
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 17
(5) Next, select Output tab. Click to mark at Cre a te HEX File box for creating the
hex file afrer compiling the project file.
(6) Select Use r tab. At Run Use r Progra ms Afte r Build/ Re build box, select Run #1
and type this command below into the box.
arm-none-eabi-size *.hex
18 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
(7) Click CC tab. At Optimiza tion box, select No Optimiza tion for setting normal
compilation.
(8) At Linke r tab, click at Do not use Sta nda rd Syste m Sta rtup File s for removing the
mark. Next , check box at Ena ble Ga rba ge Colle c tion. At Linke r Sc ript File box, type the
filename ARM.ld following the picture below. Click on the OK button to back the main
window of program.
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 19
(9) Copy the start up file Startup.s and ARM.ld from CD-ROM into same project
folder. (in this example is C:\ NXP2148)
(10) Back to main window, double-click at Sourc e G roup 1 message in Proje c t
Workspa c e box following the picture below.
(11) The Add File s to Group Sourc e Group 1 window is appeared. At File s of type
box, select the file type as Asm Sourc e file ( * .s; * .src ; * .a ) . It shows location of Sta rtup.s file
from step (9). Click on the Sta rtup .s file following click on the Add button and Close
button.
20 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
(12) Select menu File Ne w . The blank window will be appeared. Name is Te xt1.
Type this C code below (/ / is single line comment)
////
// Program for test board JX-2148
// File : LED.C
// Target MCU : NXP LPC2148 12.0MHz,
// : CCLK = 60 MHz, PCLK = 30 MHz
// IDE : Keil RVMDK V3.22a,
// Compiler : Code Sourcery G++ Lite 2008q1V126
// : LED Blink on GPIO0.22
////
#include <LPC214x.H> // LPC2148 MPU Register
////
// Delay Time Function
////
void delay(unsigned long int count)
{
while(count > 0) {count;}
}
int main(void)
{
PINSEL1 &= 0xFFFCFFFF; // Set GPIO0.22 = GPIO Function
IODIR0 = 0x00400000; // Set GPIO0.22 = Output
IOSET0 = 0x00400000; // Set GPIO0.22 Pin (OFF LED)
while(1)
{
IOCLR0 = 0x00400000; // Clear Pin P0.22 (ON LED)
delay(1500000); // Delay
IOSET0 = 0x00400000; // Set Pin P0.22 (OFF LED)
delay(1500000); // Delay
}
}
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 21
(13) Save file as LED.c . At the Proje c t Workspa c e ; it displays all files that included in
this project. This project has 2 files; Sta rtup.s and LEC.c
(14) Compile this project file by selecte menu Proje c t Re build a ll ta rge t file s If no
any error, the Output window reports messages 0 Error( s) , 0 Wa rning( s) and file size 0f
the hex file.
Finally, the result of compilation is .hex file for downloading to LPC2148
microcontroller by using LPC2000 Flash Utility or Flash Magic software
22 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
8.3 Downloa d progra m a nd te st with LPC2000 Fla sh Utility
After compile the program, from example the result file is le d .he x. Next step is
downloading hex file to LPC2148 microcontroller and run it. Developers can check the
operation at P0.22 LED. The downloading procedure is :
(1) Apply the supply voltage to J X-2148 board. Turn-on POWER switch.
(2) Connect download cable to the J X-2148 board and Serial port of computer
or connect iva USB to serial port converter (UCON-232S is recommended).
(3) Open the LPC2000 Flash Utility software.
(4) In the first time, developers must set some parameter before
At Device box set as :
- De vic e select to LPC2148
- XTAL Fre q. [kHz] set to 12000 (12MHz)
At Communication box set as :
- Conne c te d To Port select the serial port is connected
- Use Ba ud Ra te set baudrate. 9,600 bps is default.
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 23
(5) Set the J X-2148 board to ISP mode by press ISP SWITCH (its shaft will down)
following press RESET switch once.
ON
USB
ON
OFF
+
++.5-9v
JTAGJDEBUG port
RESET
SDJMMC
BLUETOOTH
ESD-02
STATUS
R
x
D
T
x
D
R
T
S
C
T
S
UART CH.1
LITIUM
BATTERY 3V
+3v BATT
12NHz
32.768kHz
+3.3v
GND
REF
DEBUC EN.
7
)
4
6

+
0

!SP
SWITCH
0.28 0.29
0.21 0.22
0.30 (AfD)
PSJ2
DAT 0.15
CLK 0.16
PIEZO
0.12-0.13
PORT
1.20
1.21
1.22
1.23
S
P
!
-
0
G0
.
0
+
0
.
0
5
0
.
0
6
0
.
0
7
+
T
W
!
-
0
G0
.
0
2
0
.
0
3
+
LPC21+8
P
O
R
T
P
1
.
1
9
P
1
.
1
8
P
1
.
1
7
P
1
.
1
6
0.25
(DfA)
G
USB
:"&
ARM7-LPC214S
Education board
Press the ISP switch. The switch's shaft is down.
1
2
(6) At the main wondow of LPC2000 Flash Utility. Click at Ma nua l Re se t button
once following click Re a d De vic e ID once too. If the connection is correct, status bar at
left down conner will show message Re a d Pa rt ID Suc c e ssfully
24 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
If connection fail, the warning window will appear following the figure 41.
Click Re a d De vic e ID button again and see the result. May be back to do in step (5) and
(6) again.
(7) If connection complete, click at Bro w se button in File na m e of Fla sh
Progra mming . Select le d.he x in path C:\ le d\ le d.he x. Next, click Uploa d to Fla sh button
to download. After downloading complete the message File Up lo a d Suc c e ssfully
Comple te d will show at the status bar.
(8) Developers can test the program by press ISP switch again to RUN mode
(The switchs shaft will release) and press RESET switch once. Observe the operation.
LED at P0.22 blink continuous.
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 25
8.4 Downloa d progra m a nd te st with Fla sh Ma gic
We have another ISP software for supporting the J X-2148. It is Flash Magic. Installtion
this software is very easy. This software is newer and also supported by NXP. User can
download free of charge at http:/ / www.flashmagictool.com. The version of Flash Magic
that support LPC2148 is V4.13 or higher.
Installation is simple. Double-click at setup (.exe) file. Accept all confirmation until
installation is completed.
8.4.1 Ha rdwa re c onne c tion a nd se tup
(1) Apply the supply voltage to J X-2148 board. Turn-on POWER switch.
(2) Connect download cable to the J X-2148 board and Serial port of computer or
connect iva USB to serial port converter (UCON-232S is recommended).
(3) Set the J X-2148 board to ISP mode by press ISP SWITCH (its shaft will down)
following press RESET switch once.
8.4.2 Fla sh M a gic se tup ( do only first time )
(1) Open Flash Magic. Enter to Main window. Select menu Option Adva nc e
O p tion...
(2) At Adva nc e Option window, select Ha rdwa re Config tab and click to remove
the marl at Use DTR c ontrol RTS box following the picture below. Click on the OK button.
26 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
8.4.3 Downloa d a nd te st
(1) Set communication properties at Ste p 1 - Communic a tion.
(1.1) Select the comminication port at COM port. For example is COM1.
(1.2) Select Baud Rate as 38400
(3.3) Select De vic e as LPC2148
(3.4) At Inte rfa c e box, select None ( ISP)
(2) Ste p 2 - Era se : Erase option; select Era se a ll Fla sh.
(3) Open the HEX file at Ste p 3 - He x File .
(4) Select Ve rify a fte r progra mming in Ste p 4 - Option if require to verify.
(5) Click on the Sta rt button in Ste p 5 - Sta rt! to start the downloading.
(6) After downloading is finished, it shows Finish message. You can test the program
by press ISP switch again to RUN mode (The switchs shaft will release) and press RESET
switch once. Observe the operation.
LED at P0.22 blink continuous.
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 27
9. Sa mple Expe rime nt
Expe rime nt - 1 : Output port
This is simple experiment. This experiment is testing output port function of LPC2148
to drive 2 LED at P0.21 and P0.22.
Proc e dure :
1.1 Build new project, in name le d
1.2 Write the program Listing P1-1. Compile to le d.he x and download to microcontroller.
1.3 Run program. Observe the operation of LED at P0.21 and P0.22
Both LED will blink every 0.5 second.
ON
USB
ON
OFF
+
++.5-9v
JTAGJDEBUG port
PESET
SDJMMC
BLUETOOTH
ESD-02
ST^TUS
R
x
D
T
x
D
R
T
S
C
T
S
UART CH.1
LITIUM
BATTERY 3V
+3v B^TT
12NHz
32.768kHz
+3.3v
CND
REF
DEBUG EN.
U
A
R
T

C
H
0
!SP
SWITCH
0.28 0.29
0.21 0.22
0.30 (^fD)
PSJ2
D^T 0.15
CLK 0.16
PIEZO
0.12-0.13
POPT
1.20
1.21
1.22
1.23
S
P
I
-
0
G0
.
0
+
0
.
0
S
0
.
0
6
0
.
0
7
+
T
W
I
-
0
G0
.
0
2
0
.
0
3
+
LPC21+8
P
O
R
T
P
1
.
1
9
P
1
.
1
8
P
1
.
1
7
P
1
.
1
6
0.25
(Df^)
C
USB
:"&
ARM7-LPC214S
Education board
Connect to
serial port
Press down to Program
Press up to Run
Observe LED operation
28 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
LPC21+8
Listing P1-1 : led.c file of led project for LPC21+8 output port
experiment (continue)
////
// Program : Example for display LED
// Description: LED Blink toggle at P0.21 and P0.22
// Frequency : Crystal 12 MHz at PLL 5x(CCLK = 60 MHz),PCLK = 30 MHz
// Filename : led.c
// C compiler : Sourcery G++ Lite Compiler
////
#include lpc214x.h // Header file for Phillips LPC2148 controller
#define LED1_ON FIO0CLR = 0x00200000 // Red led 0.21 on
#define LED1_OFF FIO0SET = 0x00200000 // Red led 0.21 off
#define LED2_ON FIO0CLR = 0x00400000 // Red led 0.22 on
#define LED2_OFF FIO0SET = 0x00400000 // Red led 0.22 off
// Function for Initial system clock //
void init()
{
PLL0CFG=0x24; // MSEL = 4,PSEL = 2
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
PLL0CON=0x1;
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
while(!(PLL0STAT & 0x400)) ; // Wait until PLL Locked
PLL0CON=0x3; // Connect the PLL as the clock source
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
MAMCR=0x2;
// Enabling MAM and setting number of clocks used for Flash memory fetch
// (4 clks in this case)
MAMTIM=0x4;
VPBDIV=0x02; // PCLK at 30 MHz
}
// Function delay //
void delay_ms(long ms) // delay 1 ms per count
{
long i,j;
for (i = 0; i < ms; i++ )
for (j = 0; j < 4000; j++ );
}
// Main Program //
int main()
{
init(); // Initialize the system
SCS = 0x03; // select the fast version of the I/O ports
FIO0DIR |= 0x00600000; // Config. pin P0.22 and P0.21 as output
while (1) // Infinite loop
{
LED1_ON; // Led at P0.21 ON
LED2_OFF; // Led at P0.22 OFF
delay_ms(500); // Delay 500 ms
LED2_ON; // Led at P0.22 ON
LED1_OFF; // Led at P0.21 OFF
delay_ms(500); // Delay 500 ms
}
}
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 29
Expe rime nt - 2 : Input port
In this experiment introduce using LPC2148 port acts input for reading data from
P0.28 and P0.29 that connected with push-button switches and resistor pull-up.
Proc e dure :
2.1 Build new project, in name switc h
2.2 Write the program Listing P2-1. Compile to switc h.he x and download to microcontroller.
2.3 Run the program. Try to press switch at P0.28 and P0.29. Watch the operation of LED at
P0.21 and P0.22.
P0.28 switch will control LED at P0.21 and P0.29 switch will control LED at P0.22
ON
USB
ON
OFF
+
++.5-9v
JTAGJDEBUG port
RESET
SDJMMC
BLUETOOTH
ESD-02
STATUS
R
x
D
T
x
D
R
T
S
C
T
S
UART CH.1
LITIUM
BATTERY 3V
+3v BATT
12NHz
32.768kHz
+3.3v
GND
REF
DEBUG EN.
U
A
R
T

C
H
0
!SP
SWITCH
0.30 (AfD)
PSJ2
DAT 0.15
CLK 0.16
PIEZO
0.12-0.13
PORT
1.20
1.21
1.22
1.23
S
P
I
-
0
G0
.
0
+
0
.
0
S
0
.
0
6
0
.
0
7
+
T
W
I
-
0
G0
.
0
2
0
.
0
3
+
LPC21+8
P
O
R
T
P
1
.
1
9
P
1
.
1
8
P
1
.
1
7
P
1
.
1
6
0.25
(DfA)
G
USB
:"&
ARM7-LPC214S
Education board
Press switch and
observe LED operation
0.21 0.22
0.28 0.29
Connect to
serial port
Press down to Program
Press up to Run
30 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
////
// Program : Example for test switch
// Description : Test switch at P0.28 and P0.29 for toggle LED at P0.21 and P0.22
// Frequency : Crystal 12 MHz at PLL 5x(CCLK = 60 MHz),PCLK = 30 MHz
// Filename : switch.c
// C compiler : CodeSourcery G++ Lite Compiler
////
#include lpc214x.h // Header file for Phillips LPC2148 controller
// Function for Initial system clock //
void init()
{
PLL0CFG=0x24; // MSEL = 4,PSEL = 2
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
PLL0CON=0x1;
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
while(!(PLL0STAT & 0x400)) ; // Wait until PLL Locked
PLL0CON=0x3; // Connect the PLL as the clock source
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
MAMCR=0x2;
// Enabling MAM and setting number of clocks used for Flash memory fetch
// (4 cclks in this case)
MAMTIM=0x4;
VPBDIV=0x02; // PCLK at 30 MHz
}
// Function Read input P0 //
char inp0(char _bit)
{
unsigned long c;
c = 1<<_bit; // Calculate digit to configuration for input port
FIO0DIR &= ~c; // Set input port from parameter _bit
return((FIO0PIN & c)>>_bit); // Read and return data bit
}
// Main Program //
void main()
{
init(); // Initialize the system
SCS = 0x03; // select the fast version of the I/O ports
FIO0DIR |= 0x00600000; // P0.21 and P0.22 for output port
FIO0SET |= 0x00600000; // OFF led P0.21 and P0.22 for initial
while (1) // Infinite loop
{
if(inp0(28)==0) // Check switch P0.28 push?
{
while(inp0(28)==0); // Wait until release switch P0.28
FIO0PIN ^= (1<<21); // Toggle led at P0.21
}
if(inp0(29)==0) // Check switch P0.29 push?
{
while(inp0(29)==0); // Wait until release switch P0.29
FIO0PIN ^= (1<<22); // Toggle led at P0.22
}
}
}
Listing P2-1 : switch.c file of switch project for LPC21+8 input port
experiment (continue)
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 31
More information about important function in this program
inp0 Read data bit from Port 0. The read bit position is agument.
syntax :
char inp0(char _bit)
parameter :
_bit define bit 0 of Port 0
return :
0 or 1 (In case connected switch, switch is pressed - return 0 and exit)
example :
char x;
x = inp0(28);
LPC21+8
Listing P2-1 : switch.c file of switch project for LPC21+8 input port
experiment (final)
32 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
Expe rime nt - 3 : Exte rna l Inte rrupt
This experiment demonstrate how to use External interrupt input port at EINT2 pin
(P0.07). Need to construct the addition circuit on breaboard of J X-2148 board below :
JTAGJDEBUG port
RESET
SDJMMC
BLUETOOTH
ESD-2
STATUS
R
x
D
T
x
D
R
T
S
C
T
S
UART CH.1
LITIUM
BATTERY 3V
+3v BATT
12NHz
32.768kHz
+3.3v
GND
REF
DEBUC EN.
!SP
SWITCH
0.28 0.29
0.21 0.22
0.30 (AfD)
PSJ2
DAT 0.15
CLK 0.16
PIEZO
0.12-0.13
PORT
1.20
1.21
1.22
1.23
S
P
I
-
0
G0
.
0
+
0
.
0
S
0
.
0
6
0
.
0
7
+
T
W
I
-
0
G0
.
0
2
0
.
0
3
+
LPC21+8
P
O
R
T
P
1
.
1
9P
1
.
1
8P
1
.
1
7P
1
.
1
6
0.25
(DfA)
G
10k
2+"&
S10 -,

P0.21
19
10k
S1
+3.3v
S
P0.07fEINT2
Construct this circuit
on breadboard
+3.3v
P0.13
P0.12
+1
39
220
SP1
P!EZO
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 33
Proc e dure :
3.1 Build new project, in name e xt_int2
3.2 Write the program Listing P3-1. Compile to e x t_int2 . he x and download to
microcontroller.
3.3 Run program. Try to press swtich at P0.07 or EINT2 port pin. Observe the operation of
LED at P0.21 and Piezo.
Switc h P0.07 pressing is used to c ontrol LED at P0.21 and generate sound for
informing the external interrupt is happen.
////
// Program : Example for EINT2(External interrupt2)
// Description : Test interrupt from switch press display by LED at P0.21
// : toggle and sound beep
// Frequency : Crystal 12 MHz at PLL 5x(CCLK = 60 MHz),PCLK = 30 MHz
// Filename : ext_int2.c
// C compiler : CodeSourcery G++ Lite Compiler
////
#include lpc214x.h // Header file for Phillips LPC2148 controller
#include sound.h // Header file for Phillips LPC2148 controller
// Function for Initial system clock //
void init()
{
PLL0CFG=0x24; // MSEL = 4,PSEL = 2
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
PLL0CON=0x1;
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
while(!(PLL0STAT & 0x400)) ; // Wait until PLL Locked
PLL0CON=0x3; // Connect the PLL as the clock source
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
MAMCR=0x2;
// Enabling MAM and setting number of clocks used for Flash memory fetch
// (4 cclks in this case)
MAMTIM=0x4;
VPBDIV=0x02; // PCLK at 30 MHz
}
// Interrupt service routine for EINT2 //
void __attribute__ ((interrupt(IRQ))) isr_int2(void)
{
beep(); // Sound beep 1 time
FIO0PIN ^= (1<<21); // Toggle LED at P0.21
EXTINT |= 0x4; // Clear interrupt flag EINT2
VICVectAddr = 0; // Acknowledge Interrupt
}
Listing P3-1 : ext_int2.c file of ext_int2 project for LPC21+8 external
interrupt port experiment (continue)
34 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
// Main Program //
int main()
{
init(); // Initialize the system
SCS = 0x03; // select the fast version of the I/O ports
FIO0DIR |= (1<<21); // Config. output P0.21 connect LED
FIO0SET |= (1<<21); // OFF LED
EXTMODE |= 0x4; // EINT2 Edge sensitive detection(Falling edge in this
program)
PINSEL0 = 0xC000; // Enable EINT2 at P0.7
VICVectAddr0 = (unsigned)isr_int2;
// Register Interrupt service routine name
VICVectCntl0 = 0x20 | 16; // EINT2 Interrupt
VICIntEnable |= 1 << 16; // Enable EINT2 Interrupt
while(1); // Infinite loop
}
More information about important function in this program
beep Generate beep sound one time. This function is add in sound.h library.
syntax :
void beep()
Listing P4-1 : ext_int2.c file of ext_int2 project for LPC21+8 external
interrupt port experiment (final)
LPC21+8
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 35
Expe rime nt - 4 : UART
ua rt.h libra ry
In this experiment must include an important library file ; uart.h. This library will set
the UART module in LPC2148. The source program of this library file in shown in Listing P4-1
Function that added in uart.h library has detail as :
uart1_init
Set the baudrate for UART1 module.
syntax :
void uart1_init(unsigned int _baudrate)
parameter :
_baudrate set baudrate value.
uart1_putc
Send a character to Transmitter buffer of UART1 module.
syntax :
void uart1_putc(char c)
parameter :
c define the transmited character
uart1_puts
Transmit string out to UART1 module
syntax :
void uart1_puts(char *p)
parameter :
p Index the transmited character
uart0_init
Set the baudrate for UART0 module.
syntax :
void uart0_init(unsigned int _baudrate)
parameter :
_baudrate set baudrate value.
uart0_putc
Send a character to Transmitter buffer of UART0 module.
syntax :
void uart0_putc(char c)
parameter :
c define the transmited character
36 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
uart0_puts
Transmit string out to UART0 module
syntax :
void uart0_puts(char *p)
parameter :
p Index the transmited character
Note : For only UART1 module, developers may be execute the many support functions
about data communication that added in stdio.h library such as printf, puts, getchar,
scanf etc...
Expe rime nt - 4.1 Tra nsmit da ta with UART0/ UART1
In this experiment is demonstration about transmit data from UART0/UART1 module
in LPC2148 by using the serial port interface circuit on the J X-2148.
Proc e dure :
4.1.1 Build new project, in name ua rt_0_1
4.1.2 Write the program Listing P4-2. Compile to ua rt_0_1.he x and download to microcontroller.
4.1.3 Open the Terminal program such as Hyper terminal or RS-232 Terminal to test the
operation. Set baudrate to 9,600 bit per second.
4.1.4 Connect serial port cable from computer RS-232 port to UART CH.0 connector on J X-
2148 board. If have more serial port, connect the serial cable to UART CH.1 connector.
4.1.5 Run the program. Watch the result on the terminal program operation.
Message on the Terminal panel will show message :
Test UART0 If connect between UARTCH.0 with RS-232 serial port
Test UART1 If connect between UARTCH.1 with RS-232 serial port
ON
USB
ON
OFF
+
++.5-9v
JTAGJDEBUG port
PESET
SDJMMC
BLUETOOTH
ESD-02
ST^TUS
R
x
D
T
x
D
R
T
S
C
T
SUART CH.1
LITIUM
BATTERY 3V
+3v B^TT
12NHz
32.768kHz
+3.3v
CND
REF
DEBUG EN.
U
A
R
T

C
H
0
!SP
SW!TCH
0.28 0.29
0.21 0.22
0.30 (^fD)
PSJ2
D^T 0.15
CLK 0.16
PIEZO
0.12-0.13
POPT
1.20
1.21
1.22
1.23
S
P
I
-
0
G0
.
0
+
0
.
0
S
0
.
0
6
0
.
0
7
+
T
W
I
-
0
G0
.
0
2
0
.
0
3
+
LPC21+8
P
O
R
T
P
1
.
1
9
P
1
.
1
8
P
1
.
1
7
P
1
.
1
6
0.25
(Df^)
C
USB
:"&
ARM7-LPC214S
Education board
* 1n as nnI In DIn sraI prI n
sam Im, must connect different port
and open terminal program separate
BuI / nnI nI sam Im, must
connect swap and open the terminal
program only one window.
Connect to
serial port*
Connect to
serial port*
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 37
#ifndef _UART_H_
#define _UART_H_
////
// Program : Library for serial communication(UART)
// Description : Library for serial communication UART0 and UART1 of LPC2148
// Frequency : Crystal 12 MHz at PLL 5x(CCLK = 60 MHz),PCLK = 30 MHz
// Filename : uart.h
// C compiler : CodeSourcery G++ Lite Compiler
////
#define _PCLK 30000000 // Define PCLK for configuration baudrate
#define uart1_setbaud(x) uart1_init(x) // Define function name uart1_setbaud equal uart1_init
#define uart0_setbaud(x) uart0_init(x) // Define function name uart0_setbaud equal
// uart0_init
// Function for Initial UART1 //
void uart1_init(unsigned int _baudrate)
{
unsigned short u1dl;
u1dl = _PCLK/(16*_baudrate); // Calculate for U1DL value
PINSEL0 |= 0x00050000; // Enable rx,tx
U1LCR = 0x00000083; // 8 bit data,1 stop bit,no parity bit
U1DLL = u1dl & 0xFF; // U1DL for low byte
U1DLM = (u1dl>>8); // U1DL for high byte
U1LCR = 0x00000003; // DLAB =0
}
// Function for send character 1 time via UART1//
void uart1_putc(char c)
{
while(!(U1LSR & 0x20)); // Wait until UART1 ready to send character
U1THR = c; // Send character
}
// Function for send string via UART1//
void uart1_puts(char *p)
{
while(*p) // Point to character
{
uart1_putc(*p++); // Send character then point to next character
}
}
// Function for Initial UART0 //
void uart0_init(unsigned int _baudrate)
{
unsigned short u0dl;
u0dl = _PCLK/(16*_baudrate); // Calculate for U0DL value
PINSEL0 |= 0x00000005; // Enable rx,tx
U0LCR = 0x00000083; // 8 bit data,1 stop bit,no parity bit
U0DLL = u0dl & 0xFF; // U0DL for low byte
U0DLM = (u0dl>>8); // U0DL for high byte
U0LCR = 0x00000003; // DLAB =0
}
// Function for send character 1 time via UART0//
void uart0_putc(char c)
{
while(!(U0LSR & 0x20)); // Wait until UART0 ready to send character
U0THR = c; // Send character
}
// Function for send string via UART1//
void uart0_puts(char *p)
{
while(*p) // Point to character
{
uart0_putc(*p++); // Send character then point to next character
}
}
#endif
Listing P4-1 : uart.h The UART library file for LPC21+8
38 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
////
// Program : UART example
// Description: Example for test module UART0 and UART1
// Frequency : Crytal 12 MHz at PLL 5x(CCLK = 60 MHz),PCLK = 30 MHz
// Filename : uart_0_1.c
// C compiler : CodeSourcery G++ Lite Compiler
////
#include lpc214x.h// Header file for Phillips LPC2148 controller
#include uart.h // Library for use module UART0,UART1(from jx2148_include floder)
// Initial system clock //
void init()
{
PLL0CFG=0x24; // MSEL = 4,PSEL = 2
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
PLL0CON=0x1;
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
while(!(PLL0STAT & 0x400)) ; // Wait until PLL Locked
PLL0CON=0x3; // Connect the PLL as the clock source
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
MAMCR=0x2;
// Enabling MAM and setting number of clocks used for Flash memory fetch
// (4 cclks in this case)
MAMTIM=0x4;
VPBDIV=0x02; // PCLK at 30 MHz
}
// Main Program //
int main()
{
init(); // Initialize the system
SCS = 0x03; // select the fast version of the I/O ports
uart0_init(9600);
// Initial UART0 @ 9600 bps,8 bit data ,1 stop bit ,no parity bit
uart1_init(9600);
// Initial UART1 @ 9600 bps,8 bit data ,1 stop bit ,no parity bit
while (1)
{
uart0_puts(Test UART0\r\n); // Send string to UART0
uart1_puts(Test UART1\r\n); // Send string to UART1
}
}
Listing P4-2 : uart_0_1.c file of uart_0_1 project for LPC21+8 UART
experiment
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 39
Figure P4-1 Shows UART0 operation at Hyper Terminal window
Figure P4-2 Shows UART1 operation at Hyper Terminal window
2+"&
40 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
Expe rime nt - 4.2 : UART ope ra tion with inte rrupt
This experiment demonstrates the UART1 operation with interrupt.
Proc e dure :
4.2.1 Build new project, in name ua rt1_int.
4.2.2 Write the program Listing P4-3. Compile to ua rt1_int. he x and download to
microcontroller.
4.2.3 Open the Terminal program such as Hyper terminal or RS-232 Terminal to test the
operation. Set baudrate to 9,600 bit per second.
4.2.4 Connect serial port cable from computer RS-232 port to UARTCH.1 connector.
4.2.5 Run the program.Watch the result on the terminal program operation.
ON
USB
ON
OFF
+
++.5-9v
JTAGJDEBUG port
RESET
SDJMMC
BLUETOOTH
ESD-02
STATUS
R
x
D
T
x
D
R
T
S
C
T
S
UART CH.1
LITIUM
BATTERY 3V
+3v BATT
12NHz
32.768kHz
+3.3v
GND
REF
DEBUG EN.
7
)
4
6

+
0

!SP
SW!TCH
0.28 0.29
0.21 0.22
0.30 (AfD)
PSJ2
DAT 0.15
CLK 0.16
PIEZO
0.12-0.13
PORT
1.20
1.21
1.22
1.23
S
P
I
-
0
G0
.
0
+
0
.
0
5
0
.
0
6
0
.
0
7
+
T
W
I
-
0
G0
.
0
2
0
.
0
3
+
LPC21+8
P
O
R
T
P
1
.
1
9
P
1
.
1
8
P
1
.
1
7
P
1
.
1
6
0.25
(DfA)
G
USB
:"&
ARM7-LPC214S
Education board
Connect to
serial port
The termional window shows message below :
Now test UART1 for echo character
Press any key for test!
Try to press any keyboard button for transmitting that character to LPC2148.
This transmit enable echo function (return character back). Thus, transmitted character
will send back to serial port and appear at the terminal program window.
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 41
////
// Program : UART example
// Description: Example for test UART1 interrupt mode
// Frequency : Crystal 12 MHz at PLL 5x(CCLK = 60 MHz),PCLK = 30 MHz
// Filename: uart_int.c
// C compiler : CodeSourcery G++ Lite Compiler
////
#include lpc214x.h // Header file for Phillips LPC2148 controller
#include uart.h // Library for use module UART0,UART1
// Function for Initial system clock //
void init()
{
PLL0CFG=0x24; // MSEL = 4,PSEL = 2
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
PLL0CON=0x1;
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
while(!(PLL0STAT & 0x400)) ; // Wait until PLL Locked
PLL0CON=0x3; // Connect the PLL as the clock source
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
MAMCR=0x2;
// Enabling MAM and setting number of clocks used for Flash memory fetch
// (4 cclks in this case)
MAMTIM=0x4;
VPBDIV=0x02; // PCLK at 30 MHz
}
// Interrupt service routine for UART1 //
void __attribute__ ((interrupt(IRQ))) isr_uart1(void)
{
char msg;
if(((msg = U1IIR) & 0x01) == 0) // Check status flag communication
{
switch (msg & 0x0E) // Filter message
{
case 0x04: while(!(U1LSR & 0x20)); // Receive Data Available
U1THR = U1RBR; // Echo character
break;
case 0x02: break; // THERE Interrupt
default: break; // Other
}
}
VICVectAddr = 0; // Acknowledge Interrupt
}
// Main Program //
int main()
Listing P4-3 : uart1_int.c file of uart1_int project for LPC21+8 UART
experiment (continue)
42 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
Listing P4-3 : uart1_int.c file of uart1_int project for LPC21+8 UART
experiment with interrupt (final)
Figure P4-3 Shows the UART1 module data communication function with
interrupt
2+"&
{
init(); // Initialize the system
SCS = 0x03; // select the fast version of the I/O ports
uart1_init(9600);
// Initial UART1 @ 9600 bps, 8 bit data, 1 stop bit, no parity bit
U1IER = 3; // Enable rx/tx interrupt for UART1
PINSEL0 |= (1<<18); // Enable RXD1(from UART1) at P0.9
VICVectAddr0 = (unsigned)isr_uart1;
// Register Interrupt service routine name
VICVectCntl0 = 0x20 | 7; // UART1 Interrupt
VICIntEnable = 1 << 7; // Enable UART1 Interrupt
uart1_puts(Now test UART1 for echo character\r\n);
// Display message for test echo character
uart1_puts(Press any key for test!\r\n);
while(1); // Infinite loop
}
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 43
Expe rime nt - 5 : A/ D c onve rte r
, . /_ ._ .. .. . .-c.+s ,
s. /.s , .-s -. .. . .,, ,_ . o/-
Proc e dure :
5.1 Build new project, in name adc.
5.2 Write the program Listing P5-1. Compile to adc.hex and download to
microcontroller.
5.3 Open the Terminal program such as Hyper terminal or RS-232 Terminal to test
the operation. Set baudrate to 9,600 bit per second.
5.4 Connect serial port cable from computer RS-232 port to UARTCH.0 connector.
ON
USB
ON
OFF
+
++.5-9v
JTAGJDEBUG port
RESET
SDJMMC
BLUETOOTH
ESD-02
STATUS
R
x
D
T
x
D
R
T
S
C
T
S
UART CH.1
LITIUM
BATTERY 3V
+3v BATT
12NHz
32.768kHz
+3.3v
GND
REF
DEBUC EN.
U
A
R
T

C
H
0
!SP
SWITCH
0.28 0.29
0.21 0.22
0.30 (AfD)
PSJ2
DAT 0.15
CLK 0.16
PIEZO
0.12-0.13
PORT
1.20
1.21
1.22
1.23
S
P
!
-
0
C0
.
0
+
0
.
0
S
0
.
0
6
0
.
0
7
+
T
W
!
-
0
C0
.
0
2
0
.
0
3
+
LPC21+8
P
O
R
T
P
1
.
1
9
P
1
.
1
8
P
1
.
1
7
P
1
.
1
6
0.25
(DfA)
G
USB
:"&
ARM7-LPC214S
Education board
Adjust analog signal
Connect to
serial port
Press down to Program
Press up to Run
5.5 Run the program.Watch the result on the terminal program operation.
The terminal window shows message below :
Analog(AD0.3): xxx
By xxx is the conversion digital data from A/ D converter module.
44 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
////
// Program : Example Analog to Digital converter
// Description : Display Analog to Digital convert value
// : on terminal program(used UART0 communication)
// Frequency : Crystal 12 MHz at PLL 5x(CCLK = 60 MHz),PCLK = 30 MHz
// Filename : adc.c
// C compiler : CodeSourcery G++ Lite Compiler
////
#include lpc214x.h // Header file for Phillips LPC2148 controller
#include stdio.h // Library for sprintf function
#include uart.h // Library for UART
// Function for Initial system clock //
void init()
{
PLL0CFG=0x24; // MSEL = 4,PSEL = 2
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
PLL0CON=0x1;
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
while(!(PLL0STAT & 0x400)) ; // Wait until PLL Locked
PLL0CON=0x3; // Connect the PLL as the clock source
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
MAMCR=0x2;
// Enabling MAM and setting number of clocks used for Flash memory fetch
//(4 cclks in this case)
MAMTIM=0x4;
VPBDIV=0x02; // PCLK at 30 MHz
}
// Function delay //
void delay_ms(long ms) // delay 1 ms per count
{
long i,j;
for (i = 0; i < ms; i++ )
for (j = 0; j < 4000; j++ );
}
// Main Program //
int main()
{
int val=0;
char s[30]; // Buffer for keep string from integer convert
init(); // Initialize the system
SCS = 0x03; // select the fast version of the I/O ports
uart0_init(9600); // Initial UART0
PINSEL1 |= 0x10000000; // Enable AD0.3 for used
AD0CR = 0x00210608; // Setup A/D: 10-bit AIN0 @ 3MHz
while (1)
{
AD0CR |= 0x01000000; // Start A/D Conversion
while ((AD0DR3 & 0x80000000) == 0); // Wait for the conversion to complete
val = ((AD0DR3 >> 6) & 0x03FF); // Extract the A/D result
sprintf(s,Analog(AD0.3): %d \r,val); // Convert string to display analog value
uart0_puts(s); // Display to Terminal program
delay_ms(200); // Delay for display
}
}
Listing P5-1 : adc.c file of adc project for LPC21+8 AfD converter experiment
(final)
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 45
2+"&
Figure P5-1 Shows the result of AfD converter experiment at the Hyper
terminal window.
46 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
Expe rime nt - 6 : Re a l- time Cloc k in LPC2148
Expe rime nt - 6.1 : RTC inte rrupt
This experiment is demonstration about set the interrupt time for Real-time
clock module within LPC2148. The interrupt will happen 2 cases. The first is interrupt
every 1 second. LED at P0.22 will blink following the interrupt event. The second is
interrupt at every second unit as 3 such as 12:05:03,12:06:03 or 02:48:03 etc.
Proc e dure :
6.1.1 Build new project, in name rtc_int.
6.1.2 Write the program Listing P6-1. Compile to rtc_int.hex and download to
microcontroller.
6.1.3 Open the Terminal program such as Hyper terminal or RS-232 Terminal to test
the operation. Set baudrate to 9,600 bit per second.
6.1.4 Connect serial port cable from computer RS-232 port to UARTCH.1 connector.
ON
USB
ON
OFF
+
++.5-9v
JTAGJDEBUG port
RESET
SDJMMC
BLUETOOTH
ESD-02
STATUS
R
x
D
T
x
D
R
T
S
C
T
S
UART CH.1
LITIUM
BATTERY 3V
+3v BATT
12NHz
32.768kHz
+3.3v
GND
REF
DEBUG EN.
U
A
R
T

C
H
0
!SP
SW!TCH
0.28 0.29
0.21 0.22
0.30 (AfD)
PSJ2
DAT 0.15
CLK 0.16
PIEZO
0.12-0.13
PORT
1.20
1.21
1.22
1.23
S
P
!
-
0
C0
.
0
+
0
.
0
S
0
.
0
6
0
.
0
7
+
T
W
!
-
0
C0
.
0
2
0
.
0
3
+
LPC21+8
P
O
R
T
P
1
.
1
9
P
1
.
1
8
P
1
.
1
7
P
1
.
1
6
0.25
(DfA)
G
USB
:"&
ARM7-LPC214S
Education board
Connect to
serial port
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 47
////
// Program : Example for Real time clock
// Frequency : Crystal 12 MHz at PLL 5x(CCLK = 60 MHz),PCLK = 30 MHz
// Filename : rtc.c
// C compiler : CodeSourcery G++ Lite Compiler
////
#include lpc214x.h // Header file for Phillips LPC2148 controller
#include sound.h // Header file for Phillips LPC2148 controller
#include stdio.h // Library for use puts function(For UART1)
#include uart.h // Library for use module UART0,UART1
#define LED1_ON FIO0CLR = 0x00400000 // Red led 0.22 on
#define LED1_OFF FIO0SET = 0x00400000 // Red led 0.22 off
char alarm = 0; // Variable for status sound alarm
// Function for Initial system clock //
void init()
{
PLL0CFG=0x24; // MSEL = 4,PSEL = 2
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
PLL0CON=0x1;
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
while(!(PLL0STAT & 0x400)) ; // Wait until PLL Locked
PLL0CON=0x3; // Connect the PLL as the clock source
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
MAMCR=0x2;
// Enabling MAM and setting number of clocks used for Flash memory fetch
// (4 cclks in this case)
MAMTIM=0x4;
VPBDIV=0x02; // PCLK at 30 MHz
}
// Function delay //
void delay_ms(long ms) // delay 1 ms per count @ CCLK 60 MHz
{
long i,j;
for (i = 0; i < ms; i++ )
for (j = 0; j < 4000; j++ );
}
// Interrupt service routine for UART1 //
void __attribute__ ((interrupt(IRQ))) isr_rtc(void)
{
if(ILR & 0x01) // Check Interrupt block generate
{
LED1_ON; // LED on
delay_ms(100); // Delay for Blink LED
LED1_OFF; // LED off
ILR = 0x01; // Clear interrupt flag
}
if(ILR & 0x02)
{
alarm = 1; // Set flag alarm for generate sound beep
ILR = 0x02; // Clear interrupt flag
}
VICVectAddr = 0; // Acknowledge Interrupt
}
Listing P6-1 : rtc_int.c file of rtc_int project for LPC21+8 RTC
experiment (continuous)
48 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
Listing P6-1 : rtc_int.c file of rtc_int project for LPC21+8 RTC
experiment (final)
// Main Program //
int main()
{
char i=0;
char str[40];
init(); // Initialize the system
SCS = 0x03; // select the fast version of the I/O ports
FIO0DIR |= 0x00400000; // Config. pin P0.22 as output
uart1_init(9600);
PREINT = 0x00000392; // Set RTC Prescaler for PCLK 30 MHz
PREFRAC = 0x00004380;
CIIR = 0x00000001; // Enable seconds counter interrupt
ALSEC = 0x00000003; // Set alarm register for 3 seconds
// (match when xx:xx:03)
AMR = 0x000000FE; // Enable seconds alarm
CCR = 0x00000001; // Start RTC
VICVectAddr13 = (unsigned)isr_rtc;
VICVectCntl13 = 0x20 | 13;
VICIntEnable |= (1<<13); // Enable RTC Interrupt
while (1) // Infinite loop
{
if(alarm==1) // Check seconds alarm match
{
beep(); // Sound beep 1 time
i++; // Increment counter for sound
if(i>10) // Over 10 time?
{
i=0; // Clear counter
alarm = 0; // Clear alarm flag
}
}
sprintf(str,TIME: %d:%d:%d \r ,HOUR,MIN,SEC);
// Convert time format hh:mm:ss
uart1_puts(str); // Display time
delay_ms(100); // Delay for display
}
}
More information about important function in this program
The suitable value for PREINT and PREFRAC register in LPC2148s RTC module
can calculate from
PREINT = int(PCLK / 32768) - 1 .....................................(Eq. P6-1)
PREFRAC = PCLK - ((PREINT + 1) x 32768).....................(Eq. P6-2)
From Eq. P6-1
PREINT value = int (30000000 / 32768) - 1 = 914 or 0x392
From Eq. P6-2
PREFRAC value = 30000000 - ((914 + 1) x 32768) = 17280 or 0x4380
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 49
6.1.5 Run program. Watch the result on the terminal program and LED at P0.22
operation.
The terminal window shows message below :
TIME: hh:mm:ss
by hh is time in hour unit., mm is time in minute unit and ss is second.
LED at P0.22 will blink in rate 1 second. This operation is defined from
the interrupt first case.
In every second at number 3, piezo will drive beep signal 10 times
continuous. This operation is defined from the interrupt second case.
Howe ve r the op e ra tion of this e xp e rim e nt RTC m od ule c a nnot op e ra te
c ontinuous without sup p ly volta g e . Because the program set to RTC clock use
same souce clock of CPU (CLKSRC bit in CCR register is 0 ). RTC module will operate
when apply supply voltage to CPU only.
In nthe next experiment will shows the solution of this limitation.
50 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
////
// Program : Example for Real time clock
// Description : Example for display via Terminal program time format hh:mm:ss
// : and user can setup new time by press key * on keyboard
// Frequency : Crystal 12 MHz at PLL 5x(CCLK = 60 MHz),PCLK = 30 MHz
// Filename : rtc_setup.c
// C compiler : CodeSourcery G++ Lite Compiler
////
#include lpc214x.h // Header file for Phillips LPC2148 controller
#include stdio.h // Library for use puts function(For UART1)
#include uart.h // Library for use module UART0,UART1
#include ctype.h // Library for isdigit function
#include stdlib.h // Library for atoi function
char key = 0; // Variable for status sound alarm
// Function for Initial system clock //
void init()
{
PLL0CFG=0x24; // MSEL = 4,PSEL = 2
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
PLL0CON=0x1;
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
while(!(PLL0STAT & 0x400)) ; // Wait until PLL Locked
PLL0CON=0x3; // Connect the PLL as the clock source
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
MAMCR=0x2;
// Enabling MAM and setting number of clocks used for Flash memory fetch
// (4 cclks in this case)
MAMTIM=0x4;
VPBDIV=0x02; // PCLK at 30 MHz
}
Expe rime nt - 6.2 : Se tting time to RTC.
This experiment will demonstrate the setting time value to RTC module. It is
writing the value to 3 time registers includes HOUR, MIN and SEC. Input all values
with keyboard pass Terminal program via UART1 module.
Proc e dure :
6.2.1 Build new project, in name rtc_setup.
6.2.2 Write the program Listing P6-2. Compile to rtc_setup.hex and download to
microcontroller. Close LPC2000 Flash Utility program.
Listing P6-2 : rtc_setup.c file of rtc_setup project for LPC21+8 RTC
experiment (continuous)
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 51
Listing P6-2 : rtc_setup.c file of rtc_setup project for LPC21+8 RTC
experiment (continuous)
// Function delay //
void delay_ms(long ms) // delay 1 ms per count @ CCLK 60 MHz
{
long i,j;
for (i = 0; i < ms; i++ )
for (j = 0; j < 4000; j++ );
}
// Interrupt service routine for UART1 //
void __attribute__ ((interrupt(IRQ))) isr_uart1(void)
{
char msg;
if(((msg = U1IIR) & 0x01) == 0) // Check status flag communication
{
switch (msg & 0x0E) // Filter message
{
case 0x04: while(!(U1LSR & 0x20)); // Receive Data Available
key = U1RBR;
break;
case 0x02: break; // THRE Interrupt
default: break; // Other
}
}
VICVectAddr = 0; // Acknowledge Interrupt
}
// Function for setup date/time for Real time clock //
void rtc_uart1_setup( char *s)
{
unsigned char tm; // Buffer for keep date/time setup value
char i=0; // Variable for loop counter
for(i=0;i<2;i++) // Loop for keep value 2 byte
{
while(!isdigit(key)); // Wait for key 0-9' only
if(i==0)
tm = 10*atoi(&key); // Keep 1 value
if(i==1)
tm = tm+atoi(&key); // Keep 2 value
uart1_putc(key); // Display key on Terminal program
key = 0; // Clear old key for next key
}
*s = tm; // Load setup new value
}
// Main Program //
int main()
{
char str[40];
init(); // Initialize the system
SCS = 0x03; // select the fast version of the I/O ports
uart1_init(9600);
// Initial UART1 @ 9600 bps,8 bit data ,1 stop bit ,no parity bit
U1IER = 3; // Enable rx/tx interrupt for UART1
PINSEL0 |= (1<<18); // Enable RXD1(from UART1) at P0.9
VICVectAddr0 = (unsigned)isr_uart1;
// Register Interrupt service routine name
VICVectCntl0 = 0x20 | 7; // UART1 Interrupt
VICIntEnable |= 1 << 7; // Enable UART1 Interrupt
52 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
Listing P6-2 : rtc_setup.c file of rtc_setup project for LPC21+8 RTC
experiment (final)
CCR = 0x00000011;
// Start RTC used 32.768 kHz crystal for RTCX1/RTCX2 pin
while (1) // Infinite loop
{
sprintf(str,TIME: %d:%d:%d \r ,HOUR,MIN,SEC);
uart1_puts(str);
delay_ms(100); // Delay for display
if(key==*) // Check key for setup time?
{
key = 0; // Clear old key for next key
uart1_puts(\nSet Time:);
rtc_uart1_setup(&HOUR); // Wait until new value of HOUR
uart1_putc(:); // Display : at terminal program
rtc_uart1_setup(&MIN); // Wait until user insert new value of MIN
uart1_putc(:); // Display : at terminal program
rtc_uart1_setup(&SEC); // Wait until user insert new value of SEC
sprintf(str,\r\nTIME: %d:%d:%d \r ,HOUR,MIN,SEC);
uart1_puts(str);
}
}
}
6.2.3 Open the Terminal program such as Hyper terminal or RS-232 Terminal to test the
operation. Set baudrate to 9,600 bit per second.
6.2. 4 Connect serial port cable from computer RS-232 port to UARTCH.1 connector.
6.2.5 Run program. Watch the result on the terminal program.
The terminal window shows message below :
TIME: hh:mm:ss
by hh is time in hour unit., mm is time in minute unit and ss is second.
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 53
2+"&
6.2.6 Press * key for setting time to RTC module. Watch the result on the terminal program.
The new message will appear in the next line :
Set Time:
Wait for data 6 digits. They mean time value in hh,mm and ss. Input the value
complete 6 digits. The time value will store in the time registers of RTC module. The terminal
will shows the setting time and run continue.
The ope ra tion of this e xpe rime nt RTC module c a n ope ra te c ontinuous without
supply volta ge . Because RTC receive the clock from 32kHz clock oscillator separate CPU
clokc. CLKSRC bit in CCR register set to 1. The time value can store with +3V supply from
litium battery on-board.
54 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
Expe rime nt - 7 : PS/ 2 Ke yboa rd inte rfa c e
This experiment is demonstration about interfacing PS/2 keyboard with LPC2148.
The heart of this operaion is ke yboa rd.h library file. LPC2148 will get the key value and
display at the terminal program via UART1.
ke yboa rd.h libra ry for PS/ 2 ke yboa rd inte rfa c ing
The full source program of this library file is shown in Listing P7-1. The description of
each function in this library file as :
kb_init
Initialize keyboard clokc pin. In this experiment is EINT0 or P0.16
syntax :
void kb_init()
kb_getchar
Get the pressed key character that this library support.
syntax :
char kb_getchar()
return :
Keyboard code or Key value
PS/ 2 ke yboa rd inte rfa c e
Keyboard detection of keyboard.h library will detect raising edge interrupt signal
at EINT0 or P0.16 pin. This pin will connect to Clock signal of keyboard. If key pressed,
status of this pin will down to zero immediately. That is start bit. The figure P7-1 shows the
timing diagram of keyboard data bit and clock signal.
To start using this library, must execute kb_init function in the top of program for
setting interrupt operation of EINT0. The function isr_int0 is interrupt service. It is set the first
priority (slot 0) After key pressed, program will jump to this service routien isr_int0.
,)6) ,)6) ,)6) ,)6)! ,)6)" ,)6)# ,)6)$ ,)6)%
+?
,=J=
56)46 2)416; 562
Figure P7-1 PSf2 keyboard signal timing diagram
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 55
////
// Program : Library for PS/2 Keyboard
// Description: Detect for input key from PS/2 keyboard
// Frequency : Crystal 12 MHz at PLL 5x(CCLK = 60 MHz),PCLK = 30 MHz
// Filename : keybord.h
// C compiler : Keil CARM Compiler
////
#include stdio.h // Library for use puts function(For UART1)
#include ctype.h // Library for use toupper function
#define LOWER 0 // Macro for lower case keyboard
#define UPPER 1 // Macro for upper case keyboard
#define CAPS_LOCK_CODE 0x58 // Macro for Caps Lock scan code
unsigned int _code=0; // Variable for keep scan code
char char_case =LOWER; // Variable for status character case(lower or upper)
const unsigned char _ascii_key[128] = // Table for decode
{
0 // 0x00
, 0 // 0x01
, 0 // 0x02
, 0 // 0x03
, 0 // 0x04
, 0 // 0x05
, 0 // 0x06
, 0 // 0x07
, 0 // 0x08
, 0 // 0x09
, 0 // 0x0A
, 0 // 0x0B
, 0 // 0x0C
, 11 // 0x0D
, 0 // 0x0E
, 0 // 0x0F
, 0 // 0x10
, 0 // 0x11
, 0 // 0x12
, 0 // 0x13
, 0 // 0x14
, q // 0x15
, ! // 0x16
, 0 // 0x17
, 0 // 0x18
, 0 // 0x19
, z // 0x1A
, s // 0x1B
, a // 0x1C
, w // 0x1D
, @ // 0x1E
, 0 // 0x1F
, 0 // 0x20
, c // 0x21
, x // 0x22
, d // 0x23
, e // 0x24
, $ // 0x25
, # // 0x26
, 0 // 0x27
, 0 // 0x28
Listing P7-1 Source program of keyboard.h library file (continue)
56 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
Listing P7-1 Source program of keyboard.h library file (continue)
, 32 // 0x29
, v // 0x2A
, f // 0x2B
, t // 0x2C
, r // 0x2D
, % // 0x2E
, 0 // 0x2F
, 0 // 0x30
, n // 0x31
, b // 0x32
, h // 0x33
, g // 0x34
, y // 0x35
, ^ // 0x36
, 0 // 0x37
, 0 // 0x38
, 0 // 0x39
, m // 0x3A
, j // 0x3B
, u // 0x3C
, & // 0x3D
, * // 0x3E
, 0 // 0x3F
, 0 // 0x40
, 44 // 0x41
, k // 0x42
, i // 0x43
, o // 0x44
, ) // 0x45
, ( // 0x46
, 0 // 0x47
, 0 // 0x48
, . // 0x49
, / // 0x4A
, l // 0x4B
, ; // 0x4C
, p // 0x4D
, - // 0x4E
, 0 // 0x4F
, 0 // 0x50
, 0 // 0x51
, 39 // 0x52
, 0 // 0x53
, 0 // 0x54
, = // 0x55
, 0 // 0x56
, 0 // 0x57
, 0 // 0x58
, 0 // 0x59
, 13 // 0x5A
, ] // 0x5B
, 0 // 0x5C
, 92 // 0x5D
, 0 // 0x5E
, 0 // 0x5F
, 0 // 0x60
, 0 // 0x61
, 0 // 0x62
, 0 // 0x63
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 57
, 0 // 0x64
, 0 // 0x65
, 8 // 0x66
, 0 // 0x67
, 0 // 0x68
, 1 // 0x69
, 0 // 0x6A
, 4 // 0x6B
, 7 // 0x6C
, 0 // 0x6D
, 0 // 0x6E
, 0 // 0x6F
, 0 // 0x70
, . // 0x71
, 2 // 0x72
, 5 // 0x73
, 6 // 0x74
, 8 // 0x75
, 27 // 0x76
, 0 // 0x77
, 0 // 0x78
, + // 0x79
, 3 // 0x7A
, - // 0x7B
, * // 0x7C
, 9 // 0x7D
, 0 // 0x7E
, 0 // 0x7F
};
// Function Check input P0 //
char _inp0(char _bit)
{
unsigned long c;
c = 1<<_bit; // Calculate digit to configuration for input port
return((FIO0PIN & c)>>_bit); // Read and return data bit
}
// Function get character from keyboard //
char kb_getchar()
{
static unsigned char temp=0
,bk=0;
unsigned char result;
while(_code == 0); // Wait for key code support only
temp = _code; // Keep code detect
if(bk==2) // Not keep code for 0xF0,0xE0,0xE1 sequent
{
bk =0;
}
if(bk==1) // Not keep code for 0xF0,0xE0,0xE1 sequent
{
bk =2;
}
if(_code==0xF0 || _code==0xE0) // Check break code and none key support
{
bk=1; // Start break code sequent
}
_code = 0; // Clear old code
Listing P7-1 Source program of keyboard.h library file (continue)
58 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
if((temp !=0xF0 || temp !=0xE0 || temp !=0xE1) && bk==0)
// Check code support?
{
if(temp == CAPS_LOCK_CODE) // Check Caps Lock mode key push?
{
char_case ^=1; // Toggle status Caps Lock mode
}
if(char_case==UPPER) // Check Upper case for character A-Z
result = toupper(_ascii_key[temp]); // Result A-Z
else
result = _ascii_key[temp]; // Result a-z
return(result); // Return result
}
else
return(0);
}
// Interrupt service routine for EINT0 //
void isr_int0(void) __irq
{
unsigned char i; // Define for counter loop
if(_inp0(16)==0) // Check start bit true?
{
while(_inp0(16)==0); // wait for 1 after start bit
for(i=0;i<10;i++) // For loop count 10 time(for receive data 8 bit)
{
while(_inp0(16)==1); // wait for 0 after data bit
_code = _code>>1; // Shift data bit to right 1 time
if(_inp0(15))
_code = _code | 0x8000; // Config data bit = 1
while(_inp0(16)==0); // wait for 1 after data bit
}
while(_inp0(16)==0); // wait for 1 after stop bit
_code = _code>>6;
_code &= 0x00FF;
}
EXTINT |= 0x1; // Clear interrupt flag EINT0
VICVectAddr = 0; // Acknowledge Interrupt
}
// Function initial PS/2 keyboard //
void kb_init()
{
FIO0DIR &= ~(1<<15); // Config. output P0.15 DATA pin for keyboard
FIO0DIR &= ~(1<<16); // Config. output P0.16 DATA pin for keyboard
EXTMODE |= 0x1; // EINT0 Edge sensitive detection(Falling edge)
PINSEL1 |= 0x01; // Enable EINT0 at P0.16
VICVectAddr0 = (unsigned)isr_int0;
// Register Interrupt service routine name
VICVectCntl0 |= (0x20 | 14); // EINT0 Interrupt
VICIntEnable |= 1 << 14; // Enable EINT0 Interrupt
}
Listing P7-1 Source program of keyboard.h library file (final)
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 59
AO
2HAIIA@
AO @=J=
4AA=IA@
AO @=J=
A 1C F0, 1C
B 32 F0, 32
C 21 F0, 21
D 23 F0, 23
E 2+ F0, 2+
F 2B F0, 2B
C 3+ F0, 3+
H 33 F0, 33
I +3 F0, +3
J 3B F0, 3B
K +2 F0, +2
L +B F0, +B
M 3A F0, 3A
N 31 F0, 31
O ++ F0, ++
P +D F0, +D
Q 1S F0, 1S
R 2D F0, 2D
S 1B F0, 1B
T 2C F0, 2C
U 3C F0, 3C
v 2A F0, 2A
W 1D F0, 1D
X 22 F0, 22
Y 3S F0, 3S
Z 1A F0, 1A
0 +S F0, +S
1 16 F0, 16
2 1E F0, 1E
3 26 F0, 26
+ 2S F0, 2S
S 2E F0, 2E
6 36 F0, 36
7 3D F0, 3D
8 3E F0, 3E
9 +6 F0, +6
AO
2HAIIA@
AO @=J=
4AA=IA@
AO @=J=
' 0E F0, 1C
- +E F0, 1C
= SS F0, 1C
\ SD F0, 1C
BKSP 66 F0, 1C
Space 29 F0, 1C
Tab 0D F0, 1C
Caps S8 F0, 1C
L Shift 12 F0, 1C
L Ctrl 1+ F0, 1C
L CUI E0, 1F F0, 1C
L Alt 11 F0, 1C
S9 F0, 1C
E0, 1+ F0, 1C
E0, 27 F0, 1C
E0, 11 F0, 1C
Apps E0, 2F F0, 1C
Enter SA F0, 1C
ESC 76 F0, 1C
F1 0S F0, 1C
F2 06 F0, 1C
F3 0+ F0, 1C
F+ 0C F0, 1C
FS 03 F0, 1C
F6 0B F0, 1C
F7 83 F0, 1C
F8 0A F0, 1C
F9 01 F0, 1C
F10 09 F0, 1C
F11 78 F0, 1C
F12 07 F0, 1C
PrtScn - - %+ F0, 1C
Scroll 7E F0, 1C
Pause
-"%%-
.".%%
F0, 1C
[ S+ F0, 1C
Insert E0, 70 F0, 1C
R Shift
R Ctrl
R CUI
R Alt
AO
2HAIIA@
AO @=J=
4AA=IA@
AO @=J=
Home E0, 6C F0, 1C
Page Up E0, 7D F0, 1C
Delete E0, 71 F0, 1C
End E0, 69 F0, 1C
Page Dwn E0, 7A F0, 1C
E0, 7S F0, 1C
E0, 6B F0, 1C
E0, 72 F0, 1C
E0, 7+ F0, 1C
NUM 77 F0, 1C
KP f E0, +A F0, 1C
KP * 7C F0, 1C
7B F0, 1C
79 F0, 1C
E0, SA F0, 1C
71 F0, 1C
KP 0 70 F0, 1C
KP 1 69 F0, 1C
KP 2 72 F0, 1C
KP 3 7A F0, 1C
KP + 6B F0, 1C
KP S 73 F0, 1C
KP 6 7+ F0, 1C
KP 7 6C F0, 1C
KP 8 7S F0, 1C
KP 9 7D F0, 1C
] SB F0, 1C
, +C F0, 1C
' S2 F0, 1C
, +1 F0, 1C
. +9 F0, 1C
f +A F0, 1C
KP -
KP +
KP EN
KP .

Table P7-1 Keyboard data of PSf2 keyboard


60 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
Operation of isr_int0 function is filter 8-bit data to store in _c ode variable and convert
to ASCII code by look-up table refer Table P7-1. In one key pressed, the data will appear 2
values. One is pressed key data, another is released key data. For examplr, S key is pressed.
Data will be 0x1B. After release, the data will change to 0xF0.
Key detection is operation of kb _g e tc ha r function. If detect key pressed, this
function will return key value (in condition, that key must support by ke yboa rd.h library).
Internal operation of kb_ge tc ha r function will look over both pressed and releasaed key
data (0xE0 and 0xF0). After that bring the key value to look up table for getting ASCII data
and return final data.
Addition about Caps Lock support, swap character format about lower case and
upper case letter. The kb_ge tc ha r function will return key a as a (0x61). If Caps Lock key
pressed and press key a again. this function will return ASCII of A (0x41) instead but not
turn on LED Caps Lock at keyboard.
Proc e dure :
7.1 Build new project, in name ke yboa rd_ps2.
7.2 Write the program Listing P7-2. Compile to ke yb oa rd _p s2.he x and download to
microcontroller. Close LPC2000 Flash Utility program.
7.3 Open the Terminal program such as Hyper terminal or RS-232 Terminal to test the
operation. Set baudrate to 9,600 bit per second.
7. 4 Connect serial port cable from computer RS-232 port to UARTCH.1 connector.
7.5 Connect PS/2 keyboard at PS/2 connecotr on J X-2148 board.
ON
USB
ON
OFF
+
++.5-9v
JTAGJDEBUG port
RESET
SDJMMC
BLUETOOTH
ESD-02
STATUS
R
x
D
T
x
D
R
T
S
C
T
SUART CH.1
LITIUM
BATTERY 3V
+3v BATT
12NHz
32.768kHz
+3.3v
GND
REF
DEBUC EN.
7
)
4
6

+
0

!SP
SWITCH
0.28 0.29
0.21 0.22
0.30 (AfD)
PSJ2
DAT 0.15
CLK 0.16
PIEZO
0.12-0.13
PORT
1.20
1.21
1.22
1.23
S
P
!
-
0
C0
.0
+
0
.0
S
0
.0
6
0
.0
7
+
T
W
!
-
0
C0
.0
2
0
.0
3
+
LPC21+8
P
O
R
T
P
1
.1
9
P
1
.1
8
P
1
.1
7
P
1
.1
6
0.25
(DfA)
G
USB
:"&
ARM7-LPC214S
Education board
Connect to RS-232 serial port
Connect to PSf2 keyboard
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 61
//-//
// Program : Example for decode form PS/2 keyboard
// Description : Get character from PS/2 keyboard
// : and display at terminal program
// : used UART1 communication
// Frequency : Crystal 12 MHz at PLL 5x(CCLK = 60 MHz),PCLK = 30 MHz
// Filename : keyboard_ps2.c
// C compiler : CodeSourcery G++ Lite Compiler
//-//
#include lpc214x.h // Header file for Phillips LPC2148 controller
#include uart.h // Library for use module UART0,UART1
#include keyboard.h // Library for use PS/2 keyboard
// Function for Initial system clock //
void init()
{
PLL0CFG=0x24; // MSEL = 4,PSEL = 2
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
PLL0CON=0x1;
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
while(!(PLL0STAT & 0x400)) ; // Wait until PLL Locked
PLL0CON=0x3; // Connect the PLL as the clock source
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
MAMCR=0x2;
// Enabling MAM and setting number of clocks used for Flash memory fetch
// (4 cclks in this case)
MAMTIM=0x4;
VPBDIV=0x02; // PCLK at 30 MHz
}
// Main Program //
int main()
{
char dat;
init(); // Initialize the system
SCS = 0x03; // select the fast version of the I/O ports
kb_init(); // Initial for used PS/2 keyboard
uart1_init(9600);
// Initial UART1 @ 9600 bps,8 bit data ,1 stop bit ,no parity bit
while(1) // Infinite loop
{
dat = kb_getchar(); // Get character from keyboard
uart1_putc(dat); // Display at terminal program
}
}
Listing P7-1 : keyboard_ps2.c file of keyboard_ps2 project for LPC21+8
RTC experiment
62 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
7.6 Run program. Try to type any key on keyboard and watch the result on the terminal
program. After that press Caps Lock key and re-type keyboard again. See the different
result.
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 63
Expe rime nt - 8 : Gra phic LCD inte rfa c e
This experiment is demonstration about interfacing GLCD5110 Graphic LCD.PS/2
keyboard with LPC2148.
GLCD5110 : Gra phic LCD 84x48 pixe l
fe a ture s
Graphic LCD module #LPH7366. Resolution is 84 x 48 pixel.
Built-in PCD8544 controller with SPI interface bus.
Built-in the backlight blue LED controlled by software
Supply voltage range is +3 to +3.3V. Maximum current is 10mA (with backlight
LED)
Display the standard size 5x7 pixel character up to 14 characters 6 lines and
mono-tone graphic image.
Size is 4.5 x 4.5 cm.
Easy to connection
Interface with any popular microcontroller.
- If interface with +3V logic system, user can connect GLCD with microcontroller
port directly.
- If interface with +5V system, user must connect through the attenuator circuit
for redeuce the logic level from +5V to +3 or +3.3V or not over the supply voltage of
GLCD5110.
The figure P8-1 shows size and pin assignment of GLCD5110.
The figure P8-2 shows the interfacing circuit with the microcontroller.
GLCD5110 libra ry file
We provide the library of C programming for LPC2148 microcontroller; glcd5110.h.
It is shown in Listing P8-1. The hardware connection is configed as follows :
G LC D5110 LPC2148 port
SDIN P0.06
SCLK P0.07
SCE P1.20
RESET P0.04
D/C P0.05
LED P1.21
64 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
Figure PS-1 Size and Pin assignment of CLCDS110 module
+Smm.
39mm.
+Smm.
39mm.
1
1
2E =A .K?JE
1 vcc Supply voltage +2.7 to +3.3v
2 CND Cround
3 SCE Enable pin - active low
+ RESET Reset pin - active low
S DfC
DatafCommand selection pin
U - WrI aIa spIa)
J - WrI mman
6 SDIN Serial data input pin
7 SCLK Clock input pin
8 LED
Backlight LED control pin
- active high
(inclued limit current resistor 330)
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 65
Figure PS-2 How to interface CLCDS110 with microcontroller
l
l
+3.3V
C
N
D
S
C
E
R
E
S
E
T
D
f
C
S
D
I
N
S
C
L
K
LED
SCK
SDO[MOSI
OUTPUT port
OUTPUT port
OUTPUT port
OUTPUT port
66 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
//
/*
Hardware Configuration
GLCD5110 | JX-2148
___________________
(1)VCC | VCC
(2)GND | GND
(3)SCE | P1.20
(4)RESET | P0.04
(5)D/C | P0.05
(6)SDIN | P0.06
(7)SCK | P0.07
(8)LED | P1.21
*/
//
#include lpc214x.h // Header file for Phillips LPC2148 controller
#include in_out.h
#ifndef _GLCD_H_
#define _GLCD_H_
#include stdio.h
#ifndef NULL
#define NULL 0
#endif
#define FALSE 0
#define TRUE 1
#define LCD_X_RES 84
#define LCD_Y_RES 48
#define LCD_CACHE_SIZE ((LCD_X_RES * LCD_Y_RES) / 8)
unsigned char glcd_ini=0;
/* Type definitions */
typedef char bool;
typedef unsigned char byte;
typedef unsigned int word;
typedef enum
{
LCD_CMD = 0,
LCD_DATA = 1
} LcdCmdData;
typedef enum
{
PIXEL_OFF = 0,
PIXEL_ON = 1,
PIXEL_XOR = 2
}lcdPixelMode;
/* Public function prototypes */
void lcdInit(void);
void lcdClear(void);
void lcdUpdate(void);
void lcdGotoXY(byte x,byte y);
Listing PS-1 Source program of glcdS110.h library file (continue)
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 67
Listing PS-1 Source program of glcdS110.h library file (continue)
void lcdChar(byte ch);
void lcdString(byte _x,byte _y,byte *dataPtr);
void lcdPixel(byte x, byte y, lcdPixelMode mode);
void lcdLine(byte x1, byte y1, byte x2, byte y2, lcdPixelMode mode);
void configGlcd();
void lcdBackLight(char set);
/*Private function prototypes*/
// Function prototypes are mandatory otherwise the compiler generates unreliable code.
static void lcdSend(byte data, LcdCmdData cd);
void delay_ms(long ms);
/*
Character generator
This table defines the standard ASCII characters in a 5x7 dot format.
*/
static const byte FontLookup [][5] =
{
{ 0x00, 0x00, 0x00, 0x00, 0x00 }, // sp
{ 0x00, 0x00, 0x2f, 0x00, 0x00 }, // !
{ 0x00, 0x07, 0x00, 0x07, 0x00 }, //
{ 0x14, 0x7f, 0x14, 0x7f, 0x14 }, // #
{ 0x24, 0x2a, 0x7f, 0x2a, 0x12 }, // $
{ 0x23, 0x13, 0x08, 0x64, 0x62 }, // %
{ 0x36, 0x49, 0x55, 0x22, 0x50 }, // &
{ 0x00, 0x05, 0x03, 0x00, 0x00 }, //
{ 0x00, 0x1c, 0x22, 0x41, 0x00 }, // (
{ 0x00, 0x41, 0x22, 0x1c, 0x00 }, // )
{ 0x14, 0x08, 0x3E, 0x08, 0x14 }, // *
{ 0x08, 0x08, 0x3E, 0x08, 0x08 }, // +
{ 0x00, 0x00, 0x50, 0x30, 0x00 }, // ,
{ 0x10, 0x10, 0x10, 0x10, 0x10 }, // -
{ 0x00, 0x60, 0x60, 0x00, 0x00 }, // .
{ 0x20, 0x10, 0x08, 0x04, 0x02 }, // /
{ 0x3E, 0x51, 0x49, 0x45, 0x3E }, // 0
{ 0x00, 0x42, 0x7F, 0x40, 0x00 }, // 1
{ 0x42, 0x61, 0x51, 0x49, 0x46 }, // 2
{ 0x21, 0x41, 0x45, 0x4B, 0x31 }, // 3
{ 0x18, 0x14, 0x12, 0x7F, 0x10 }, // 4
{ 0x27, 0x45, 0x45, 0x45, 0x39 }, // 5
{ 0x3C, 0x4A, 0x49, 0x49, 0x30 }, // 6
{ 0x01, 0x71, 0x09, 0x05, 0x03 }, // 7
{ 0x36, 0x49, 0x49, 0x49, 0x36 }, // 8
{ 0x06, 0x49, 0x49, 0x29, 0x1E }, // 9
{ 0x00, 0x36, 0x36, 0x00, 0x00 }, // :
{ 0x00, 0x56, 0x36, 0x00, 0x00 }, // ;
{ 0x08, 0x14, 0x22, 0x41, 0x00 }, // <
{ 0x14, 0x14, 0x14, 0x14, 0x14 }, // =
{ 0x00, 0x41, 0x22, 0x14, 0x08 }, // >
{ 0x02, 0x01, 0x51, 0x09, 0x06 }, // ?
{ 0x32, 0x49, 0x59, 0x51, 0x3E }, // @
{ 0x7E, 0x11, 0x11, 0x11, 0x7E }, // A
{ 0x7F, 0x49, 0x49, 0x49, 0x36 }, // B
{ 0x3E, 0x41, 0x41, 0x41, 0x22 }, // C
{ 0x7F, 0x41, 0x41, 0x22, 0x1C }, // D
{ 0x7F, 0x49, 0x49, 0x49, 0x41 }, // E
{ 0x7F, 0x09, 0x09, 0x09, 0x01 }, // F
{ 0x3E, 0x41, 0x49, 0x49, 0x7A }, // G
{ 0x7F, 0x08, 0x08, 0x08, 0x7F }, // H
{ 0x00, 0x41, 0x7F, 0x41, 0x00 }, // I
{ 0x20, 0x40, 0x41, 0x3F, 0x01 }, // J
{ 0x7F, 0x08, 0x14, 0x22, 0x41 }, // K
{ 0x7F, 0x40, 0x40, 0x40, 0x40 }, // L
68 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
Listing PS-1 Source program of glcdS110.h library file (continue)
{ 0x7F, 0x02, 0x0C, 0x02, 0x7F }, // M
{ 0x7F, 0x04, 0x08, 0x10, 0x7F }, // N
{ 0x3E, 0x41, 0x41, 0x41, 0x3E }, // O
{ 0x7F, 0x09, 0x09, 0x09, 0x06 }, // P
{ 0x3E, 0x41, 0x51, 0x21, 0x5E }, // Q
{ 0x7F, 0x09, 0x19, 0x29, 0x46 }, // R
{ 0x46, 0x49, 0x49, 0x49, 0x31 }, // S
{ 0x01, 0x01, 0x7F, 0x01, 0x01 }, // T
{ 0x3F, 0x40, 0x40, 0x40, 0x3F }, // U
{ 0x1F, 0x20, 0x40, 0x20, 0x1F }, // V
{ 0x3F, 0x40, 0x38, 0x40, 0x3F }, // W
{ 0x63, 0x14, 0x08, 0x14, 0x63 }, // X
{ 0x07, 0x08, 0x70, 0x08, 0x07 }, // Y
{ 0x61, 0x51, 0x49, 0x45, 0x43 }, // Z
{ 0x00, 0x7F, 0x41, 0x41, 0x00 }, // [
{ 0x55, 0x2A, 0x55, 0x2A, 0x55 }, // 55
{ 0x00, 0x41, 0x41, 0x7F, 0x00 }, // ]
{ 0x04, 0x02, 0x01, 0x02, 0x04 }, // ^
{ 0x40, 0x40, 0x40, 0x40, 0x40 }, // _
{ 0x00, 0x01, 0x02, 0x04, 0x00 }, //
{ 0x20, 0x54, 0x54, 0x54, 0x78 }, // a
{ 0x7F, 0x48, 0x44, 0x44, 0x38 }, // b
{ 0x38, 0x44, 0x44, 0x44, 0x20 }, // c
{ 0x38, 0x44, 0x44, 0x48, 0x7F }, // d
{ 0x38, 0x54, 0x54, 0x54, 0x18 }, // e
{ 0x08, 0x7E, 0x09, 0x01, 0x02 }, // f
{ 0x0C, 0x52, 0x52, 0x52, 0x3E }, // g
{ 0x7F, 0x08, 0x04, 0x04, 0x78 }, // h
{ 0x00, 0x44, 0x7D, 0x40, 0x00 }, // i
{ 0x20, 0x40, 0x44, 0x3D, 0x00 }, // j
{ 0x7F, 0x10, 0x28, 0x44, 0x00 }, // k
{ 0x00, 0x41, 0x7F, 0x40, 0x00 }, // l
{ 0x7C, 0x04, 0x18, 0x04, 0x78 }, // m
{ 0x7C, 0x08, 0x04, 0x04, 0x78 }, // n
{ 0x38, 0x44, 0x44, 0x44, 0x38 }, // o
{ 0x7C, 0x14, 0x14, 0x14, 0x08 }, // p
{ 0x08, 0x14, 0x14, 0x18, 0x7C }, // q
{ 0x7C, 0x08, 0x04, 0x04, 0x08 }, // r
{ 0x48, 0x54, 0x54, 0x54, 0x20 }, // s
{ 0x04, 0x3F, 0x44, 0x40, 0x20 }, // t
{ 0x3C, 0x40, 0x40, 0x20, 0x7C }, // u
{ 0x1C, 0x20, 0x40, 0x20, 0x1C }, // v
{ 0x3C, 0x40, 0x30, 0x40, 0x3C }, // w
{ 0x44, 0x28, 0x10, 0x28, 0x44 }, // x
{ 0x0C, 0x50, 0x50, 0x50, 0x3C }, // y
{ 0x44, 0x64, 0x54, 0x4C, 0x44 } // z
};
/*
Global Variables
*/
static byte LcdCache [ LCD_CACHE_SIZE ];
static int LcdCacheIdx;
static int LoWaterMark;
static int HiWaterMark;
static bool UpdateLcd;
// Function delay //
void delay_ms(long ms) // delay 1 ms per count @ CCLK 60 MHz
{
long i,j;
for (i = 0; i < ms; i++ )
for (j = 0; j < 6659; j++ );
}
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 69
/*
Name : lcdInit
*/
void lcdInit ( void )
{
delay_ms(500) // Ensure delay for initial Pull-up on reset pin.
// IOSET0 |= LCD_RST_PIN;
out_0(4,1); // Set output bits on port B.
delay_ms(10); // Toggle display reset pin. IOCLR0 |= LCD_RST_PIN;
out_0(4,0);
delay_ms(10); //delay_ms(10); //IOSET0 |= LCD_RST_PIN;
out_0(4,1); // Enable SPI port: No interrupt, MSBit first, Master mode, CPOL->0,
// CPHA->0, Clk/4,SPCR = 0x50;
// Disable LCD controller
// IOSET0 |= LCD_CE_PIN;
out_1(20,1); // Disable SCE pin
lcdSend( 0x21, LCD_CMD ); // LCD Extended Commands.
lcdSend( 0xC8, LCD_CMD ); // Set LCD Vop (Contrast).
lcdSend( 0x06, LCD_CMD ); // Set Temp coefficent.
lcdSend( 0x13, LCD_CMD ); // LCD bias mode 1:48.
lcdSend( 0x20, LCD_CMD ); // LCD Commands, Horizontal addressing mode.
lcdSend( 0x0C, LCD_CMD ); // LCD in normal mode.
LoWaterMark = LCD_CACHE_SIZE; // Reset watermark pointers.
HiWaterMark = 0;
lcdClear();
lcdUpdate();
}
/*
Name : lcdClear
Description : Clears the display. lcdUpdate must be called next.
*/
void lcdClear ( void )
{
int i;
for ( i = 0; i < LCD_CACHE_SIZE; i++ )
{
LcdCache[i] = 0x00;
}
LoWaterMark = 0; // Reset watermark pointers.
HiWaterMark = LCD_CACHE_SIZE - 1;
UpdateLcd = TRUE;
}
/*
Name : lcdGotoXY
Description : Sets cursor location to xy location corresponding to basic font
size.
Argument(s) : x, y -> Coordinate for new cursor position. Range: 1,1 .. 14,6
*/
void lcdGotoXY ( byte x, byte y )
{
configGlcd();
LcdCacheIdx = (x - 1) * 6 + (y - 1) * 84;
}
void configGlcd()
{
if(glcd_ini==0)
{
glcd_ini=1;
lcdInit();
lcdClear();
}
}
Listing PS-1 Source program of glcdS110.h library file (continue)
70 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
/*
Name : lcdSend
Description : Sends data to display controller.
Argument(s) : data -> Data to be sent
cd -> Command or data (see/use enum)
*/
void lcdSend ( byte data, LcdCmdData cd )
{
int j,data_in; // Enable display controller (active low). IOCLR0 |= LCD_CE_PIN;
out_1(20,0); // Enable SCE pin
//out_0(20,0); // Off
if ( cd == LCD_DATA )
{ // IOSET0 |= LCD_DC_PIN;
out_0(5,1);
}
else
{ // IOCLR0 |= LCD_DC_PIN;
out_0(5,0);
}
// Send data to display controller. Wait until Tx register empty.
data_in = data;
for ( j = 0; j <8; j++ )
{ // IOCLR0 |= LCD_CLK_PIN;
out_0(7,0);
if ((data_in & 0x80)!=0)
{ // IOSET0 |= LCD_MOSI_PIN;
out_0(6,1);
}
else
{ // IOCLR0 |= LCD_MOSI_PIN;
out_0(6,0);
}
data_in=data_in<<1;
out_0(7,1); // IOSET0 |= LCD_CLK_PIN;
}
// Disable display controller.
// IOSET0 |= LCD_CE_PIN;
out_0(20,1);
}
/*
Name : lcdChar
Description : Displays character at current cursor position and increment position.
Argument(s) : size -> Font size. See enum.
ch -> Character to write.
*/
void lcdChar (byte ch )
{
byte i;
configGlcd();
if ( LcdCacheIdx < LoWaterMark )
{
LoWaterMark = LcdCacheIdx; // Update low marker.
}
if ( (ch < 0x20) || (ch > 0x7b) )
{ // Convert to a printable character.
ch = 92;
}
for ( i = 0; i < 5; i++ )
{
LcdCache[LcdCacheIdx++] = FontLookup[ch - 32][i] << 1;
}
if ( LcdCacheIdx > HiWaterMark )
{
HiWaterMark = LcdCacheIdx;
}
LcdCache[LcdCacheIdx++] = 0x00; // Horizontal gap between characters.
}
Listing PS-1 Source program of glcdS110.h library file (continue)
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 71
/*
Name : lcdString
Description : Displays a character at current cursor location and increment location
according to font size.
Argument(s) : size -> Font size. See enum.
dataPtr -> Pointer to null terminated ASCII string to display.
*/
void lcdString (byte _x,byte _y,byte *dataPtr)
{
configGlcd();
lcdGotoXY(_x,_y);
while (*dataPtr)
{
lcdChar(*dataPtr++);
}
}
/*
Name : lcdPixel
Description : Displays a pixel at given absolute (x, y) location.
Argument(s) : x, y -> Absolute pixel coordinates
mode -> Off, On or Xor. See enum.
Return value : None.
*/
void lcdPixel(byte x, byte y, lcdPixelMode mode)
{
word index;
byte offset;
byte data;
configGlcd();
if ( x > LCD_X_RES ) return;
if ( y > LCD_Y_RES ) return;
index = ((y / 8) * 84) + x;
offset = y - ((y / 8) * 8);
data = LcdCache[index];
if ( mode == PIXEL_OFF )
{
data &= (~(0x01 << offset));
}
else if ( mode == PIXEL_ON )
{
data |= (0x01 << offset);
}
else if ( mode == PIXEL_XOR )
{
data ^= (0x01 << offset);
}
LcdCache[index] = data;
if ( index < LoWaterMark )
{
LoWaterMark = index; // Update low marker.
}
if ( index > HiWaterMark )
{ // Update high marker.
HiWaterMark = index;
}
}
Listing PS-1 Source program of glcdS110.h library file (continue)
72 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
Listing PS-1 Source program of glcdS110.h library file (continue)
/*
Name : lcdLine
Description : Draws a line between two points on the display.
Argument(s) : x1, y1 -> Absolute pixel coordinates for line origin.
x2, y2 -> Absolute pixel coordinates for line end.
mode -> Off, On or Xor. See enum.
*/
void lcdLine ( byte x1, byte y1, byte x2, byte y2, lcdPixelMode mode )
{
int dx, dy, stepx, stepy, fraction;
configGlcd();
dy = y2 - y1;
dx = x2 - x1;
if ( dy < 0 )
{
dy = -dy;
stepy = -1;
}
else
{
stepy = 1;
}
if ( dx < 0 )
{
dx = -dx;
stepx = -1;
}
else
{
stepx = 1;
}
dx <<= 1;
dy <<= 1;
lcdPixel( x1, y1, mode );
if ( dx > dy )
{
fraction = dy - (dx >> 1);
while ( x1 != x2 )
{
if ( fraction >= 0 )
{
y1 += stepy;
fraction -= dx;
}
x1 += stepx;
fraction += dy;
lcdPixel( x1, y1, mode );
}
}
else
{
fraction = dx - (dy >> 1);
while ( y1 != y2 )
{
if ( fraction >= 0 )
{
x1 += stepx;
fraction -= dy;
}
y1 += stepy;
fraction += dx;
lcdPixel( x1, y1, mode );
}
}
UpdateLcd = TRUE;
}
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 73
/*
Name : lcdUpdate
Description : Copies the LCD cache into the device RAM.
Argument(s) : None.
Return value : None.
*/
void lcdUpdate ( void )
{
int i;
if ( LoWaterMark < 0 )
LoWaterMark = 0;
else if ( LoWaterMark >= LCD_CACHE_SIZE )
LoWaterMark = LCD_CACHE_SIZE - 1;
if ( HiWaterMark < 0 )
HiWaterMark = 0;
else if ( HiWaterMark >= LCD_CACHE_SIZE )
HiWaterMark = LCD_CACHE_SIZE - 1;
// Set base address according to LoWaterMark.
lcdSend( 0x80 | (LoWaterMark % LCD_X_RES), LCD_CMD );
lcdSend( 0x40 | (LoWaterMark / LCD_X_RES), LCD_CMD );
// Serialize the video buffer.
for ( i = LoWaterMark; i <= HiWaterMark; i++ )
{
lcdSend( LcdCache[i], LCD_DATA );
}
LoWaterMark = LCD_CACHE_SIZE - 1; // Reset watermark pointers.
HiWaterMark = 0;
UpdateLcd = FALSE;
}
//*************************************************************************
// Purpose : Draw a rectangle on a graphic LCD
// Inputs : (x1, y1) - the start coordinate
// (x2, y2) - the end coordinate
// fill - YES or NO
// color - ON or OFF
// Dependencies: glcd_pixel(), glcd_line()
//*************************************************************************
void lcdRect( unsigned char x1,
unsigned char y1,
unsigned char x2,
unsigned char y2,
unsigned char fill,
unsigned char color)
{
if(fill)
{
unsigned char i, xmin, xmax, ymin, ymax;
if(x1 < x2) // Find x min and max
{
xmin = x1;
xmax = x2;
}
else
{
xmin = x2;
xmax = x1;
}
if(y1 < y2) // Find the y min and max
Listing PS-1 Source program of glcdS110.h library file (continue)
74 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
Listing PS-1 Source program of glcdS110.h library file (final)
{
ymin = y1;
ymax = y2;
}
else
{
ymin = y2;
ymax = y1;
}
for(; xmin <= xmax; ++xmin)
{
for(i=ymin; i<=ymax; ++i)
{
lcdPixel(xmin, i, color);
}
}
}
else
{
lcdLine(x1, y1, x2, y1, color); // Draw the 4 sides
lcdLine(x1, y2, x2, y2, color);
lcdLine(x1, y1, x1, y2, color);
lcdLine(x2, y1, x2, y2, color);
}
}
// Function for draw Progress Bar //
void lcdProgBar( unsigned char _x,
unsigned char _y,
unsigned char width,
unsigned char high,
unsigned char percentage)
{
lcdRect(_x,_y,_x+width,_y+high,0,1); // Draw Beyon
lcdRect(_x+1,_y+1,_x+width-1,_y+high-1,1,0); // Clear fill
lcdRect(_x,_y,_x+((percentage*width)/100),_y+high,1,1); // Paint color @ percentage
}
void lcdBackLight(char set)
{
out_1(21,set);
}
#endif
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 75
GLCD5110 libra ry func tion
lcdClear
Clear screen
syntax :
void lcdClear(void);
example :
#include lpc214x.h
#include glcd5110.h
.................
void main()
{
...............
lcdClear(); // Clear screen
................
}
lcdUpdate
Update GLCd screen with new mesasge and value. Use with lcdChar, lcdString,
lcdPixel, lcdLine, lcdRect and lcdProgBar function.
syntax :
void lcdUpdate(void);
lcdGotoXY
Set column and row position or co-ordinator for displaying character. Maximum
chararacter display is 14 x 6. The start point of screen; column 1 Row 1 is locared to top left
corner of screen.
syntax :
void lcdGotoXY (byte x, byte y)
parameter :
x : Column position (1 to 14)
y : Row position or Line (1 to 6)
lcdChar
Display one character on GLCD screen
syntax :
void lcdChar (byte ch)
parameter :
ch : Character display
76 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
example :
#include lpc214x.h
#include glcd5110.h
.................
void main()
{
...............
lcdGotoXY(12,2); // Set display position at Column 12 Line 2
lcdChar(N); // Display N at Column 12 Line 2
lcdChar(o); // Display o at Column 13 Line 2
lcdChar(k); // Display k at Column 14 Line 2
lcdChar(i); // Display i at Column 1 Line 3
lcdChar(a); // Display a at Column 2 Line 3
lcdChar(5); // Display 5 at Column 3 Line 3
lcdChar(1); // Display 1 at Column 4 Line 3
lcdChar(1); // Display 1 at Column 5 Line 3
lcdChar(0); // Display 0 at Column 6 Line 3
lcdUpdate(); // Update screen
................
}
Result :

E=#

Line 1
Line 2
Line 3
Line +
Line 5
Line 6
Column 12
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 77
lcdString
Display message on GLCD sceen
syntax :
void lcdString (byte _x,byte _y,byte *dataPtr);
parameter :
_x : Column position (1 to 14)
_y : Line position (1 to 6)
dataPtr : String display pointer
example :
#include lpc214x.h
#include glcd5110.h
.................
void main()
{
...............
lcdString(1,1,Hello world); // Display message on Line 1
lcdString(1,4,Line 4 Demo); // Display message on Line 4
lcdUpdate(); // Update screen
................
}
Result :

11.1

111
.1+

Line 1
Line 2
Line 3
Line +
Line 5
Line 6
78 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
lcdPixel
Set pixel display. The co-ordinator (0,0) is top left corner of screen.
syntax :
void lcdPixel(byte x, byte y, LcdPixelMode mode);
parameter :
x : Row pixel position (0 to 83)
y : Column pixel position (0 to 47)
LcdPixelMode : Set color mode
LcdPixelMode =0 as white or none
LcdPixelMode =1 as black
LcdPixelMode =2 as toggle
example :
#include lpc214x.h
#include glcd5110.h
.................
void main()
{
...............
lcdPixel(5,3,1); // Plot black point at (5,3) position of screen
lcdPixel(10,25,0); // Plot white dot at (10,25) position of screen
lcdPixel(30,20,2); // Invert color of (30,20) position of screen
lcdUpdate(); // Update screen
................
}
lcdLine
Draw a straight line.
syntax :
void lcdLine(byte x1, byte y1, byte x2, byte y2, LcdPixelMode mode);
parameter :
x1 : Start column position (0 to 83)
y1 : Start row position (0 to 47)
x2 : Destination column position (0 to 83)
y2 : Destination row position (0 to 47)
LcdPixelMode : Set color mode
LcdPixelMode =0 as white or none
LcdPixelMode =1 as black
LcdPixelMode =2 as toggle
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 79
example :
#include lpc214x.h
#include glcd5110.h
.................
void main()
{
...............
lcdLine(1,1,20,20,1); // Draw a straight line from (1,1) to (20,20)
lcdLine(1,1,20,20,0); // Drwaw a straight line from (1,1) to (20,20)
lcdUpdate(); // Update sceen
...............
}
lcdRect
Draw a rectangle at setting position.
syntax :
void lcdRect( unsigned char x1,
unsigned char y1,
unsigned char x2,
unsigned char y2,
unsigned char fill,
unsigned char color);
parameter :
x1 : Start row co-ordinator (0 to 83)
y1 : Start column co-ordinator (0 to 47)
x2 : Destination row co-ordinator (0 to 83)
y2 : Destination column co-ordinator (0 to 47)
fill : Fill color in the area
fill =0 No fill
fill =1 Fill color
color : Mode of display
color =0 : White or none
color =1 : Black
color =2 : Toggle color
example :
#include lpc214x.h
#include glcd5110.h
void main()
{
lcdRect(5,5,25,25,0,1);
// Draw a rectangular with left co-ordinator (5,5),
// right co-ordinator (25,25), No fill and Black border
lcdUpdate();
}
80 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
LcdProgBar
Create the Progress bar at setting position and shows shadow ratio.
syntax :
void LcdProgBar(unsigned char _x,
unsigned char _y,
unsigned char width,
unsigned char high,
unsigned char percentage)
parameter :
_x : Start column position (0 to 83)
_y : Start row position (0 to 47)
width : Number of pixel for progress bar width
high : Number of pixel for progess bar height
percentage : Shadow ratio for progress bar
example :
#include lpc214x.h
#include glcd5110.h
void main()
{
lcdLine(0,10,83,5,70);
// Create the progress bar at (0,10),
// width 83 pixels, height 5 pixels and 70% shadow ratio
lcdUpdate(); // Update screen
}
Result :

(0,10)
5 pixels height
Shadow 70 of width
83 pixels width
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 81
delay_ms
Delay in millisecond unit.
syntax :
void delay_ms(long ms)
parameter :
ms : Time in millisecond unit
example :
#include lpc214x.h
#include glcd5110.h
.................
void main()
{
...............
lcdString(1,1,Hello LCD); // Displays message Line 1
lcdString(1,2,0123456789"); // Displays message Line 2
lcdUpdate(); // Update screen
delay_ms(2000); // Delay 2000 ms. (2 second)
lcdClear(); // Clear screen
lcdString(1,1,This is test);// Displays message Line 1
lcdString(1,2,DELAY 2 sec); // Displays message Line 2
lcdUpdate(); // Update screen
................
}
82 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
Expe rime nt - 8.1 Simple me ssa ge displa y on GLCD
Proc e dure :
8.1.1 Build new project, in name glc d01_01.
8.1.2 Write the program Listing P8-2. Compile to glc d_01.he x and download to microcontroller.
Close LPC2000 Flash Utility program.
+3.3v
1
2
3
+
5
9
8
7
6
T1! T1O
13
8
7
6
2
15
16
P1O P1!
P2O P2!
v+
v-
vdd
C16
0.1F
C19, C20
0.1F x2
K7
7)46
45!
152
1
C1+
C1-
3
C17
0.1F
+
C2+
C2-
5
C18
0.1F
SW2
4-5-6
+3.3
v
+3.3v
P20
1k
4

P23
+7
10
9
12
21
19
+1
57 !C6
K!^7031
+3.3
v
PST +v
CND
SW3
152
1+!
2+"&
!C5
N^X3232
P0.0l[RxD0
P0.00[TxD0
P0.l+[BSL
RST
C+
15pF
C5
15pF
XT^L1
32.768kHz
C6
33pF
C7
33pF
XT^L2
12NHz
D2
1N5819
+3.3v
C8
C8-C10
0.1F x3
C9
C10
+3.3v
+3.3v
CND
JP2
8HAB
RTCXl
RTCX2
Xl
X2
Vbat
Vdd3-l(I[O)
Vdd3-2(I[O)
Vdd3-3(I[O)
Vdd3(A)
VssA
Vref
D3
1N5819
B^TT1
+3v
3
5
62
6l
+9
23
+3
5l
7
59
63
6 l8 25 l2
Vssl Vss2 Vss3 Vss+
3l
30
29
27
P0.07
P0.06
P0.05
P0.0+
+0
++
Pl.22
Pl.2l
l
l
+3.3V
C
N
D
S
C
E
R
E
S
E
T
D
f
C
S
D
I
N
S
C
L
K
L
E
D
,52
/+,#
Figure PS-2 CLCDS110 experiment circuit with LPC21+8
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 83
8.1.3 Connect LPC2148 port to GLCD5110 as follows :
G LC D5110 LPC2148 port
SDIN P0.06
SCLK P0.07
SCE P1.20
RESET P0.04
D/C P0.05
LED P1.21
8.1.4 Run program
At GLCD5110 screen shows message as follows :

J .1+:.......
-1.......
`.1.11.....

...1.+::..
. IJ."`
LED back light is blinked with 0.5 second.
ON
USB
ON
OFF
R
x
D
T
x
D
R
T
S
C
T
S
UART CH.1
LITIUM
BATTERY 3V
+3v BATT
12NHz
32.768kHz
+3.3v
GND
REF
DEBUC EN.
7
)
4
6

+
0

!SP
SWITCH
0.28 0.29
0.21 0.22
0.30 (AfD)
PSJ2
DAT 0.15
CLK 0.16
PIEZO
0.12-0.13
PORT
1.20
1.21
1.22
1.23
S
P
!
-
0
G0
.
0
+
0
.
0
5
0
.
0
6
0
.
0
7
+
T
W
!
-
0
G0
.
0
2
0
.
0
3
+
LPC21+8
P
O
R
T
P
1
.
1
9
P
1
.
1
8
P
1
.
1
7
P
1
.
1
6
0.25
(DfA)
G
USB
:"&
ARM7-LPC214S
Education board

Figure P8-3 Circuit construction on JX-21+8 board for GLCD5110 experiment


84 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
////
// Program : Example for GLCD display
// Description : Example for GLCD display on JX-2148 Board
// Frequency : Crystal 12 MHz at PLL 5x(CCLK = 60 MHz),PCLK = 30 MHz
// Filename : glcd_01.c
// C compiler : CodeSourcery G++ Lite Compiler
////
#include lpc214x.h // Header file for Phillips LPC2148 controller
#include glcd5110.h // Library for GLCD Nokia5110
// Initial system clock //
void init()
{
PLL0CFG=0x24; // MSEL = 4,PSEL = 2
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
PLL0CON=0x1;
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
while(!(PLL0STAT & 0x400)) ; // Wait until PLL Locked
PLL0CON=0x3; // Connect the PLL as the clock source
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
MAMCR=0x2; // Enabling MAM and setting number of clocks
// used for Flash memory fetch
// (4 cclks in this case)
MAMTIM=0x4;
VPBDIV=0x02; // PCLK at 30 MHz
}
// Main Program //
void main()
{
int cnt,i=0; // Counter variable
constchar *pText1 = JX-2148; // Store message in Program memory
constchar *pText2 = Graphic LCD; // Store message in Program memory
constchar *pText3 = Nokia 5110; // Store message in Program memory
init(); // Initialize the system
SCS = 0x03; // select the fast version of the I/O ports
lcdString(1,1,pText1); // Set message on line 1
lcdString(1,2,pText2); // Set message on line 2
lcdString(1,3,pText3); // Set message on line 3
lcdUpdate(); // Display message
lcdGotoXY(1,4); // Go to (1,4)
for (cnt=0; cnt<14; cnt++) // Loop for set - on line 4
{
lcdChar(-);
}
Listing PS-2 : glcd_01.c file of GLCD5110 simple message display for
LPC21+8 experiment (continue)
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 85
Listing PS-2 : glcd_01.c file of GLCD5110 simple message display for
LPC21+8 experiment (final)
lcdUpdate(); // Display message
lcdGotoXY(3,5); // Go to (3,5)
for (cnt='0'; cnt<='9'; cnt++) // Loop for set 0-9' on line 5
{
lcdChar(cnt);
}
lcdUpdate(); // Display message
lcdGotoXY(1,6); // Go to (1,6)
for (cnt'A'; cnt<'N'; cnt++) // Loop for set A-N on line 6
{
lcdChar(cnt);
}
lcdUpdate(); // Display message
while(1) // Infinite loop
{
lcdBackLight(1); // BackLight ON
delay_ms(500); // Delay 500 ms
lcdBackLight(0); // BackLight OFF
delay_ms(500); // Delay 500 ms
}
}
Expe rime nt - 8.2 Simple gra phic displa y on GLCD
Proc e dure :
8.2.1 Build new project, in name glc d_02.
8.2.2 Write the program Listing P8-3. Compile to glc d_02.he x and download to microcontroller.
Close LPC2000 Flash Utility program.
8.2.3 Run program
At GLCD5110 screen shows message as follows :

Rectangular
Pixel dot
Straight line
86 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
////
// Program : Example for GLCD display
// Description : Example for GLCD display on JX-2148 Board
// Frequency : Crystal 12 MHz at PLL 5x(CCLK = 60 MHz),PCLK = 30 MHz
// Filename : glcd_02.c
// C compiler : CodeSourcery G++ Lite Compiler
////
#include lpc214x.h // Header file for Phillips LPC2148 controller
#include glcd5110.h // Header file for Phillips LPC2148 controller
// Initial system clock //
void init()
{
PLL0CFG=0x24; // MSEL = 4,PSEL = 2
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
PLL0CON=0x1;
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
while(!(PLL0STAT & 0x400)) ; // Wait until PLL Locked
PLL0CON=0x3; // Connect the PLL as the clock source
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
MAMCR=0x2;
// Enabling MAM and setting number of clocks used for Flash memory fetch
// (4 cclks in this case)
MAMTIM=0x4;
VPBDIV=0x02; // PCLK at 30 MHz
}
// Main Program //
void main()
{
init(); // Initialize the system
SCS = 0x03; // select the fast version of the I/O ports
lcdPixel(60,20,1); // Draw Pixel at(60,20)
lcdLine(40,30,25,40,1); // Draw Line at(60,20)
lcdRect(5,5,25,25,0,1); // Draw Rectangle at(60,20)
lcdUpdate(); // Display message
while(1);
}
Listing PS-3 : glcd_02.c file of GLCD5110 simple graphic display for
LPC21+8 experiment
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 87
Expe rime nt - 8.3 Ana log displa y on GLCD
This experiment demonstrares reading analog signal at P0.30 of LPC2148 that
connect with variable resistor and display value with progress bar on GLCD5110 screen.
+3.3v
1
2
3
+
5
9
8
7
6
T1! T1O
13
8
7
6
2
15
16
R1O R1!
R2O R2!
v+
v-
vdd
C16
0.1F
C19, C20
0.1F x2
K7
7)46
45!
152
1
C1+
C1-
3
C17
0.1F
+
C2+
C2-
5
C18
0.1F
SW2
4-5-6
+3.3
v
+3.3v
R20
1k
4

R23
+7
10
9
12
21
19
+1
57 !C6
K!A7031
+3.3
v
RST +v
GND
SW3
152
1+!
2+"&
!C5
NAX3232
P0.01fRxD0
P0.00fTxD0
P0.1+fBSL
RST
C+
15pF
C5
15pF
XTAL1
32.768kHz
C6
33pF
C7
33pF
XTAL2
12NHz
D2
1N5819
+3.3v
C8
C8-C10
0.1F x3
C9
C10
+3.3v
+3.3v
GND
JP2
8HAB
RTCX1
RTCX2
X1
X2
vbat
vdd3-1(IfO)
vdd3-2(IfO)
vdd3-3(IfO)
vdd3(A)
vssA
vref
D3
1N5819
BATT1
+3v
3
S
62
61
+9
23
+3
S1
7
S9
63
6 18 2S 12
vss1 vss2 vss3 vss+
31
30
29
27
P0.07
P0.06
P0.0S
P0.0+
+0
++
P1.22
P1.21
1
1
+3.3v
G
N
D
S
C
E
R
E
S
E
T
D
f
C
S
D
!
N
S
C
L
K
L
E
D
,52
/+,#
+3.3v
P0.30
vR1-10k
),+
!
1S
Figure PS-4 Graphic display creation experiment for LPC21+8
88 J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board
Proc e dure :
8.3.1 Build new project, in name glc d_03.
8.3.2 Write the program Listing P8-4. Compile to glc d_03.he x and download to microcontroller.
Close LPC2000 Flash Utility program.
////
// Program : Example for GLCD display
// Description: Example for GLCD display analog value with Progress bar
// Frequency : Crystal 12 MHz at PLL 5x(CCLK = 60 MHz),PCLK = 30 MHz
// Filename : glcd_03.c
// C compiler : CodeSourcery G++ Lite Compiler
////
#include lpc214x.h // Header file for Phillips LPC2148 controller
#include glcd5110.h // Header file for Phillips LPC2148 controller
// Initial system clock //
void init()
{
PLL0CFG=0x24; // MSEL = 4,PSEL = 2
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
PLL0CON=0x1;
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
while(!(PLL0STAT & 0x400)) ; // Wait until PLL Locked
PLL0CON=0x3; // Connect the PLL as the clock source
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
MAMCR=0x2;
// Enabling MAM and setting number of clocks used for Flash memory fetch
// (4 cclks in this case)
MAMTIM=0x4;
VPBDIV=0x02; // PCLK at 30 MHz
}
// Function for Read analog value from A/D 0.30 //
unsigned int analog(void)
{
unsigned int val=0;
AD0CR |= 0x01000000; // Start A/D Conversion
while ((AD0DR3 & 0x80000000) == 0); // Wait for the conversion to complete
val = ((AD0DR3 >> 6) & 0x03FF); // Extract the A/D result
return(val);
}
Listing P8-+ : glcd_03.c file of GLCD5110 graphic display with AJD
converter for LPC21+8 experiment (continue)
J X-2148 : LPC2148 ARM7-32 bit Microcontroller Education board 89
Listing P8-+ : glcd_03.c file of GLCD5110 graphic display with AJD
converter for LPC21+8 experiment (final)
// Main Program //
void main()
{
char str_adc[20]; // Buffer for keep string from analog value
char str_percentage[10]; // Buffer for keep string from percentag
unsigned int adc_val=0,percentage=0;
// Variable for keep analog and percentage
init(); // Initialize the system
SCS = 0x03; // select the fast version of the I/O ports
PINSEL1 |= 0x10000000; // Enable AD0.3
AD0CR = 0x00210608; // Setup A/D: 10-bit AIN0 @ 3MHz
while(1) // Infinite loop
{
adc_val = analog(); // Get analog value from A/D 0.30
percentage = (adc_val*100)/1023; // Calculate to percentage
sprintf(str_adc,(A/D): %d ,adc_val);
// Convert string to display analog value
lcdString(1,1,str_adc); // Set analog value display on line 1
sprintf(str_percentage,%d%% ,percentage);
// Convert string to display percentage
lcdString(7,3,str_percentage);
// Set percentage value display on line 3
lcdProgBar(0,10,83,5,percentage); // Display progress bar at
// (0,10),width 83 pixel,high 5 pixel
lcdUpdate(); // Display message
}
}
8.3.3 Run program. Adjust the variable resistor on J X-2148 board and see the result at GLCD
5110 screen.
The GLCD5110 displays the conversion value and progress bar that get from A/ D
converter module of LPC2148.

1.........
`.1.:` ....

...1.+::..
. IJ.`

You might also like