You are on page 1of 43

Embedded System Lab Manual 18ECL66 Sem: VI

R T E Society’s
Rural Engineering College Hulkoti
Department of Electronics & Communication Engineering
---------------------------------------------------------------------------------------------------------------------------
-

Lab Manual

Embedded System Lab


Lab Code: 18ECL66
Semester: VI

Prepared by

Prof. Asif Iqbal M

Lab Instructor

Ameer Betageri

DEPT OF E&C, REC, HULKOTI 1


Embedded System Lab Manual 18ECL66 Sem: VI

Syllabus

PART-A: Conduct the following Study experiments to learn ALP using ARM Cortex M3 Registers using
an Evaluation board and the required software tool.
1. ALP to multiply two 16 bit binary numbers.
2. ALP to find the sum of first 10 integer numbers.
3. ALP to find the number of O's and 1's in a 32 bit data
4. ALP to find determine whether the given 16 bit is even or odd
5. ALP to write data to RAM

PART-B: Conduct the following experiments on an ARM CORTEX M3 evaluation board using
evaluation version of Embedded 'C' & Keil Uvision-4 tool/compiler.

6. Display “Hello World” message using Internal UART.

7. Interface and Control a DC Motor.

8. Interface a Stepper motor and rotate it in clockwise and anti-clockwise direction.

9. Interface a DAC and generate Triangular and Square waveforms.

10. Interface a 4x4 keyboard and display the key code on an LCD.

11. Demonstrate the use of an external interrupt to toggle an LED On/Off.

12. Display the Hex digits 0 to F on a 7-segment LED interface, with an appropriate delay in between.

13. Measure Ambient temperature using a sensor and SPI ADC IC.

Keil Micro Vision® 5 IDE tool : Step by step Tutorial

This chapter describes the Build Mode of µVision and explains the user interface; outlines the options for
generating and maintaining projects, including output file options, and highlights configuration options for
optimum code quality.

The required steps for creating application programs are listed below:

1. Package Installer File explains how to install LPC1768 device to µVision5 project file.
2. Create Project File explains how to create a µVision5 project file.
DEPT OF E&C, REC, HULKOTI 2
Embedded System Lab Manual 18ECL66 Sem: VI

3. Select Device describes how tool settings, peripherals, and dialogs are customized.
4. Set Options for Target explains how to specify relevant parameters for your target.
5. Create Source File describes how to add new files to the project.
6. Configure a Target

Configure Cortex-M Target describes how to change the startup-code and how to use the library
retarget file for Cortex-M devices. In addition, this is a brief explanation of CMSIS.

7. Create File Group explains how to structure the code files for a better overview.
8. Specify Memory Layout describes how to change file and group attributes.
9. Build Project describes the build-options.

Package Installer:

1. Select Project - NewµVision Project from the µVision menu.


This opens a standard Windows dialog, which prompts you for the new project file
2. Now Scroll down to Manage-Pack installer

3 In Pack Installer select NXP - LPC1700 Series. Click on Install in Action menu so as to

Up- Date the Device series

DEPT OF E&C, REC, HULKOTI 3


Embedded System Lab Manual 18ECL66 Sem: VI

Create Project File

µVision5 maintains the files that belong to a project in one project file. It takes only a few steps to create a
new project file with µVision4:

1. Select Project - New Project from the µVision5 menu.


This opens a standard Windows dialog, which prompts you for the new project file name.

2. Create a new folder Test.

3. Switch to the new folder and type the project name Test1. µVision4 automatically adds the extension
.uvproj.
4. Click Save & Select Device for Target ‘Target 1’ is opened, select NXP

When you create a new project, µVision4 asks you to select a microcontroller. This step customizes
DEPT OF E&C, REC, HULKOTI 4
Embedded System Lab Manual 18ECL66 Sem: VI

the µVision4 environment with pre-configured options and sets the tool options, peripherals, and
dialogs for that particular device. The Select Device for Target dialog shows the µVision Device
Database.

Select the microcontroller you use. For this example, choose the NXP(founded by philips)

Select the device LPC-1768 and click OK as shown below above

5 Now Manage Run Time Environment window will open as shown in the fig below.

 Expand CMSIS option and select the CORE by selecting the check box.
 Expand Divice option and select the Startup by selecting the check box.

DEPT OF E&C, REC, HULKOTI 5


Embedded System Lab Manual 18ECL66 Sem: VI

6 Now the Target is created. Right Click on Target1 and Select Option for Target ‘Target1’…..
OR Press Alt+F7

7 Now the Option for Target ‘Target1’window will open.

a. Select the Xtal (MHz):12.0 in Target Menu

DEPT OF E&C, REC, HULKOTI 6


Embedded System Lab Manual 18ECL66 Sem: VI

b. Select Create HEX File Check box in Output menu

c. Enter R/W Base address as 0x10000000 in Linker Menu.

DEPT OF E&C, REC, HULKOTI 7


Embedded System Lab Manual 18ECL66 Sem: VI

8 Click on new document for writing the program & save the code with .c extension in desired folder.

DEPT OF E&C, REC, HULKOTI 8


Embedded System Lab Manual 18ECL66 Sem: VI

9 Expand the Target 1 in the Project folder

DEPT OF E&C, REC, HULKOTI 9


Embedded System Lab Manual 18ECL66 Sem: VI

10 Right click on the source Group1 & select Add Files to Group ‘Source Group 1’.
Select the file from the folder where project is saved & click on add.

Build Project

Build the project once the coding is done and check for errors. For building the project click F7 or click on
below shown option.

DEPT OF E&C, REC, HULKOTI 10


Embedded System Lab Manual 18ECL66 Sem: VI

1. Translate and link the source files of the application with a click on one of the build-buttons
located in the Build Toolbar.
2. Errors or warnings are displayed in the Build Output Window. Double-click on a message to jump to
the line where the incident occurred.

