Anda di halaman 1dari 89

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 1

JX-2148
LPC2148 ARM7-32 bit Microcontroller Education board
1. Kit Contents
In standard package of JX-2148 board include : 1. JX-2148 Education board 2. CX-232 serial port cable 3. AWG#22 wire jumper, 7cm. length 4. Documentation 5. CD-ROM 6. GLCD5110 graphic LCD module x1 x1 x 10 x1 x1 x1

To run this education board youll need: DC adaptor +6Vdc 500mA (maximum +9Vdc)

2. JX-2148 board features


l 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

l Standard JTAG connector l USB 2.0 Full Speed Interface (USB connector type B). JX-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.

l Dual Serial Ports. JX-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.

l SD/MMC socket. The JX-2148 provides one SPI module to interface SD/MMC
memory socket.

l A PS/2 jack for interface Keyboard or Mouse. l 2 of push-button switches with resistor pull-up.

2 l JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board

l 2 of LED indicators l Analog Voltage Control for ADC Input. JX-2148 provides an adjustable analog
voltage source for testing the A/D converter feature of the LPC2148.

l A small buzzer for sound experiment l Mini-breadboard 170 points contact. l 32kHz crytal and +3V battery backup for real-time clock system within MCU. l +3.3V on-board regulator for MCU and +5V for PS/2 circuit. l Polarity voltage protection.

3. System requirements
To use the JX-2148 Education Board, the following item must be prepared :

l 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. l Install Windows XP Operating System l Install Keil ARM tool kit evaluation version. Download at www.keil.com l Install Sourcery G++ Lite Edition - free C compiler for ARM Download at www.codesourcery.com l 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 l USB to RS-232 serial port converter. In case the computer does not provide RS232 port. (Suggest UCON-232S. See detail at www.inexglobal.com) l DC adaptor +9V 500mA recommended. l 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 l ESD-200 Bluetooth module if need to make wireless communication. l PS/2 Keyboard if need to make PS/2 keyboard interface experiment. l PS/2 Mouse if need to make PS/2 mouse interface experiment. l USB cable, AB type not over 3m. length for testing USB interface. l ULINKUSB-JTAG adaptor. Direct contact to www.keil.com.

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 3

4. JX-2148 board layout


The figure 1 illustration shows the important interface and hardware components of the JX-2148 board.

JTAG pin assignment


RESET GND RTCK TRST TCLK TDO TMS N/C GND N/C GND TDI Vcc
' 

Top view

ESD-200 Bluetooth module connector pin assignment


ANTENNA

"

&

pin 8 and 9 not used

CS

MOSI

GND SCK MISO CP +3.3V GND WP

GND +V,, STATUS GND

RxD TxD RTS CTS

RESET

BLUETOOTH ESD-02 SD/MMC STATUS

+ +4.5-9V ON OFF

JTAG/DEBUG port

ARM7-LPC2148 Education board

JX-2148

DEBUG EN.

+3.3V REF GND

12MHz

UART CH.1

ON USB

32.768kHz LPC2148
P1.19 P1.18 P1.17 P1.16

+3V BATT

LITIUM BATTERY 3V PIEZO 0.12-0.13 PS/2 0.22 CLK 0.16 DAT 0.15

G 0.02 0.03 +

TWI-0

PORT

0.25 (D/A) UART CH0 G

SPI-0

USB

G 0.04 0.05 0.06 0.07 +

PORT

1.20 1.21 1.22 1.23

0.21

SWITCH

ISP

0.28

0.29

0.30 (A/D)

Figure 1 : The JX-2148 board layout

ESD-02

GND

GND

GND

GND

GND

GND

Vcc

CTS RTS TxD RxD

4 l JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board

5. JX-2148 operation
The operation of JX-2148 board has 3 main sections following : (1) LPC2148 microcontroller unit (2) Power supply (3) Input/Output circuit Microcontroller 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. Power supply of JX-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. Many I/O devices are installed on the JX-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, JTAG 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 circuit description


The complete shcematic of the JX-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 I2C 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.

D1 1N5819 R2 22k
CLK DAT CP1

+3.3V

+5V

+V IN IC2 2931-5.0 GND

+3.3V

K1 USB
R3 22k
RES RES

+5VUSB USBDUSBD+

SD/MMC
R10 10k R11 10k

K3 K4 R12 10k R14 150


RxD TxD RTS CTS

Vdd OUT

+3.3V R15 10k LED5 BT-STATUS

+V SHD
WP1 Vss1 Vss2 CS DI DO SCK

BD1 1A50V +3.3V C3 0.1 F R8 510 R5 27 +3.3V 16 Vdd V+ V10 T1I T1O IC4 MAX3232 9 R1O R1I 10 USBD+ USBD- P0.23 P0.22 P0.21 VBUS 17 P0.31/ UP_LED P0.20 P0.19 P0.18 P0.17 P0.16 P0.15 SSEL1 MOSI1 MISO1 SCK1 41 P0.13 39 P0.12 37 P0.11 R19 220
RTS UART

SW1 POWER +3.3V +3.3V Q1 R26 DTA114 1.5k R13 150 R9 510 SP1 PIEZO 54 53 47 46 45 C11 0.1 F 15 2 6 7 C12, C13 0.1 F x2 MOD1

IC1 78R33

PS2

J1 DC.input 4.5-12V ESD-02


R6 27
RTS_Bluetooth CTS_Bluetooth RxD_Bluetooth TxD_Bluetooth

C1 220/25V R7 10k 58 LED3 LED4 0.22 0.21 2 1 55

R1 510

IN

OUT

GND R4 510 LED2 USB 11

LED1 ON

C2 1000 F 6.3V

K2 DC.input 4.5-12V PORT1


P1.16 P1.17 P0.10 JP5 CTS1_SELECT 34 JP6 RxD1_SELECT 33 JP7 TxD1_SELECT
TxD_UART RxD_UART

16 35
CTS_UART

JP4 RTS1_SELECT

P1.18 P1.19 P1.20 P0.09/RxD1 P1.21 P1.22 P1.23 P0.08/TxD1 16

P1.16 12 P1.17 8 P1.18 4 P1.19

1 2 3 4 12 R2O R2I 13 5 K6 11 T2I T2O 14

6 7 8 9

+3.3V

R16 10k *4

48 P1.20 44 P1.21 40 P1.22 36 P1.23

SPI-0
P0.07/SSEL0 P0.06/MOSI0 P0.05/MISO0 P0.04/SCK0 GND +3.3 V

TRST TDI TMS TCK RTCK TDO RST

IC3 LPC2148

C14 0.1 F

4 5

C2+ C2-

C1+ C1-

1 3

UART1 RS-232
C15 0.1 F

JP1 DBG_EN K5 C4 15pF RTCX1 5 RTCX2 C5 15pF XTAL1 32.768kHz 62 X1 C6 33pF +3.3V X2 C7 33pF XTAL2 12MHz 63 Vref 61 3

DIS

1 3 5 7 9 11 13 15 17 19 P1.24 12 P1.25 8 P1.26/RTCK 4 P1.27/TDO 48 P1.28/TDI 44 P1.29/TCK 40 P1.30/TMS 36 P1.31/TRST 31 P0.07/SSEL0 30 P0.06/MOSI0 29 P0.05/MISO0 27 P0.04/SCK0

2 4 6 8 10 12 14 16 18 20

EN

IC5 MAX3232

+3.3V 16

C16 0.1 F 15 1 C17 0.1 F +3.3V 26 P0.03/SDA0 22 P0.02/SCL0 C18 0.1 F P0.03/SDA0 P0.02/SCL0 GND P0.01/RxD0 P0.00/TxD0 P0.14/BSL +3.3V 21 19 41 SW2 RESET 57
R21 10k

JTAG

TWI (I2C)

Vdd C1+ 3 4 5 C1C2+ V+ VC210 R1O 9 T1I +3.3 V R20 1k


R22 22k

R17 10k

R18 10k

2 6 R1I T1O 12 R2O R2I 7 8 13 C19, C20 0.1 F x2 1 2 3 4 5 SW3 R23 47 RST RST P0.25/AD0.4/AOUT 9 P0.28/DA GND P0.30 IC6 KIA7031 GND +3.3V K7 6 7 8 9

JP2 Vref GND 23 D2 1N5819 C8 C10 D3 1N5819 C8-C10 0.1 F x3 59 49 C9 43 Vdd3-2(I/O) 51 Vdd3-3(I/O) 7 Vdd3(A) VssA Vbat Vss1 6 Vdd3-1(I/O)

+3.3V

ISP
+V +3.3 V

+3.3V

UART0 RS-232 ISP

BATT1 +3V

Vss2 Vss3 Vss4 18 25 12

Figure 2 JX-2148 board schematic diagram


P0.29 P0.28 VR1-10k ADC 0.30 S2 P0.29

R25 10k

R24 10k S1 P0.28

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 5

6 l JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board

BLUETOOTH ESD-200

BLUETOOTH ESD-200

Install ESD-20 module on female connector

ANTENNA

ESD-200 STATUS CTS RTS TxD RxD UART CH.1 STATUS CTS RTS TxD RxD UART CH.1

Select jumpers to define UART1 module of LPC2148 connected with RS-232 serial port

Select jumpers to define UART1 module of LPC2148 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)
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 JTAG interface. In-system flash programming of JX-2148 will work via UART0 module. SW3 is ISP mode switch. Must pess this switch to enter 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 JX-2148 board define SSP to connect with MMC/SD card interface. The SPI module (SPI0) will reserve to connect addition SPI peripheral.

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 7

In A/D converter demonstration, on JX-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 JX-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 jumper : 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. jumper : Select to enable degugging via JTAG connector.

8 l JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board

7. Software Developmet tools :


We suggest the free of charge development tools for LPC2148 microcontroller. It includes 3 mainly tools as RealView Microcontroller Development Kit or Keil ARM tool kit evaluation version, Sourcery G++ Lite (its C compiler) and ISP Downloading software (LPC2000 Flash Utility and Flash Magic)

7.1 Software installation


7.1.1 Sourcery G++ Lite : C compiler for 32-bit ARM microcontroller
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.codesourcery.com/ gnu_toolchains/arm/portal/release323. 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 Next button.

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 9

(2) The License Agreement window is appeared. Select option I accept the terms of License Agreement and click on the Next button. (3) Click OK or Next button to accept all step until to Choose Install Set window. Select type of installation as Typical. Click on the Next button.

(4) Choose Install Folder window is appeared. Select drive and folder as C:\Program Files\CodeSourcery\Sourcery G++ Lite. Click on the Next button.

10 l JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board

(5) Add product to the PATH? window is appeared for changing installation path. Select Modify PATH for current user heder for adding installtion path for speific user or select Modify PATH for all users. header for adding path for everyone. Click on the Next button.

(6) The Choose Shortcut Folder is appeared next. Click on other header and Next button.

(7) Software shows installation summary. Click on the Next button until software is installed successfully. Click on Done button to finish.

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 11

7.1.2 Realview Microcontroller Development 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.exe). The installation window is appeared. Click on the Next button.

(2) The License Agreement window is appeared. Select option I accept the terms of License Agreement and click on the Next button. (3) Folder Selection window is appeared. Selecte drive and folder for installtion. For example is C:\Keil . Click on the Next button.

12 l JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board

(4) Enter the Customer Information window. Type your information and e-mail address. After that the Next button will be active. Click this button to next step.

(5) Installtion is proceed. Wait until installation is completed.

(6) The Keil uVision3 Setup Completed will be appeared. Click the box following the picture below and Finish button. The installation is finished.

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 13

7.1.3 LPC2000 Flash 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 JX-2148 Education board. The installation program for this utility is included on the INEX JX-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 Flash Magic


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 l JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board

8. How to develop code with Keil Vision3 and Sourcery G++ Lite compiler
This sections introduce you to the Keil development tools, and take you through the process using them with the JX-2148 board. Youll learn how to create the C code, compile, download and run a program on this board. Developing programs for the JX-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 JX-2148 Board by using LPC2000 Flash Utility or Flash Magic.

8.1 How to use Sourcery G++ Lite with Keil 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 Project Close Project.... (2) After that select menu Project, Management, Component, Environment, Book. The Component, Environment and Book window is appeared.

(2.1) At Select ARM Development Tools , select Use c Compiler (2.2) Set the new compiler at GNU-Tool-Prefix box as arm-none-eabi(2.3) At Cygnus Folder box, select the code location. Normally it is in C:\Program Files\CodeSourcery\Sourcery G++ Lite\ folder. Click on the OK button.

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 15

8.2 Create the example project file


(1) Create the new project fle. Select menu Project New Project. Set the project name and folder location.

This example is set name as Test in C:\NXP2148 folder. Click on the Save button. (2) Select target chip on the Select Device for Target Target 1 window

16 l JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board

(3) At Data base box, select Microcontroller manufacturer as NXP (founded by Philips) and select device as LPC2148. Click on the OK button.

(4) Select menu Project Option for Target Target1 . The Option for Target Target1 is appeared. Select Target tab. At Xtal (MHz): box, set clock frequency as 12.0. Its mean 12MHz clock frequency.

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 17

(5) Next, select Output tab. Click to mark at Create HEX File box for creating the hex file afrer compiling the project file.

(6) Select User tab. At Run User Programs After Build/Rebuild box, select Run #1 and type this command below into the box.

arm-none-eabi-size *.hex

18 l JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board

(7) Click CC tab. At Optimization box, select No Optimization for setting normal compilation.

(8) At Linker tab, click at Do not use Standard System Startup Files for removing the mark. Next , check box at Enable Garbage Collection. At Linker Script File box, type the filename ARM.ld following the picture below. Click on the OK button to back the main window of program.

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 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 Source Group 1 message in Project Workspace box following the picture below.

(11) The Add Files to Group Source Group 1 window is appeared. At Files of type box, select the file type as Asm Source file (*.s; *.src; *.a). It shows location of Startup.s file from step (9). Click on the Startup.s file following click on the Add button and Close button.