3. Once you have generated your application successfully, you can start debugging.

Down loading Hex File to LPC 1768

Installation Steps for Flash Magic Software


1. Click on the Setup File

2. Double Click on the exe file

3. Click Next and accept the agreement

DEPT OF E&C, REC, HULKOTI 11


Embedded System Lab Manual 18ECL66 Sem: VI

DEPT OF E&C, REC, HULKOTI 12


Embedded System Lab Manual 18ECL66 Sem: VI

Click on Install

Click on the Flash Magic Icon installed over desktop

DEPT OF E&C, REC, HULKOTI 13


Embedded System Lab Manual 18ECL66 Sem: VI

Click on Select Device Button, expand ARM Cortex option & select the device LPC-1768

5 Select the COM Port Name, follow these Steps for knowing the PORT Name

a. Insert one end of the USB cable to the USB Port and Other end to kit.

b. Right Click on My Computer option from the desktop and select Manage Option as shown in
the below figure.

DEPT OF E&C, REC, HULKOTI 14


Embedded System Lab Manual 18ECL66 Sem: VI

c. Click on Manage button and select the Device Manager Option as shown below

d. Expand Ports option on the right hand side to see the Serial port name of the USB Connected.
For Example : USB Serial Port(COM8)

DEPT OF E&C, REC, HULKOTI 15


Embedded System Lab Manual 18ECL66 Sem: VI

6 Once the PORT name is known Select from COM Port dropdown, Set the Baud Rate and Oscillator
(MHz) to 115200 and 12.0 respectively & check the Erase Flash+Code Rd prot Used by Hex file.

7 Select the program from the desktop machine on click of Browse button

DEPT OF E&C, REC, HULKOTI 16


Embedded System Lab Manual 18ECL66 Sem: VI

8 Once the program is selected click on the Start Button for downloading the code. Program is
downloaded through USB Port & check for the desired Output.

9 Now Press the Reset Button on VTCM3_B_1 kit and check for the desired output.

Register Configuration
LPC1768 has its GPIOs divided into five ports PORT0 - PORT4, although many of them are not
physically 32bit wide. Refer the data sheet for more info. The Below registers will be used for
Configuring and using the GPIOs registers for sending and receiving the Digital signals. A structure
LPC_GPIOn(n= 0,1,2,3) contains all the registers for required for GPIO operation. Refer lpc17xx.h
file for more info on the registers.

LPC1768 GPIO
PINSEL FIODIR FIOSET, FIOCLR, FIOPIN
Selects Pin Function Configure Pin Access the Port Pin
Direction

DEPT OF E&C, REC, HULKOTI 17


Embedded System Lab Manual 18ECL66 Sem: VI

PINSEL: GPIO Pins Select Register Almost all the LPC1768 pins are multiplexed to
support more than 1 function. Every GPIO pin has a minimum of one function and max of four
functions. The required function can be selected by configuring the PINSEL register. As there
can be up to 4 functions associated with a GPIO pin, two bits for each pin are available to select
the function. This implies that we need two PINSEL registers to configure a PORT pins. By this
the first 16(P0.0-P0.16) pin functions of PORT0 can be selected by 32 bits of PINSELO register.
The remaining 16 bits(P0.16-P0.32) are configured using 32bits of PINSEL1 register. As mentioned
earlier every pin has max of four functions. Below table shows how to select the function for a
particular pin using two bits of the PINSEL register.

Value Function Enumeration


00 Primary (default) function, typically GPIO PINSEL_FUNC_0
port
01 First alternate function PINSEL_FUNC_1
10 Second alternate function PINSEL_FUNC_2
11 Third alternate function PINSEL_FUNC_3

FIODIR:Fast GPIO Direction Control Register.

This register individually controls the direction of each port pin.

Values Direction
0 Input
1 Output

FIOSET:Fast Port Output Set Register.


This register controls the state of output pins. Writing 1s produces highs at the corresponding port
pins. Writing 0s has no effect. Reading this register returns the current contents of the port output
register not the physical port value.

Values FIOSET
0 No Effect
1 Sets High on Pin
FIOCLR:Fast Port Output Clear Register.

This register controls the state of output pins. Writing 1s produces lows at the corresponding port
pins. Writing 0s has no effect.

Values FIOCLR
0 No Effect
1 Sets Low on Pin

FIOPIN:Fast Port Pin Value Register .

This register is used for both reading and writing data from/to the
PORT. Output: Writing to this register places corresponding values in all bits of the
particular PORT pins. Input: The current state of digital port pins can be read from this register,
regardless of pin direction or alternate function selection (as long as pins are not
DEPT OF E&C, REC, HULKOTI 18
Embedded System Lab Manual 18ECL66 Sem: VI

configured as an input to ADC). Note:It is recommended to configure the PORT


direction and pin function before using it.

GPIO Registers in LPC1768

Registers on LPC1768 are present on Peripheral AHB bus(Advanced High performance Bus) for fast
read/write timing. So, these are basically Fast I/O or Enhanced I/O and hence the naming
convention in datasheet uses a prefix of “FIO” instead of something like “GIO” for all the registers
related to GPIO. Lets go through these as given below.

1) FIODIR : This is the GPIO direction control register. Setting a bit to 0 in this register will configure
the corresponding pin to be used as an Input while setting it to 1 will configure it as Output.

2) FIOMASK : This gives masking mechanism for any pin i.e. it is used for Pin access control. Setting
a bit to 0 means that the corresponding pin will be affected by changes to other registers like
FIOPIN, FIOSET, FIOCLR. Writing a 1 means that the corresponding pin won‟t be affected by other
registers.

3) FIOPIN : This register can be used to Read or Write values directly to the pins. Regardless of the
direction set for the particular pins it gives the current start of the GPIO pin when read.