20 l JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board

(12) Select menu File New . The blank window will be appeared. Name is Text1. 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; IODIR0 = 0x00400000; IOSET0 = 0x00400000; while(1) { IOCLR0 = 0x00400000; delay(1500000); IOSET0 = 0x00400000; delay(1500000); } }

// Set GPIO0.22 = GPIO Function // Set GPIO0.22 = Output // Set GPIO0.22 Pin (OFF LED)

// // // //

Clear Pin P0.22 (ON LED) Delay Set Pin P0.22 (OFF LED) Delay

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 21

(13) Save file as LED.c. At the Project Workspace; it displays all files that included in this project. This project has 2 files; Startup.s and LEC.c

(14) Compile this project file by selecte menu Project Rebuild all target files If no any error, the Output window reports messages 0 Error(s), 0 Warning(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 l JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board

8.3 Download program and test with LPC2000 Flash Utility


After compile the program, from example the result file is led.hex. 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 JX-2148 board. Turn-on POWER switch. (2) Connect download cable to the JX-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 l At Device box set as : - Device select to LPC2148 set to 12000 (12MHz)

- XTAL Freq. [kHz]

l At Communication box set as : - Connected To Port select the serial port is connected - Use Baud Rate set baudrate. 9,600 bps is default.

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 23

(5) Set the JX-2148 board to ISP mode by press ISP SWITCH (its shaft will down) following press RESET switch once.
2

RESET

BLUETOOTH ESD-02 SD/MMC STATUS

+ +4.5-9V ON OFF

JTAG/DEBUG port

ARM7-LPC2148 Education board

JX-2148

DEBUG EN.

+3.3V REF GND

12MHz

CTS RTS TxD RxD

UART CH.1

ON USB

32.768kHz LPC2148
P1.19 P1.18 P1.17 P1.16

+3V BATT

LITIUM BATTERY 3V PIEZO 0.12-0.13 PS/2 0.22 CLK 0.16 DAT 0.15

G 0.02 0.03 +

TWI-0

PORT

0.25 (D/A) 7)46+0 G

SPI-0

USB

G 0.04 0.05 0.06 0.07 +

PORT

1.20 1.21 1.22 1.23

0.21

SWITCH

ISP

0.28 1

0.29

0.30 (A/D)

Press the ISP switch. The switch's shaft is down.


(6) At the main wondow of LPC2000 Flash Utility. Click at Manual Reset button once following click Read Device ID once too. If the connection is correct, status bar at left down conner will show message Read Part ID Successfully

24 l JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board

If connection fail, the warning window will appear following the figure 41. Click Read Device ID button again and see the result. May be back to do in step (5) and (6) again.

(7) If connection complete, click at Browse button in Filename of Flash Programming. Select led.hex in path C:\led\led.hex. Next, click Upload to Flash button to download. After downloading complete the message File Upload Successfully Completed 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.

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 25

8.4 Download program and test with Flash Magic


We have another ISP software for supporting the JX-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 Hardware connection and setup


(1) Apply the supply voltage to JX-2148 board. Turn-on POWER switch. (2) Connect download cable to the JX-2148 board and Serial port of computer or connect iva USB to serial port converter (UCON-232S is recommended). (3) Set the JX-2148 board to ISP mode by press ISP SWITCH (its shaft will down) following press RESET switch once.

8.4.2 Flash Magic setup (do only first time)


(1) Open Flash Magic. Enter to Main window. Select menu Option Advance Option...

(2) At Advance Option window, select Hardware Config tab and click to remove the marl at Use DTR control RTS box following the picture below. Click on the OK button.

26 l JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board

8.4.3 Download and test


(1) Set communication properties at Step 1 - Communication. (1.1) Select the comminication port at COM port. For example is COM1. (1.2) Select Baud Rate as 38400 (3.3) Select Device as LPC2148 (3.4) At Interface box, select None (ISP)

(2) Step 2 - Erase : Erase option; select Erase all Flash.

(3) Open the HEX file at Step 3 - Hex File. (4) Select Verify after programming in Step 4 - Option if require to verify. (5) Click on the Start button in Step 5 - Start! 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.

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 27

9. Sample Experiment Experiment -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.

Procedure :
1.1 Build new project, in name led 1.2 Write the program Listing P1-1. Compile to led.hex 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.

RESET

BLUETOOTH ESD-02 SD/MMC STATUS

+ +4.5-9V ON OFF

JTAG/DEBUG port

ARM7-LPC2148 Education board

JX-2148

DEBUG EN.

+3.3V REF GND

12MHz

CTS RTS TxD RxD

UART CH.1

TWI-0

PORT

SPI-0

Connect to serial port

ON USB

32.768kHz LPC2148
P1.19 P1.18 P1.17 P1.16

+3V BATT

LITIUM BATTERY 3V PIEZO 0.12-0.13 PS/2 0.22 CLK 0.16 DAT 0.15

G 0.02 0.03 +

USB 0.25 (D/A) UART CH0 G

G 0.04 0.05 0.06 0.07 +

PORT

1.20 1.21 1.22 1.23

0.21

SWITCH

ISP

0.28

0.29

0.30 (A/D)

Press down to Program Press up to Run

Observe LED operation

28 l JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board

//// // 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 void init() { PLL0CFG=0x24; PLL0FEED=0xAA; PLL0FEED=0x55; PLL0CON=0x1; PLL0FEED=0xAA; PLL0FEED=0x55; Initial system clock // // MSEL = 4,PSEL = 2 // Feed process

// Feed process

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 } }

Listing P1-1 : led.c file of led project for LPC2148 output port experiment (continue)

LPC2148

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 29

Experiment -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.

Procedure :
2.1 Build new project, in name switch 2.2 Write the program Listing P2-1. Compile to switch.hex 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

RESET

BLUETOOTH ESD-02 SD/MMC STATUS

+ +4.5-9V ON OFF

JTAG/DEBUG port

ARM7-LPC2148 Education board

JX-2148

DEBUG EN.

+3.3V REF GND

12MHz

CTS RTS TxD RxD

UART CH.1

P1.19 P1.18 P1.17 P1.16

G 0.02 0.03 +

TWI-0

PORT

SPI-0

USB 0.25 (D/A) UART CH0 G

G 0.04 0.05 0.06 0.07 +

Connect to serial port

ON USB

32.768kHz LPC2148

+3V BATT

LITIUM BATTERY 3V PIEZO 0.12-0.13 PS/2 0.22 CLK 0.16 DAT 0.15

PORT

1.20 1.21 1.22 1.23

0.21

SWITCH

ISP

0.28

0.29

0.30 (A/D)

Press down to Program Press up to Run

Press switch and observe LED operation

30 l JX-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; // PLL0FEED=0x55; while(!(PLL0STAT & 0x400)) ; // PLL0CON=0x3; PLL0FEED=0xAA; // PLL0FEED=0x55; Feed process Wait until PLL Locked // Connect the PLL as the clock source Feed process

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 LPC2148 input port experiment (continue)

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 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 return : define bit 0 of Port 0

0 or 1 (In case connected switch, switch is pressed - return 0 and exit)


example :

char x; x = inp0(28);

Listing P2-1 : switch.c file of switch project for LPC2148 input port experiment (final)
LPC2148

32 l JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board

Experiment -3 : External Interrupt


This experiment demonstrate how to use External interrupt input port at EINT2 pin (P0.07). Need to construct the addition circuit on breaboard of JX-2148 board below :
Construct this circuit on breadboard

+3.3V

10k P0.07/EINT2 5 S1

LPC2148
+3.3V P0.21 19 LED 0.21
P0.13 P0.12 41 39 220

510
SP1 PIEZO

RESET

BLUETOOTH ESD-02 SD/MMC STATUS

JTAG/DEBUG port

DEBUG EN.

+3.3V REF GND 32.768kHz

12MHz

CTS RTS TxD RxD

UART CH.1

+3V BATT LPC2148

LITIUM BATTERY 3V PIEZO 0.12-0.13 PS/2 0.22 CLK 0.16 DAT 0.15

P1.1 91.1 P 81.1 P 71.1 P 6

G 0.02 0.03 +

TWI-0

PORT

0.25 (D/A) G

SPI-0

G 0.04 0.05 0.06 0.07 +

PORT

10k

1.20 1.21 1.22 1.23

0.21

SWITCH

ISP

0.28

0.29

0.30 (A/D)

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 33

Procedure :
3.1 Build new project, in name ext_int2 3.2 Write the program Listing P3-1. Compile to ext_int2.hex 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. Switch P0.07 pressing is used to control 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 void init() { PLL0CFG=0x24; PLL0FEED=0xAA; PLL0FEED=0x55; PLL0CON=0x1; PLL0FEED=0xAA; PLL0FEED=0x55; while(!(PLL0STAT & 0x400)) ; PLL0CON=0x3; PLL0FEED=0xAA; PLL0FEED=0x55; Initial system clock // // MSEL = 4,PSEL = 2 // Feed process

// Feed process // Wait until PLL Locked // Connect the PLL as the clock source // Feed process

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 LPC2148 external interrupt port experiment (continue)

34 l JX-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 LPC2148 external interrupt port experiment (final)

LPC2148

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 35

Experiment -4 : UART
uart.h library
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 :

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 :

define the transmited character

36 l JX-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...

Experiment -4.1 Transmit data 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 JX-2148.

Procedure :
4.1.1 Build new project, in name uart_0_1 4.1.2 Write the program Listing P4-2. Compile to uart_0_1.hex 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 JX2148 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 UART CH.0 with RS-232 serial port

Test UART1 If connect between UART CH.1 with RS-232 serial port
RESET BLUETOOTH ESD-02 SD/MMC STATUS 12MHz CTS RTS TxD RxD UART CH.1

+ +4.5-9V ON OFF

JTAG/DEBUG port

ARM7-LPC2148 Education board

JX-2148

DEBUG EN.

Connect to serial port*

+3.3V REF GND

P1.19 P1.18 P1.17 P1.16

Connect to serial port*

ON USB

32.768kHz LPC2148

+3V BATT

LITIUM BATTERY 3V PIEZO 0.12-0.13 PS/2 0.22 CLK 0.16 DAT 0.15

G 0.02 0.03 +

TWI-0

PORT

0.25 (D/A) UART CH0 G

SPI-0

USB

G 0.04 0.05 0.06 0.07 +

PORT

1.20 1.21 1.22 1.23

0.21

* In case connect the both serial port in same time, must connect different port and open terminal program separate But if connect not same time, must connect swap and open the terminal program only one window.

SWITCH

ISP

0.28

0.29

0.30 (A/D)

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 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 LPC2148

38 l JX-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; PLL0FEED=0x55;

// Feed process

while(!(PLL0STAT & 0x400)) ; // Wait until PLL Locked PLL0CON=0x3; PLL0FEED=0xAA; PLL0FEED=0x55; // Connect the PLL as the clock source // Feed process

MAMCR=0x2; // Enabling MAM and setting number of clocks used for Flash memory fetch // (4 cclks in this case) MAMTIM=0x4; VPBDIV=0x02; } // 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 } } // PCLK at 30 MHz

Listing P4-2 : uart_0_1.c file of uart_0_1 project for LPC2148 UART experiment

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 39

Figure P4-1 Shows UART0 operation at Hyper Terminal window

Figure P4-2 Shows UART1 operation at Hyper Terminal window


LPC2148

40 l JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board

Experiment - 4.2 : UART operation with interrupt


This experiment demonstrates the UART1 operation with interrupt.

Procedure :
4.2.1 Build new project, in name uart1_int. 4.2.2 Write the program Listing P4-3. Compile to uart1_int.hex 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.
RESET BLUETOOTH ESD-02 SD/MMC STATUS 12MHz CTS RTS TxD RxD UART CH.1

+ +4.5-9V ON OFF

JTAG/DEBUG port

ARM7-LPC2148 Education board

JX-2148

DEBUG EN.

+3.3V REF GND

Connect to serial port

ON USB

32.768kHz LPC2148
P1.19 P1.18 P1.17 P1.16

+3V BATT

LITIUM BATTERY 3V PIEZO 0.12-0.13 PS/2 0.22 CLK 0.16 DAT 0.15

G 0.02 0.03 +

TWI-0

PORT

0.25 (D/A) 7)46+0 G

SPI-0

USB

G 0.04 0.05 0.06 0.07 +

PORT

1.20 1.21 1.22 1.23

0.21

SWITCH

ISP

0.28

0.29

0.30 (A/D)

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.

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 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; PLL0FEED=0x55;

// Feed process

while(!(PLL0STAT & 0x400)) ; // Wait until PLL Locked PLL0CON=0x3; PLL0FEED=0xAA; PLL0FEED=0x55; // Connect the PLL as the clock source // Feed process

MAMCR=0x2; // Enabling MAM and setting number of clocks used for Flash memory fetch // (4 cclks in this case) MAMTIM=0x4; VPBDIV=0x02; } // 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() // PCLK at 30 MHz

Listing P4-3 : uart1_int.c file of uart1_int project for LPC2148 UART experiment (continue)

42 l JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board

{ 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 }

Listing P4-3 : uart1_int.c file of uart1_int project for LPC2148 UART experiment with interrupt (final)

Figure P4-3 Shows the UART1 module data communication function with interrupt

LPC2148

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 43

Experiment -5 : A/D converter


This experiment is demonstration of Analog to digital converter module within LPC2148 operation. Selects AD0.3 pin (P0.30). Read the conversion result to display at the terminal program via UART0. Procedure :
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.
RESET BLUETOOTH ESD-02 SD/MMC STATUS 12MHz CTS RTS TxD RxD UART CH.1

+ +4.5-9V ON OFF

JTAG/DEBUG port

ARM7-LPC2148 Education board

JX-2148

DEBUG EN.

+3.3V REF GND

P1.19 P1.18 P1.17 P1.16

G 0.02 0.03 +

TWI-0

PORT

SPI-0

USB 0.25 (D/A) UART CH0 G

G 0.04 0.05 0.06 0.07 +