4) FIOSET : It is used to drive an „output‟ configured pin to Logic 1 i.e HIGH. Writing Zero does
NOT have any effect and hence it cannot be used to drive a pin to Logic 0 i.e LOW. For driving pins
LOW FIOCLR is used which is explained below.

5) FIOCLR : It is used to drive an „output‟ configured pin to Logic 0 i.e LOW. Writing Zero does NOT
have any effect and hence it cannot be used to drive a pin to Logic 1.

Most of the PINS of LPC176x MCU are Multiplexed i.e. these pins can be configured to provide up
to 4 different functions. By default, after Power-On or Reset : all pins of all ports are set as GPIO
so we can directly use them when learning GPIO usage. The different functions that any particular
pin provides can be selected by setting appropriate value in the PINSEL register for the
corresponding pin. Each pin on any port has 2 corresponding bits in PINSEL register. The first 16
pins (0-15) on a given port will have a corresponding 32 bit PINSEL register and the rest 16 bits will
have another register. For example bits 0 & 1 in PINSEL0 are used to select function for Pin 1 of
Port 0, bits 2 & 3 in PINSEL0 are used to select function for PIN 2 of port 0 and so on. The same is
applicable for PINMODE register which will go through in last section of this article. Have a look at
the diagram given below.
PINSEL0 Register

31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
P0.15 P0.14 P0.13 P0.12 P0.11 P0.10 P0.9 P0.8 P0.7 P0.6 P0.5 P0.4 P0.3 P0.2 P0.1 P0.0

PINSEL1

31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
P0.31 P0.30 P0.29 P0.28 P0.27 P0.26 P0.25 P0.24 P0.23 P0.22 P0.21 P0.20 P0.19 P0.18 P0.17 P0.16

DEPT OF E&C, REC, HULKOTI 19


Embedded System Lab Manual 18ECL66 Sem: VI

Example : Port 0.0 pin‟s function is decided by contents of PINSEL0 register bit 0 and bit 1

P0.0 function decided by P0.0


Function as
PINSEL0.1 PINSEL0.0
0 0 when PINSEL0.1= 0 , PINSEL0.0= 0 Then P0.0 Function as General Purpose
I/O
0 1 when PINSEL0.1= 0, PINSEL0.0= 1 Then P0.0 Function as RD1
1 0 when PINSEL0.1= 1, PINSEL0.0= 0 Then P0.0 function as TXD3
1 1 when PINSEL0.1= 1, PINSEL0.0= 1 Then P0.0 function as SDA1

Since by default all pins are configured as GPIOs we don‟t need to explicitly assign a „0‟
value to PINSEL register in Programming examples.

DEPT OF E&C, REC, HULKOTI 20


Embedded System Lab Manual 18ECL66 Sem: VI

PART-A EXPERIMENTS

EXPERMENT No 1

; Multiplying two 16-bit number


; The 32-bit result stored in register R2

AREA MYCODE, CODE


ENTRY
EXPORT __main

__main
mov r0,#0x0004
mov r1,#0xffff
mul r2,r0,r1

HERE B HERE
END

Result:

DEPT OF E&C, REC, HULKOTI 21


Embedded System Lab Manual 18ECL66 Sem: VI

EXPERMENT No 2

;addition of 10 numbers 1 to 10
;The result of addition is stored in r2

AREA MYCODE, CODE


ENTRY
EXPORT __main

__main
mov r0,#0
mov r1,#1
loop1 add r0,r1
add r1,#1
cmp r1,#0x0b
bne loop1

HERE B HERE
END

Result:

DEPT OF E&C, REC, HULKOTI 22


Embedded System Lab Manual 18ECL66 Sem: VI

EXPERMENT No 3

; Finding number of zeros and ones in given 32-bit number


; r3 holds 32-bit number
; r1 holds number zeros
; r2 holds number ones

AREA MYCODE, CODE


ENTRY
EXPORT __main
__main
mov r0,#0x20
mov r1,#0
mov r2,#0
mov r3,#0xFFF0
movt r3,#0xFFFF
loop RORS r3,r3,#1
bcs ones1
add r1,r1,#1
b next
ones1 add r2,r2,#1
next subs r0,r0,#1
bne loop

HERE B HERE
END
Result:

DEPT OF E&C, REC, HULKOTI 23


Embedded System Lab Manual 18ECL66 Sem: VI

EXPERMENT No 4
; Finding number given 16-bit number odd or even
; r3 holds 16-bit number
; r1 holds number 0xAA if number is even
; r1 holds number 0xff if number is odd

AREA MYCODE, CODE


ENTRY
EXPORT __main
__main
mov r1,#0
mov r3,#0x1236
loop lsrs r3,#1
bcs odd
mov r1,#0xAA
b HERE
odd mov r1,#0xff

HERE B HERE

END

Result:

DEPT OF E&C, REC, HULKOTI 24


Embedded System Lab Manual 18ECL66 Sem: VI

EXPERMENT No 5
; Writing data to RAM using different store instructions

AREA myData, DATA


data DCW 0

AREA MYCODE, CODE


ENTRY
EXPORT __main
__main
mov r0,#0x20
mov r1,#0x1234
mov r2,#0x2211
movt r2,#0x4433
mov r3,#0xDDCC
movt r3,#0xFFEE