Connect to serial port

ON USB

32.768kHz LPC2148

+3V BATT

LITIUM BATTERY 3V PIEZO 0.12-0.13 PS/2 0.22 CLK 0.16 DAT 0.15

PORT

1.20 1.21 1.22 1.23

0.21

SWITCH

ISP

0.28

0.29

0.30 (A/D)

Press down to Program Press up to Run

Adjust analog signal

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 l JX-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 void init() { PLL0CFG=0x24; PLL0FEED=0xAA; PLL0FEED=0x55; PLL0CON=0x1; PLL0FEED=0xAA; PLL0FEED=0x55; Initial system clock // // MSEL = 4,PSEL = 2 // Feed process

// Feed process

while(!(PLL0STAT & 0x400)) ; // Wait until PLL Locked PLL0CON=0x3; PLL0FEED=0xAA; PLL0FEED=0x55; // Connect the PLL as the clock source // Feed process

MAMCR=0x2; // Enabling MAM and setting number of clocks used for Flash memory fetch //(4 cclks in this case) MAMTIM=0x4; VPBDIV=0x02; } // 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 } } // PCLK at 30 MHz

Listing P5-1 : adc.c file of adc project for LPC2148 A/D converter experiment (final)

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 45

Figure P5-1 Shows the result of A/D converter experiment at the Hyper terminal window.

LPC2148

46 l JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board

Experiment - 6 : Real-time Clock in LPC2148


Experiment - 6.1 : RTC interrupt
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.

Procedure :
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.
RESET BLUETOOTH ESD-02 SD/MMC STATUS 12MHz CTS RTS TxD RxD UART CH.1

+ +4.5-9V ON OFF

JTAG/DEBUG port

ARM7-LPC2148 Education board

JX-2148

DEBUG EN.

+3.3V REF GND

Connect to serial port

ON USB

32.768kHz LPC2148
P1.19 P1.18 P1.17 P1.16

+3V BATT

LITIUM BATTERY 3V PIEZO 0.12-0.13 PS/2 0.22 CLK 0.16 DAT 0.15

G 0.02 0.03 +

TWI-0

PORT

0.25 (D/A) UART CH0 G

SPI-0

USB

G 0.04 0.05 0.06 0.07 +

PORT

1.20 1.21 1.22 1.23

0.21

SWITCH

ISP

0.28

0.29

0.30 (A/D)

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 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; PLL0FEED=0x55; // Feed process

while(!(PLL0STAT & 0x400)) ; // Wait until PLL Locked PLL0CON=0x3; PLL0FEED=0xAA; PLL0FEED=0x55; // Connect the PLL as the clock source // Feed process

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 LPC2148 RTC experiment (continuous)

48 l JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board

// 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

Listing P6-1 : rtc_int.c file of rtc_int project for LPC2148 RTC experiment (final)

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 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.

However the operation of this experiment RTC module cannot operate continuous without supply voltage. 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 l JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board

Experiment - 6.2 : Setting 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.

Procedure :
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.
//// // 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; PLL0FEED=0x55;

// Feed process

while(!(PLL0STAT & 0x400)) ; // Wait until PLL Locked PLL0CON=0x3; PLL0FEED=0xAA; PLL0FEED=0x55; // Connect the PLL as the clock source // Feed process

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 }

Listing P6-2 : rtc_setup.c file of rtc_setup project for LPC2148 RTC experiment (continuous)

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 51

// 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

Listing P6-2 : rtc_setup.c file of rtc_setup project for LPC2148 RTC experiment (continuous)

52 l JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board

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); } } }

Listing P6-2 : rtc_setup.c file of rtc_setup project for LPC2148 RTC experiment (final)
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.

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 53

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 operation of this experiment RTC module can operate continuous without supply voltage. 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.

LPC2148

54 l JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board

Experiment -7 : PS/2 Keyboard interface


This experiment is demonstration about interfacing PS/2 keyboard with LPC2148. The heart of this operaion is keyboard.h library file. LPC2148 will get the key value and display at the terminal program via UART1.

keyboard.h library for PS/2 keyboard interfacing


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 keyboard interface


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.

Clock Data
START DATA0 DATA1 DATA2 DATA3 DATA4 DATA5 DATA6 DATA7 PARITY STOP

Figure P7-1 PS/2 keyboard signal timing diagram

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 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 { 0 , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , unsigned char _ascii_key[128] = 0 0 0 0 0 0 0 0 0 0 0 0 11 0 0 0 0 0 0 0 q ! 0 0 0 z s a w @ 0 0 c x d e $ # 0 0 // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F 0x10 0x11 0x12 0x13 0x14 0x15 0x16 0x17 0x18 0x19 0x1A 0x1B 0x1C 0x1D 0x1E 0x1F 0x20 0x21 0x22 0x23 0x24 0x25 0x26 0x27 0x28 // Table for decode

Listing P7-1 Source program of keyboard.h library file (continue)

56 l JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board

, 32 , v , f , t , r , % , 0 , 0 , n , b , h , g , y , ^ , 0 , 0 , 0 , m , j , u , & , * , 0 , 0 , 44 , k , i , o , ) , ( , 0 , 0 , . , / , l , ; , p , - , 0 , 0 , 0 , 39 , 0 , 0 , = , 0 , 0 , 0 , 0 , 13 , ] , 0 , 92 , 0 , 0 , 0 , 0 , 0 , 0

// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //

0x29 0x2A 0x2B 0x2C 0x2D 0x2E 0x2F 0x30 0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38 0x39 0x3A 0x3B 0x3C 0x3D 0x3E 0x3F 0x40 0x41 0x42 0x43 0x44 0x45 0x46 0x47 0x48 0x49 0x4A 0x4B 0x4C 0x4D 0x4E 0x4F 0x50 0x51 0x52 0x53 0x54 0x55 0x56 0x57 0x58 0x59 0x5A 0x5B 0x5C 0x5D 0x5E 0x5F 0x60 0x61 0x62 0x63

Listing P7-1 Source program of keyboard.h library file (continue)

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 57

, 0 , 0 , 8 , 0 , 0 , 1 , 0 , 4 , 7 , 0 , 0 , 0 , 0 , . , 2 , 5 , 6 , 8 , 27 , 0 , 0 , + , 3 , - , * , 9 , 0 , 0 };

// // // // // // // // // // // // // // // // // // // // // // // // // // // //

0x64 0x65 0x66 0x67 0x68 0x69 0x6A 0x6B 0x6C 0x6D 0x6E 0x6F 0x70 0x71 0x72 0x73 0x74 0x75 0x76 0x77 0x78 0x79 0x7A 0x7B 0x7C 0x7D 0x7E 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 l JX-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)

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 59

Key
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9

Pressed key data 1C 32 21 23 24 2B 34 33 43 3B 42 4B 3A 31 44 4D 15 2D 1B 2C 3C 2A 1D 22 35 1A 45 16 1E 26 25 2E 36 3D 3E 46

Released key data

Key
' = \ BKSP Space Tab Caps L Shift L Ctrl L GUI L Alt R Shift R Ctrl R GUI R Alt Apps Enter ESC F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 PrtScn Scroll Pause [ Insert

Pressed key data 0E 4E 55 5D 66 29 0D 58 12 14 E0, 1F 11 59 E0, 14 E0, 27 E0, 11 E0, 2F 5A 76 05 06 04 0C 03 0B 83 0A 01 09 78 07


E0,12, E0, 7C

Released key data

Key
Home Page Up Delete End Page Dwn

Pressed key data E0, 6C E0, 7D E0, 71 E0, 69 E0, 7A E0, 75 E0, 6B E0, 72 E0, 74 77 E0, 4A 7C 7B 79 E0, 5A 71 70 69 72 7A 6B 73 74 6C 75 7D 5B 4C 52 41 49 4A

Released key data

F0, 1C F0, 32 F0, 21 F0, 23 F0, 24 F0, 2B F0, 34 F0, 33 F0, 43 F0, 3B F0, 42 F0, 4B F0, 3A F0, 31 F0, 44 F0, 4D F0, 15 F0, 2D F0, 1B F0, 2C F0, 3C F0, 2A F0, 1D F0, 22 F0, 35 F0, 1A F0, 45 F0, 16 F0, 1E F0, 26 F0, 25 F0, 2E F0, 36 F0, 3D F0, 3E F0, 46

F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C

F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C F0, 1C

NUM KP / KP * KP KP + KP EN KP . KP 0 KP 1 KP 2 KP 3 KP 4 KP 5 KP 6 KP 7 KP 8 KP 9 ] ; ' , . /

7E
E1,14,77,E1, F0,14,F0,77

54 E0, 70

Table P7-1 Keyboard data of PS/2 keyboard

60 l JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board

Operation of isr_int0 function is filter 8-bit data to store in _code 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_getchar function. If detect key pressed, this function will return key value (in condition, that key must support by keyboard.h library). Internal operation of kb_getchar 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_getchar 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.

Procedure :
7.1 Build new project, in name keyboard_ps2. 7.2 Write the program Listing P7-2. Compile to keyboard_ps2.hex 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 JX-2148 board.
RESET BLUETOOTH ESD-02 SD/MMC STATUS 12MHz CTS RTS TxD RxD UART CH.1

+ +4.5-9V ON OFF

JTAG/DEBUG port

ARM7-LPC2148 Education board

JX-2148

DEBUG EN.

+3.3V REF GND

Connect to RS-232 serial port

ON USB

32.768kHz LPC2148
P1.19 P1.18 P1.17 P1.16

+3V BATT

LITIUM BATTERY 3V PIEZO 0.12-0.13 PS/2 0.22 CLK 0.16 DAT 0.15

G 0.02 0.03 +

TWI-0

PORT

0.25 (D/A) 7)46+0 G

SPI-0

USB

G 0.04 0.05 0.06 0.07 +

PORT

1.20 1.21 1.22 1.23

0.21

Connect to PS/2 keyboard


SWITCH

ISP

0.28

0.29

0.30 (A/D)

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 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 void init() { PLL0CFG=0x24; PLL0FEED=0xAA; PLL0FEED=0x55; PLL0CON=0x1; PLL0FEED=0xAA; PLL0FEED=0x55; Initial system clock //

// MSEL = 4,PSEL = 2 // Feed process

// Feed process

while(!(PLL0STAT & 0x400)) ; // Wait until PLL Locked PLL0CON=0x3; PLL0FEED=0xAA; PLL0FEED=0x55; // Connect the PLL as the clock source // Feed process

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 LPC2148 RTC experiment

62 l JX-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.

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 63

Experiment -8 : Graphic LCD interface


This experiment is demonstration about interfacing GLCD5110 Graphic LCD.PS/2 keyboard with LPC2148.

GLCD5110 : Graphic LCD 84x48 pixel


features l Graphic LCD module # LPH7366. Resolution is 84 x 48 pixel. l Built-in PCD8544 controller with SPI interface bus. l Built-in the backlight blue LED controlled by software l Supply voltage range is +3 to +3.3V. Maximum current is 10mA (with backlight
LED)

l Display the standard size 5x7 pixel character up to 14 characters 6 lines and
mono-tone graphic image.

l Size is 4.5 x 4.5 cm. l Easy to connection l 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 library 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 : GLCD5110 LPC2148 port

SDIN SCLK SCE RESET D/C LED

P0.06 P0.07 P1.20 P0.04 P0.05 P1.21

64 l JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board

45mm. 39mm. 1

39mm. 45mm.

Pin
1 2 3 4 5

Name
Vcc GND SCE RESET D/C

Function
Supply voltage +2.7 to +3.3V Ground Enable pin - active low Reset pin - active low Data/Command selection pin "0" - Write data display "1" - Write command Serial data input pin Clock input pin Backlight LED control pin - active high (inclued limit current resistor 330 )

6 7 8

SDIN SCLK LED

Figure P8-1 Size and Pin assignment of GLCD5110 module

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 65

OUTPUT port OUTPUT port OUTPUT port SDO/MOSI SCK RESET SDIN +3.3V SCLK GND SCE D/C LED OUTPUT port

Figure P8-2 How to interface GLCD5110 with microcontroller

66 l JX-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 #endif #define FALSE #define TRUE

0 1 84 48 ((LCD_X_RES * LCD_Y_RES) / 8)

#define LCD_X_RES #define LCD_Y_RES

#define LCD_CACHE_SIZE 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 = PIXEL_ON = PIXEL_XOR = }lcdPixelMode; /* Public function prototypes */ void lcdInit(void); void lcdClear(void); void lcdUpdate(void); void lcdGotoXY(byte x,byte y);

0, 1, 2

Listing P8-1 Source program of glcd5110.h library file (continue)

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 67

void void void void void void

lcdChar(byte ch); lcdString(byte _x,byte _y,byte *dataPtr); lcdPixel(byte x, byte y, lcdPixelMode mode); lcdLine(byte x1, byte y1, byte x2, byte y2, lcdPixelMode mode); configGlcd(); 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

Listing P8-1 Source program of glcd5110.h library file (continue)

68 l JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board