ldr r4,=data
strb r2,[r4]
strh r2,[r4,#4]
str r2,[r4,#8]
strd r2,r3,[r4,#12]

HERE B HERE

END
Result :

DEPT OF E&C, REC, HULKOTI 25


Embedded System Lab Manual 18ECL66 Sem: VI

PART-B EXPERIMENTS

LED Pin Configuration


VTCM3_3board provides eight individual SMD led’s connected to LPC-1768 device through
74HC151driver IC. D1 to D8 are connected to general purpose I/O pins on LPC-1768 device as
shown in table(14) When LPC-1768 device drives Logic ‘1’ the corresponding LED turns on.

LED Pin connection table.

LED D1 D2 D3 D4 D5 D6 D7 D8
LPC-1768
81 80 79 78 77 76 48 49
Pin No
LPC-1768
P0.4 P0.5 P0.6 P0.7 P0.8 P0.9 P0.10 P0.11
Port No

SEVEN SEGMENT DIPLAY Pin Configuration:

D11, D12, D13 and D14 are Common Cathode segments connected to LPC-1768 device so that
each segment is individually controlled by a general purpose I/O pin. When the LPC-1768 device
drives logic ‘0’ the corresponding segment turns on. See fig and table for more details.

DEPT OF E&C, REC, HULKOTI 26


Embedded System Lab Manual 18ECL66 Sem: VI

D9 D10 D11 D12


Seven Segment Pin connection table.

Seven
Segment g f a b p c d e
Data Lines
LPC-1768 Pin
75 74 73 70 69 68 67 66
No
LPC-1768
P2.7 P2.6 P2.5 P2.4 P2.3 P2.2 P2.1 P2.0
Port No

SEVEN SEGMENT Selection Pin Configurations:


As VTCM3_3 board comes with 4 digit seven segment unit. Displays connected to the microcontroller
usually occupy a large number of valuable I/O pins, which can be a big problem especially if it is needed to
display multi digit numbers. The problem is more than obvious if, for example, it is needed to display four
digit numbers (a simple calculation shows that 32 output pins are needed in this case). The solution to this
problem is called MULTIPLEXING. This is how an optical illusion based on the same operating principle
as a film camera is made. Only one digit is active at a time, but they change their state so quickly making
impression that all digits of a number are simultaneously active. Each digit can made active using
switching transistors Q1, Q2, Q3 and Q4 and these on switched on and off by selection lines which are in
turn connected to LPC-1768 ports. Table shows the details of seven segment selection lines.
Seven Segment Selection table.

Seven Segment Disp1 Disp2 Disp3 Disp4


Selection Lines (D9) (D10) (D11) (D12)
LPC-1768 Pin No 40 43 44 45
LPC-1768 Port No P1.26 P1.27 P1.28 P1.29

Display Encoding:

DEPT OF E&C, REC, HULKOTI 27


Embedded System Lab Manual 18ECL66 Sem: VI

16 X 2 LCD Display

An LCD display is specifically manufactured to be used with microcontrollers, which means that it
cannot be activated by standard IC circuits. It is used for displaying different messages on a
miniature liquid crystal display. It displays all the letters of alphabet, Greek letters, punctuation
marks, mathematical symbols etc. In addition, it is possible to display symbols made up by the
user. Other useful features include automatic message shift (left and right), cursor appearance,
LED backlight etc.

There are pins along one side of a small printed board. These are used for connecting to the
microcontroller.
Digits to Hex There are in total
Display Segments
display code of 14 pins marked
g f a b p c d e with numbers (16 if
0 1 0 0 0 1 0 0 0 88 it has backlight).
1 1 1 1 0 1 0 1 1 EB Their function is
described in the
2 0 1 0 0 1 1 0 0 4C
table below:
3 0 1 0 0 1 0 0 1 49
4 0 0 1 0 1 0 1 1 2B LCD Pin Configuration
5 0 0 0
LCD 1 LCD1 Pin 0 LPC- 0 1 LPC-19
6 0 0 0 No 1 Functions
1 1 17681 0 176818
Pin
Pin No Port No
7 1 1 0 0 1 0 1 1 CB
1 GND - -
8 0 0 0 0 1 0 0 0 08
2 VCC - -
9 0 0 0 0 1 0 0 1 09
3 - -
A 0 0 0 0 1 0 1 0 0A
4 RS 24 P2.28
B 0 0 1 1 1 0 0 0 38
5 R/W GND GND
C 1 0 0 1 1 0 0 0 98
6 EN 25 P2.25
D 0 1 1 0 1 0 0 0 68
7 DAT1 75 P2.0
E 0 0 0 1 1 1 0 0 1C
8 DAT2 74 P2.1
9 DAT3 73 P2.2
F 0 0 0 1 1 1 1 0 1E
10 DAT4 70 P2.3

DEPT OF E&C, REC, HULKOTI 28


Embedded System Lab Manual 18ECL66 Sem: VI

11 DAT5 69 P2.4
12 DAT6 68 P2.5
13 DAT7 67 P2.6
14 DAT8 66 P2.7
15 VCC - -
16 GND - -

DC Motor Pin Configuration

DC (direct current) motor rotates continuously. It has two terminals positive and negative.
Connecting DC power supply to these terminals rotates motor in one direction and reversing the
polarity of the power supply reverses the direction of rotation.

The speed of Dc motor can maintained at a constant speed for a given load by using “Pulse Width
Modulation (PWM)” technique. By changing the width of the pulse of applied to dc motor, the
power applied is varied thereby DC motor speed can be increased or decreased. Wider the pulse
Faster is the Speed, Narrower is the Pulse, and Slower is the Speed

U9 is L293 driver IC used to drive the dc motor. It has enable lines which is used to switch on the
DC motor. It is connected to P4.28. Logic ‘1 ’ enables the driver and logic ‘0 ’ disables the
driver.P4.28 and P4.29 are used for Motor 1 direction and speed control.

DC Motor Pin connection table.

Motor Motor LPC-1768 LPC-1768


Selection Direction Pin No Port No
P4.28=1 &
DCM0-Clk 82
P4.29=0
Motor 85 P4.28=0 &
DCM1-Aclk
P4.29=1
DCM_EN 65 P2.8=1

Stepper Motor Configuration:

A stepper motor is a special type of electric motor that moves in increments, or steps, rather than
turning smoothly as a conventional motor does. Typical increments are 0.9 or 1.8 degrees, with 400
or 200 increments thus representing a full circle. The speed of the motor is determined by the time
delay between each incremental movement.
U8 is a Driver Buffer (ULN2003) device connected to LPC-1768 Device and can be used for
driving Stepper Motor. On the LPC-1768, P1.22 to P1.25 is used to generate the pulse sequence
required to run the stepper Motor. Also, the Stepper Motor is powered by its own power supply pin
(COM), which is connected to a 12V supply. Table shows connections for stepper Motor.
Stepper Motor Pin connection table.
Stepper LPC-1768 LPC-1768
Motor Coil Pin No Port No

A 39 P1.22
B 37 P1.23
C 38 P1.24
D 39 P1.25

Relay Configurations:
DEPT OF E&C, REC, HULKOTI 29
Embedded System Lab Manual 18ECL66 Sem: VI

A relay is an electrically operated switch. Many relays use an electromagnet to operate a switching


mechanism mechanically, but other operating principles are also used. Relays are used where it is
necessary to control a circuit by a low-power signal (with complete electrical isolation between
control and controlled circuits), or where several circuits must be controlled by one signal. The first
relays were used in long distance telegraph circuits, repeating the signal coming in from one circuit
and re-transmitting it to another. Relays were used extensively in telephone exchanges and early
computers to perform logical operations.
K1 is an electromagnetic relay which is connected to P0.25 through Dip switch. We need to send
logic ‘1’ to switch on relay.J9 is three pin PBT terminal used to connect external device to relay.
Table shows connections for Relay.

Relay connection table.


Relay coil LPC-1768 LPC-1768
Pin No Port No
Relay 07 P0.25
HEX KEY PAD Pin configurations:
The hex keypad is a peripheral that is organized in rows and Columns. Hex key Pad 16 Keys
arranged in a 4 by 4 grid, labeled with the hexadecimal digits 0 to F. An example of this can been
seen in Figure 1, below. Internally, the structure of the hex keypad is very simple. Wires run in
vertical columns (we call them C0 to C3) and in horizontal rows (called R0 to R3). These 8 wires are
available externally, and will be connected to the lower 8 bits of the port. Each key on the keypad is
essentially a switch that connects a row wire to a column wire. When a key is pressed, it makes an
electrical connection between the row and column. Table shows connections for HEX KEY Pad
matrix.

HEX KEY Pad matrix table.


ROW ROW ROW ROW COL COL COL COL
ROW/COLOUMNS
1 2 3 4 1 2 3 4
LPC-1768 Pin No 32 33 34 35 89 88 87 86
LPC-1768 Port No P1.18 P1.19 P1.20 P1.21 P1.14 P1.15 P1.16 P1.17

USER KEY PAD Pin configurations:


VT1768 3_3board provides eight individual KEYS connected to LPC-1768 device through PORT1.
S1 to S6,S11and S16 are connected to general purpose I/O pins on 2148 device as shown in table.
2148 device port pin drives to Logic ‘0’ when the corresponding key is pressed. Table shows
connections for USER KEY Pad connection.

USER KEY Pad connection table.

USER
DEFINE S1 S6 S11 S12 S17 S22 S23 S24
D KEYS
LPC-
1768 1 2 3 4 5 6 7 8
Pin No
LPC-
1768 P1.14 P1.15 P1.16 P1.17 P1.18 P1.19 P1.20 P1.21
Port No

BUZZER & SPEAKER Pin Configuration.

A buzzer or beeper is an audio signaling device, which may be mechanical, electromechanical,


DEPT OF E&C, REC, HULKOTI 30
Embedded System Lab Manual 18ECL66 Sem: VI

or piezoelectric. Typical uses of buzzers and beepers include alarm devices, timers and confirmation


of user input such as a mouse click or keystroke. LS1 is a small 12mm round buzzer that operates
around the audible 2kHz range. We drove it through Q8 which in turn connected to P3.25.We need
to send Logic ‘1’ to generate beep.
A speaker is a device which converts electrical signal to audible signal.J7 is a two pin RMC where
we are connecting external speaker. We drove it through Q5 which in turn connected to P3.25 via
Jumper JP2.We need to send Logic ‘1’ to generate Tone.

Speaker /Buzzer pin connection Table.

Speaker/ LPC-1768 LPC-1768


Buzzer Pin Pin No Port No
1 27 P3.25

ADC:
• 12-bit successive approximation analog to digital converter.
• Input multiplexing among 8 pins.
• Power-down mode.
• Measurement range VREFN to VREFP (typically 3 V; not to exceed VDDA voltage level).
• 12-bit conversion rate of 200 kHz.
• Burst conversion mode for single or multiple inputs.
• Optional conversion on transition on input pin or Timer Match signal. Basic clocking for the A/D
converters is provided by the APB clock. A programmable divider is included in each
converter to scale this clock to the clock (maximum 13 MHz) needed by the successive
approximation process. A non-burst mode conversion requires 65 clocks and a burst mode
conversion requires 64 clocks.

ADC pin description


Pin Type Description
AD0.7 to AD0.0 Input Analog Inputs.
The ADC cell can measure the voltage on any of these
input signals. Digital signals are disconnected from
the ADC input pins when the ADC function is
selected on that pin in the Pin Select register.Warning:
if the ADC is used, signal levels on analog input pins
must not be above the level of VDDA at any time.
Otherwise, A/D converter readings will be invalid. If
the A/D converter is not used in an application then
the pins associated with A/D inputs can be used as 5
V tolerant digital IO pins.
VREFP, VRE Reference Voltage References. These pins provide a voltage reference level
for the ADC and DAC. Note: VREFP should be tied
to VDD (3V3) and VREFN should be tied to VSS if
the ADC and DAC are not used.
VDDA, VSSA Power Analog Power
and Ground. These should typically be the same voltages as VDD
and VSS, but should be isolated to minimize noise and
error. Note: VDDA should be tied to VDD(3V3) and
VSSA should be tied to VSS if the ADC and DAC are
not used.

DEPT OF E&C, REC, HULKOTI 31


Embedded System Lab Manual 18ECL66 Sem: VI

As VTCM3_3 board comes with two ADC inputs. One is connected to a potentiometer for external
analog voltage and another is for temperature measurement.

A 5K variable POT is connected to AD0(P0.23) input of LPC1768. By varying this we are applying 0
to 3.3V to ADC0 input. This analog voltage input can be converted into digital output.

An LM35 temperature sensor is connected through ADC SSP IC to SSEL input of LPC1768 for
ambient temperature measurement.

DAC:

Features

• 10-bit digital to analog converter

• Resistor string architecture

• Buffered output

• Selectable speed vs. power

• Maximum update rate of 1 MHZ.

As VTCM3_3 board comes with one DAC output for generation different wave forms. AOUT
(P0.26) is connected to TEST point TP1. The generated waveforms can be viewed through TP1
(DAC) and TP2 (GND) by connecting CRO.
PWM:

Features

• Counter or Timer operation (may use the peripheral clock or one of the capture inputs as the
clock source).

• Seven match registers allow up to 6 single edge controlled or 3 double edge controlled PWM
outputs, or a mix of both types. The match registers also allow:

– Continuous operation with optional interrupt generation on match.

– Stop timer on match with optional interrupt generation.

– Reset timer on match with optional interrupt generation.

• Supports single edge controlled and/or double edge controlled PWM outputs. Single edge
controlled PWM outputs all go high at the beginning of each cycle unless the output is a
constant low. Double edge controlled PWM outputs can have either edge occur at any position
within a cycle. This allows for both positive going and negative going pulses.

• Pulse period and width can be any number of timer counts. This allows complete flexibility in
the trade-off between resolution and repetition rate. All PWM outputs will occur at the same
repetition rate.

• Double edge controlled PWM outputs can be programmed to be either positive going or
negative going pulses.
• Match register updates are synchronized with pulse outputs to prevent generation of
DEPT OF E&C, REC, HULKOTI 32
Embedded System Lab Manual 18ECL66 Sem: VI

Erroneous pulses. Software must "release" new match values before they can become effective.
• May be used as a standard timer if the PWM mode is not enabled.
• A 32-bit Timer/Counter with a programmable 32-bit prescaler.
• Two 32-bit capture channels take a snapshot of the timer value when an input signals
transitions. A capture event may also optionally generate an interrupt. As VTCM3_3 board
comes with one DAC output for generation different wave forms. AOUT (P0.26) is connected to
TEST point TP1. The generated waveforms can be viewed through TP1 (DAC) and TP2 (GND) by
connecting CRO.

As VTCM3_3 board comes with one PWM output for generation PWM wave forms. AOUT (P0.26)
is connected to TEST point TP1. The generated waveforms can be viewed through TP1 (DAC) and
TP2 (GND) by connecting CRO.

EXPERMENT No 6

// Display “Hello World” message using Internal UART.

#include "LPC17xx.h"

#define FOSC 12000000

#define FCCLK (FOSC * 8)

#define FCCO (FCCLK * 3)

#define FPCLK (FCCLK / 4)

#define UART0_BPS 9600

void UART0_Init (void)


{
unsigned int usFdiv;
/* UART0 */
LPC_PINCON->PINSEL0 |= (1 << 4);
LPC_PINCON->PINSEL0 |= (1 << 6);
LPC_UART0->LCR = 0x83;
usFdiv = (FPCLK / 16) / UART0_BPS;
LPC_UART0->DLM = usFdiv / 256;
LPC_UART0->DLL = usFdiv % 256;
LPC_UART0->LCR = 0x03;
LPC_UART0->FCR = 0x06;
}

int UART0_SendByte (int ucData)


{
while (!(LPC_UART0->LSR & 0x20));
return (LPC_UART0->THR = ucData);
}

int UART0_GetChar (void)


DEPT OF E&C, REC, HULKOTI 33
Embedded System Lab Manual 18ECL66 Sem: VI

{
while (!(LPC_UART0->LSR & 0x01));
return (LPC_UART0->RBR);
}

void UART0_SendString (unsigned char *s)


{
while (*s != 0)
UART0_SendByte(*s++);
}
int main(void)
{
SystemInit();
UART0_Init();
UART0_SendString("HELLO WORLD!!!");
UART0_SendByte(0x0D); UART0_SendByte(0x0A); //CR LF
}

EXPERMENT No 7

// Interface and Control a DC Motor.

#include <LPC17xx.H>
#include "lcd.h"

#define MOTOR_MASK 0x30000000


#define MTE (1 << 8)
#define KEY_START (1 << 14)
#define KEY_STOP (1 << 15)
#define KEY_INC (1 << 16)
#define KEY_DEC (1 << 17)

void motor_write( uint32_t data )


{
uint32_t temp;

temp=(data << 28) & MOTOR_MASK;

LPC_GPIO4->FIOCLR |= MOTOR_MASK;
LPC_GPIO4->FIOSET |= temp;
}

int main (void)


{
unsigned int del=0;
unsigned int i=0;
init_lcd();

LPC_GPIO4->FIODIR |= MOTOR_MASK;
LPC_GPIO2->FIODIR |= MTE;

LPC_GPIO2->FIOCLR |= MTE;

LPC_GPIO1->FIODIR &= ~(KEY_START | KEY_STOP | KEY_INC | KEY_DEC );


LPC_GPIO1->FIOSET |= (KEY_START | KEY_STOP | KEY_INC | KEY_DEC );
DEPT OF E&C, REC, HULKOTI 34
Embedded System Lab Manual 18ECL66 Sem: VI

lcd_putstring16(0,"1,2 START/STOP");
lcd_putstring16(1,"3,4 SPED DCMOTOR");

while(1)
{
if (!(LPC_GPIO1->FIOPIN & KEY_START))
{
motor_write(0x01);
LPC_GPIO2->FIOSET |= MTE;
}

if (!(LPC_GPIO1->FIOPIN & KEY_STOP))


{
motor_write(0x03);

LPC_GPIO2->FIOCLR |= MTE;
}

if (!(LPC_GPIO1->FIOPIN & KEY_INC))


{
if (del != 0)
del = del - 1;
}

if (!(LPC_GPIO1->FIOPIN & KEY_DEC))


{
if (del != 50000)
del = del + 1;
}

if (del == 0)
LPC_GPIO2->FIOSET |= MTE;
else
{
LPC_GPIO2->FIOCLR |= MTE;
for (i=0; i < del; i++);
LPC_GPIO2->FIOSET |= MTE;
for (i=0; i < del; i++);
}
}
}

DEPT OF E&C, REC, HULKOTI 35


Embedded System Lab Manual 18ECL66 Sem: VI

EXPERMENT No 8

// Interface a Stepper motor and rotate it in clockwise and anti-clockwise direction.


#include <LPC17xx.H>
#include "lcd.h"
#define MOTOR_MASK 0x03C00000
#define KEY_CW (1 << 18)
#define KEY_CCW (1 << 19)
void motor_write( uint32_t data )
{
uint32_t temp;
temp=(data << 22) & MOTOR_MASK;
LPC_GPIO1->FIOCLR |= MOTOR_MASK;
LPC_GPIO1->FIOSET |= temp;
}
int main (void)
{
uint32_t stpval=0x01;
unsigned char dir=0;
init_lcd();
lcd_putstring16(0," STEPPER MOTOR ");
lcd_putstring16(1,"5,6-DIR");

LPC_GPIO1->FIODIR |= MOTOR_MASK;
LPC_GPIO1->FIOCLR |= MOTOR_MASK;
LPC_GPIO1->FIODIR &= ~( KEY_CW | KEY_CCW);
LPC_GPIO1->FIOSET |= (KEY_CW | KEY_CCW);
motor_write(stpval);
while(1)
{
if (!(LPC_GPIO1->FIOPIN & KEY_CW))
dir = 0;
if (!(LPC_GPIO1->FIOPIN & KEY_CCW))
dir = 1;
DEPT OF E&C, REC, HULKOTI 36
Embedded System Lab Manual 18ECL66 Sem: VI

if (dir == 0)
{
if (stpval == 8)
stpval = 1;
else
stpval <<= 1;
}
else
{
if (stpval == 1)
stpval = 8;
else
stpval >>= 1;
}
motor_write(stpval);
delay(del);
}
}
}

EXPERMENT No 9A

// Interface a DAC and generate Square waveforms.

#include <LPC17xx.H>
#include "lcd.h"
#define voltage 1024
#define freq 120000

int main (void)


{
uint32_t m;
LPC_PINCON->PINSEL1 |= (1<<21);
init_lcd();
lcd_putstring16(0,"* DAC - SQUARE *");
lcd_putstring16(1,"* LPC1768 DEMO *");

while(1)
{
LPC_DAC->DACR = (voltage/2 << 6);
for(m = freq; m > 1; m--);
LPC_DAC->DACR = (voltage << 6);
for(m = freq; m > 1; m--);
}
}

EXPERMENT No 9B

// Interface a DAC and generate Triangular.


#include <LPC17xx.H>
#include "lcd.h"
#define voltage 1024
#define freq 10

DEPT OF E&C, REC, HULKOTI 37


Embedded System Lab Manual 18ECL66 Sem: VI

int main (void)


{
uint32_t i = 0;
uint32_t m;
LPC_PINCON->PINSEL1 |= (1<<21);
init_lcd();
lcd_putstring16(0," DAC - TRIANGLE ");
lcd_putstring16(1,"* LPC1768 DEMO *");
while(1)
{
for(i = 0; i < voltage; i++)
{
LPC_DAC->DACR = (i << 6);
for(m = freq; m > 1; m--);
}
for(i = voltage; i > 0; i--)
{
LPC_DAC->DACR = (i << 6);
for(m = freq; m > 1; m--);
}
}
}

EXPERMENT No 10

// Interface a 4x4 keyboard and display the key code on an LCD.

#include <LPC17xx.H>
#include "lcd.h"

#define COL1 (1 << 14)


#define COL2 (1 << 15)
#define COL3 (1 << 16)
#define COL4 (1 << 17)

#define ROW1 (1 << 18)


#define ROW2 (1 << 19)
#define ROW3 (1 << 20)
#define ROW4 (1 << 21)

#define COLMASK (COL1 | COL2 | COL3 | COL4)


#define ROWMASK (ROW1 | ROW2 | ROW3 | ROW4)

void col_write( unsigned char data )


{
unsigned int temp=0;

temp=(data << 14) & COLMASK;

LPC_GPIO1->FIOCLR |= COLMASK;
LPC_GPIO1->FIOSET |= temp;
}

DEPT OF E&C, REC, HULKOTI 38


Embedded System Lab Manual 18ECL66 Sem: VI

int main (void)


{
unsigned char key, i;
unsigned char rval[] = {0x7,0xB,0xD,0xE,0x0};
unsigned char keyPadMatrix[] =
{
'C','8','4','0',
'D','9','5','1',
'E','A','6','2',
'F','B','7','3'
};

init_lcd();

LPC_GPIO1->FIODIR |= COLMASK;
LPC_GPIO1->FIODIR &= ~(ROWMASK);

lcd_putstring16(0,"Press HEX Keys..");


lcd_putstring16(1,"Key Pressed = ");
while (1)
{
key = 0;

for( i = 0; i < 4; i++ )


{

col_write(rval[i]);

if (!(LPC_GPIO1->FIOPIN & ROW1))


break;

key++;
if (!(LPC_GPIO1->FIOPIN & ROW2))
break;
key++;
if (!(LPC_GPIO1->FIOPIN & ROW3))
break;

key++;
if (!(LPC_GPIO1->FIOPIN & ROW4))
break;
key++;
}
if (key == 0x10)
lcd_putstring16(1,"Key Pressed = ");
else
{
lcd_gotoxy(1,14);
lcd_putchar(keyPadMatrix[key]);
}
}

DEPT OF E&C, REC, HULKOTI 39


Embedded System Lab Manual 18ECL66 Sem: VI

EXPERMENT No 11

// Demonstrate the use of an external interrupt to toggle an LED On/Off.

#include <lpc17xx.h>
#include "lcd.h"
#define PINSEL_EINT0 20
#define PINSEL_EINT1 22

#define LED1 (1 << 4)


#define LED2 (1 << 5)

#define SBIT_EINT0 0
#define SBIT_EINT1 1

#define SBIT_EXTMODE0 0
#define SBIT_EXTMODE1 1

#define SBIT_EXTPOLAR0 0
#define SBIT_EXTPOLAR1 1

void EINT0_IRQHandler(void)
{
LPC_SC->EXTINT = (1<<SBIT_EINT0);
LPC_GPIO0->FIOPIN ^= LED1;
}
void EINT1_IRQHandler(void)
{
LPC_SC->EXTINT = (1<<SBIT_EINT1);
LPC_GPIO0->FIOPIN ^= LED2;
}
DEPT OF E&C, REC, HULKOTI 40
Embedded System Lab Manual 18ECL66 Sem: VI

int main()
{
init_lcd();

lcd_putstring16(0,"XTERNL INTERUPTS");
lcd_putstring16(1,"I0-LED1 I1-LED2");

LPC_SC->EXTINT = (1<<SBIT_EINT0) | (1<<SBIT_EINT1);


LPC_PINCON->PINSEL4 = (1<<PINSEL_EINT0) | (1<<PINSEL_EINT1);
LPC_SC->EXTMODE = (1<<SBIT_EXTMODE0) | (1<<SBIT_EXTMODE1);
LPC_SC->EXTPOLAR = (1<<SBIT_EXTPOLAR0)| (1<<SBIT_EXTPOLAR0);

LPC_GPIO0->FIODIR = (LED1 | LED2);


LPC_GPIO0->FIOPIN = 0x00;

NVIC_EnableIRQ(EINT0_IRQn);
NVIC_EnableIRQ(EINT1_IRQn);

while(1)
{
// Do nothing
}
}

EXPERMENT No 12

// Display the Hex digits 0 to F on a 7-segment LED interface, with an appropriate delay in between

#include <LPC17xx.H> /* NXP LPC17xx definitions */


//#include <stdio.h>
#include "lcd.h"
#define dig1 (1 << 26)
#define dig2 (1 << 27)
#define dig3 (1 << 28)
#define dig4 (1 << 29)
unsigned char data7[] =
{0x88,0xeb,0x4c,0x49,0x2b,0x19,0x18,0xcb,0x8,0x9,0xa,0x38,0x9C,0x68,0x1c,0x1e};
int main (void)
{
unsigned int i,j;

unsigned int count=0;

LPC_GPIO2->FIODIR = 0x000000FF;
LPC_GPIO2->FIOPIN = 0x000000FF;
LPC_GPIO1->FIODIR |= 0x3C000000;
LPC_GPIO1->FIOPIN &= ~(0x3C000000);

init_lcd();

lcd_putstring16(0," 7-SEG COUNTER ");


while(1)
{
++count;
DEPT OF E&C, REC, HULKOTI 41
Embedded System Lab Manual 18ECL66 Sem: VI

if (count > 0xFFFF) count = 0;


for (i=0; i < 1000; i++)
{
LPC_GPIO2->FIOPIN = data7[count & 0x000F];
LPC_GPIO1->FIOSET = dig1;
for (j=0;j<500;j++);
LPC_GPIO1->FIOCLR = dig1;

LPC_GPIO2->FIOPIN = data7[(count & 0x00F0)>>4];


LPC_GPIO1->FIOSET = dig2;
for (j=0;j<500;j++);
LPC_GPIO1->FIOCLR = dig2;

LPC_GPIO2->FIOPIN = data7[(count & 0x0F00)>>8];


LPC_GPIO1->FIOSET = dig3;
for (j=0;j<500;j++);
LPC_GPIO1->FIOCLR = dig3;

LPC_GPIO2->FIOPIN = data7[(count & 0xF000)>>12];


LPC_GPIO1->FIOSET = dig4;
for (j=0;j<500;j++);
LPC_GPIO1->FIOCLR = dig4;
}
}
}

EXPERMENT No 13

// Measure Ambient temperature using a sensor and SPI ADC IC

#include <LPC17xx.H>
#include <stdio.h>
#include "lcd.h"
#include "spi.h"
int main (void)
{
uint8_t msb, lsb;
uint16_t ADCValue;
float temp;
char lstr[10];

SPI_Init();
init_lcd();

lcd_putstring16(0,"RAW ADC = 0000 ");


lcd_putstring16(1,"TEMP = 000 degC");

while(1)
{
SPI_EnableChipSelect();
delay(1);
SPI_Write(0x01);
msb = SPI_Write(0xA0);
lsb = SPI_Write(0x00);

DEPT OF E&C, REC, HULKOTI 42


Embedded System Lab Manual 18ECL66 Sem: VI

SPI_DisableChipSelect();
msb &= 0x0F;
ADCValue = (msb << 8) | lsb;

sprintf (lstr, "%4u", ADCValue);


lcd_gotoxy(0,10);
lcd_putstring(lstr);
temp = ((ADCValue * 3.3) / 4096) * 100;
sprintf (lstr, "%0.1f", temp);
lcd_gotoxy(1,7);
lcd_putstring(lstr);

delay(500);
}
}

DEPT OF E&C, REC, HULKOTI 43

You might also like