{ { { { { { { { { { { { { { { { { { { { { { { { { { { { { { { { { { { { { { { { { { { { { {

0x7F, 0x7F, 0x3E, 0x7F, 0x3E, 0x7F, 0x46, 0x01, 0x3F, 0x1F, 0x3F, 0x63, 0x07, 0x61, 0x00, 0x55, 0x00, 0x04, 0x40, 0x00, 0x20, 0x7F, 0x38, 0x38, 0x38, 0x08, 0x0C, 0x7F, 0x00, 0x20, 0x7F, 0x00, 0x7C, 0x7C, 0x38, 0x7C, 0x08, 0x7C, 0x48, 0x04, 0x3C, 0x1C, 0x3C, 0x44, 0x0C, 0x44,

0x02, 0x04, 0x41, 0x09, 0x41, 0x09, 0x49, 0x01, 0x40, 0x20, 0x40, 0x14, 0x08, 0x51, 0x7F, 0x2A, 0x41, 0x02, 0x40, 0x01, 0x54, 0x48, 0x44, 0x44, 0x54, 0x7E, 0x52, 0x08, 0x44, 0x40, 0x10, 0x41, 0x04, 0x08, 0x44, 0x14, 0x14, 0x08, 0x54, 0x3F, 0x40, 0x20, 0x40, 0x28, 0x50, 0x64,

0x0C, 0x08, 0x41, 0x09, 0x51, 0x19, 0x49, 0x7F, 0x40, 0x40, 0x38, 0x08, 0x70, 0x49, 0x41, 0x55, 0x41, 0x01, 0x40, 0x02, 0x54, 0x44, 0x44, 0x44, 0x54, 0x09, 0x52, 0x04, 0x7D, 0x44, 0x28, 0x7F, 0x18, 0x04, 0x44, 0x14, 0x14, 0x04, 0x54, 0x44, 0x40, 0x40, 0x30, 0x10, 0x50, 0x54,

0x02, 0x10, 0x41, 0x09, 0x21, 0x29, 0x49, 0x01, 0x40, 0x20, 0x40, 0x14, 0x08, 0x45, 0x41, 0x2A, 0x7F, 0x02, 0x40, 0x04, 0x54, 0x44, 0x44, 0x48, 0x54, 0x01, 0x52, 0x04, 0x40, 0x3D, 0x44, 0x40, 0x04, 0x04, 0x44, 0x14, 0x18, 0x04, 0x54, 0x40, 0x20, 0x20, 0x40, 0x28, 0x50, 0x4C,

0x7F 0x7F 0x3E 0x06 0x5E 0x46 0x31 0x01 0x3F 0x1F 0x3F 0x63 0x07 0x43 0x00 0x55 0x00 0x04 0x40 0x00 0x78 0x38 0x20 0x7F 0x18 0x02 0x3E 0x78 0x00 0x00 0x00 0x00 0x78 0x78 0x38 0x08 0x7C 0x08 0x20 0x20 0x7C 0x1C 0x3C 0x44 0x3C 0x44

}, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }

// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //

M N O P Q R S T U V W X Y Z [ 55 ] ^ _ a b c d e f g h i j k l m n o p q r s t u v w x y 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++ ); }

Listing P8-1 Source program of glcd5110.h library file (continue)

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 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; HiWaterMark = 0; lcdClear(); lcdUpdate(); // Reset watermark pointers.

} /* 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 P8-1 Source program of glcd5110.h library file (continue)

70 l JX-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 P8-1 Source program of glcd5110.h library file (continue)

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 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; // } if ( index > HiWaterMark ) { // HiWaterMark = index; } }

Update low marker.

Update high marker.

Listing P8-1 Source program of glcd5110.h library file (continue)

72 l JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board

/* 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; }

Listing P8-1 Source program of glcd5110.h library file (continue)

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 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 P8-1 Source program of glcd5110.h library file (continue)

74 l JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board

{ 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, lcdLine(x1, lcdLine(x1, lcdLine(x2, }

y1, y2, y1, y1,

x2, x2, x1, x2,

y1, y2, y2, y2,

color); color); color); color);

// Draw the 4 sides

} // 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

Listing P8-1 Source program of glcd5110.h library file (final)

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 75

GLCD5110 library function 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 l JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board

example :

#include lpc214x.h #include glcd5110.h ................. void main() { ............... lcdGotoXY(12,2); // lcdChar(N); // lcdChar(o); // lcdChar(k); // lcdChar(i); // lcdChar(a); // lcdChar(5); // lcdChar(1); // lcdChar(1); // lcdChar(0); // lcdUpdate(); // ................ }
Result :

Set display position at Column 12 Line 2 Display N at Column 12 Line 2 Display o at Column 13 Line 2 Display k at Column 14 Line 2 Display i at Column 1 Line 3 Display a at Column 2 Line 3 Display 5 at Column 3 Line 3 Display 1 at Column 4 Line 3 Display 1 at Column 5 Line 3 Display 0 at Column 6 Line 3 Update screen

Line Line Line Line Line Line

1 2 3 4 5 6

00000000000000 00000000000Nok ia511000000000 00000000000000 00000000000000 00000000000000




Column 12

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 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); // lcdString(1,4,Line 4 Demo); // lcdUpdate(); // ................ } Result :


Display message on Line 1 Display message on Line 4 Update screen

Line Line Line Line Line Line

1 2 3 4 5 6

Hello0world000 00000000000Nok ia511000000000 Line040Demo000 00000000000000 00000000000000




78 l JX-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

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 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 l JX-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)

83 pixels width

Shadow 70% of width

5 pixels height

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 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); // lcdString(1,2,0123456789"); // lcdUpdate(); // delay_ms(2000); // lcdClear(); // lcdString(1,1,This is test); // lcdString(1,2,DELAY 2 sec); // lcdUpdate(); // ................ }

Displays message Line 1 Displays message Line 2 Update screen Delay 2000 ms. (2 second) Clear screen Displays message Line 1 Displays message Line 2 Update screen

82 l JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board

Experiment -8.1 Simple message display on GLCD


Procedure :
8.1.1 Build new project, in name glcd01_01. 8.1.2 Write the program Listing P8-2. Compile to glcd_01.hex and download to microcontroller. Close LPC2000 Flash Utility program.

P0.07 P0.06

31 30 29 27 40 44

IC3 LPC2148

P0.05 P0.04 P1.22 P1.21

RESET

SDIN

SCLK

GND

5
C5 15pF C6 33pF +3.3V XTAL1 32.768kHz

+3.3V RTCX2 1

62 X1 61 X2 63 Vref 23 43 51 7

C7 33pF

XTAL2 12MHz

JP2 8HAB

+3.3V GND

+3.3V D2 1N5819 C8 C9 C8-C10 0.1 F x3 D3 1N5819 BATT1 +3V C10

Vdd3-1(I/O) Vdd3-2(I/O) Vdd3-3(I/O) Vdd3(A)

DSP1 GLCD5110

59 VssA 49 Vbat

IC5 MAX3232 C17 0.1 F C18 0.1 F 1 3 4 5

+3.3V 16 V+ VR1I T1O R2I

C16 0.1 F 15 2 6 7 8 13 C19, C20 0.1 F x2 1 2 3 4 5 K7 6 7 8 9

Vdd C1+ C1C2+

P0.01/RxD0 P0.00/TxD0 P0.14/BSL

21 19 +3.3V
R21 10k

41 SW2 4-5-6

R22 22k

+3.3 V R20 1k

C210 R1O 9 T1I 12 R2O

R23 47 RST IC6 KIA7031 GND

ISP
+V +3.3 V

SW3

LED UART0 RS-232 ISP

SCE

RST

57

Vss1 Vss2 Vss3 Vss4 6 18 25 12

Figure P8-2 GLCD5110 experiment circuit with LPC2148

D/C

C4 15pF

RTCX1

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 83

ON OFF

ARM7-LPC2148 Education board

JX-2148

DEBUG EN.

+3.3V REF GND

12MHz

CTS RTS TxD RxD

UART CH.1

ON USB

32.768kHz LPC2148
P1.19 P1.18 P1.17 P1.16 G 0.02 0.03 +

+3V BATT

LITIUM BATTERY 3V PIEZO 0.12-0.13 PS/2 0.22 CLK 0.16 DAT 0.15

TWI-0

PORT

0.25 (D/A) 7)46+0 G

SPI-0

USB

G 0.04 0.05 0.06 0.07 +

PORT

1.20 1.21 1.22 1.23

0.21

SWITCH

ISP

0.28

0.29

0.30 (A/D)

Figure P8-3 Circuit construction on JX-2148 board for GLCD5110 experiment


8.1.3 Connect LPC2148 port to GLCD5110 as follows : GLCD5110 LPC2148 port

SDIN SCLK SCE RESET D/C LED


8.1.4 Run program

P0.06 P0.07 P1.20 P0.04 P0.05 P1.21

At GLCD5110 screen shows message as follows :




JX - 21480000000 Graphic0LCD000 Nokia051100000 -------------00012345678900 ABCDEFGHIJKLMN




LED back light is blinked with 0.5 second.

84 l JX-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; PLL0FEED=0x55; while(!(PLL0STAT & 0x400)) ; PLL0CON=0x3; PLL0FEED=0xAA; PLL0FEED=0x55; MAMCR=0x2; MAMTIM=0x4; VPBDIV=0x02; } // Main Program // void main() { int cnt,i=0; // Counter variable constchar *pText1 = JX-2148; // Store message in Program constchar *pText2 = Graphic LCD; // Store message in Program constchar *pText3 = Nokia 5110; // Store message in Program init(); // Initialize the system SCS = 0x03; // select the fast version of the I/O lcdString(1,1,pText1); lcdString(1,2,pText2); lcdString(1,3,pText3); lcdUpdate(); lcdGotoXY(1,4); for (cnt=0; cnt<14; cnt++) { lcdChar(-); } // // // // Set message on line 1 Set message on line 2 Set message on line 3 Display message // PCLK at 30 MHz

// Feed process

// Wait until PLL Locked // Connect the PLL as the clock source // Feed process

// Enabling MAM and setting number of clocks // used for Flash memory fetch // (4 cclks in this case)

memory memory memory ports

// Go to (1,4) // Loop for set - on line 4

Listing P8-2 : glcd_01.c file of GLCD5110 simple message display for LPC2148 experiment (continue)

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 85

lcdUpdate(); lcdGotoXY(3,5); for (cnt='0'; cnt<='9'; cnt++) { lcdChar(cnt); } lcdUpdate(); lcdGotoXY(1,6); for (cnt'A'; cnt<'N'; cnt++) { lcdChar(cnt); } lcdUpdate(); while(1) { lcdBackLight(1); delay_ms(500); lcdBackLight(0); delay_ms(500); } }

// Display message // Go to (3,5) // Loop for set 0-9' on line 5

// Display message // Go to (1,6) // Loop for set A-N on line 6

// Display message // Infinite loop // // // // BackLight Delay 500 BackLight Delay 500 ON ms OFF ms

Listing P8-2 : glcd_01.c file of GLCD5110 simple message display for LPC2148 experiment (final)

Experiment -8.2 Simple graphic display on GLCD


Procedure :
8.2.1 Build new project, in name glcd_02. 8.2.2 Write the program Listing P8-3. Compile to glcd_02.hex 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 l JX-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; PLL0FEED=0x55;

// Feed process

while(!(PLL0STAT & 0x400)) ; // Wait until PLL Locked PLL0CON=0x3; PLL0FEED=0xAA; PLL0FEED=0x55; // Connect the PLL as the clock source // Feed process

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 P8-3 : glcd_02.c file of GLCD5110 simple graphic display for LPC2148 experiment

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 87

Experiment -8.3 Analog display 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.

P0.07 P0.06
+3.3V

31 30 29 27 40 44

P0.05 15 P0.04 P0.30 P1.22 P1.21

VR1-10k ADC 0.30

IC3 LPC2148
C4 15pF

RESET

SDIN

SCLK

GND

+3.3V

1 3 5
C5 15pF C6 33pF +3.3V XTAL1 32.768kHz

RTCX1 RTCX2 X1 X2 Vref

62 61

C7 33pF

XTAL2 12MHz

DSP1 GLCD5110

JP2 8HAB

+3.3V GND

63

+3.3V D2 1N5819 C8 C9 C8-C10 0.1 F x3 D3 1N5819 BATT1 +3V C10

23 43 51 7

Vdd3-1(I/O) Vdd3-2(I/O) Vdd3-3(I/O) Vdd3(A)

59 VssA 49 Vbat

IC5 MAX3232 C17 0.1 F C18 0.1 F 1 3 4 5

+3.3V 16 V+ VR1I T1O R2I

C16 0.1 F 15 2 6 7 8 13 C19, C20 0.1 F x2 1 2 3 4 5 K7 6 7 8 9

Vdd C1+ C1C2+

P0.01/RxD0 P0.00/TxD0 P0.14/BSL

21 19 +3.3 +3.3V V R20 1k


R22 22k

C210 R1O 9 T1I 12 R2O

41 SW2 4-5-6

R21 10k

R23 47 RST IC6 KIA7031 GND

ISP
+V +3.3 V

SW3

LED UART0 RS-232 ISP

SCE

RST Vss1 Vss2 Vss3 6 18 25 Vss4 12

57

Figure P8-4 Graphic display creation experiment for LPC2148

D/C

88 l JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board

Procedure :
8.3.1 Build new project, in name glcd_03. 8.3.2 Write the program Listing P8-4. Compile to glcd_03.hex 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; PLL0FEED=0x55;

// Feed process

while(!(PLL0STAT & 0x400)) ; // Wait until PLL Locked PLL0CON=0x3; PLL0FEED=0xAA; 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; } // 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); } // PCLK at 30 MHz // Connect the PLL as the clock source // Feed process

Listing P8-4 : glcd_03.c file of GLCD5110 graphic display with A/D converter for LPC2148 experiment (continue)

JX-2148 : LPC2148 ARM7-32 bit Microcontroller Education board l 89

// 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) { adc_val = analog(); percentage = (adc_val*100)/1023; sprintf(str_adc,(A/D): %d lcdString(1,1,str_adc); sprintf(str_percentage,%d%% lcdString(7,3,str_percentage); // Set percentage value display on line 3 lcdProgBar(0,10,83,5,percentage); lcdUpdate(); } } // Display progress bar at // (0,10),width 83 pixel,high 5 pixel // Display message // Infinite loop // Get analog value from A/D 0.30 // Calculate to percentage

,adc_val); // Convert string to display analog value // Set analog value display on line 1 ,percentage); // Convert string to display percentage

Listing P8-4 : glcd_03.c file of GLCD5110 graphic display with A/D converter for LPC2148 experiment (final)
8.3.3 Run program. Adjust the variable resistor on JX-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.


A/D:1002000000 Nokia097% 0000 -------------00012345678900 ABCDEFGHIJKLMN




Anda mungkin juga menyukai