Panimalar Engineering College: Ec6711 - Embedded Laboratory Iv Ece-Vii Semester
Panimalar Engineering College: Ec6711 - Embedded Laboratory Iv Ece-Vii Semester
Panimalar Engineering College: Ec6711 - Embedded Laboratory Iv Ece-Vii Semester
2017-2018(ODD SEMESTER)
1
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
DEPARTMENT OF ECE
VISION
MISSION
M1: To provide best facilities, infrastructure and environment to its students, researchers and
field.
M2: To provide quality education through effective teaching – learning process for their
M3: To expose strong insight in the core domains with industry interaction.
M4: Prepare graduates adaptable to the changing requirements of the society through life
long learning.
1. To prepare graduates to analyze, design and implement electronic circuits and systems
analyze, design and create novel products and solutions for real life problems.
3. To introduce the research world to the graduates so that they feel motivated for higher
studies and innovation not only in their own domain but multidisciplinary domain.
teamwork and leadership qualities in their profession and adapt to current trends by
PROGRAMME OUTCOMES
Engineering problems.
2. Problem Analysis: Able to identify, formulate, review research literature, and analyze
problems and design system components or processes that meet the specified needs with
appropriate considerations for the public health and safety and the cultural, societal, and
environmental considerations.
and research methods including design of experiments, analysis and interpretation of data,
5. Modern tool usage: Able to create, select and apply appropriate techniques, resources,
6. The Engineer and society: Able to apply reasoning informed by the contextual knowledge
to access societal, health, safety, legal and cultural issues and the consequent
8. Ethics: Able to apply ethical principles and commit to professional ethics and
3
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
with the Engineering community and with society at large, such as, being able to
comprehend and write effective reports and design documentation, make effective
11. Project Management and Finance: Able to demonstrate knowledge and understanding
of the engineering and management principles and apply these to one’s own work, as a
12. Life – long learning: Able to recognize the needs for, and have the preparation and
technological change.
4
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
SYLLABUS
LIST OF EXPERIMENTS
1. Study of ARM evaluation system
2. Interfacing ADC and DAC.
3. Interfacing LED and PWM.
4. Interfacing real time clock and serial port.
5. Interfacing keyboard and LCD.
6. Interfacing EPROM and interrupt.
7. Mailbox.
8. Interrupt performance characteristics of ARM and FPGA.
9. Flashing of LEDS.
10. Interfacing stepper motor and temperature sensor.
11. Implementing zigbee protocol with ARM.
OUTCOMES: At the end of the course, the student should be able to:
5
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
TABLE OF CONTENT
PAGE
S.No PARTICULARS
No
1 Basics for Embedded Systems for Software Development 4
2 How to develop embedded software for LPC 1768 using Keil IDE 9
3 How to download and Run program using Flash Magic into LPC1768(Target ) 11
6
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
LAB EXPERIMENTS
PAGE
S.No PARTICULARS
No
1 Interfacing LEDS with LPC1768 55
ADDITIONAL EXPERIMENTS
7
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
8
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Basic C Operator
Arithmetic Operators: The following table shows all the arithmetic operators supported by the C
language. Assume variable A holds 10 and variable B holds 20 then −
Relational Operators: The following table shows all the relational operators supported by C.
Assume variable A holds 10 and variable B holds 20 then −
Logical Operators: Following table shows all the logical operators supported by C language.
Assume variable A holds 1 and variable B holds 0, then −
9
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Bitwise Operators: Bitwise operators work on bits and perform bit-by-bit operation. The truth tables
for &, |, and ^ is as follows −
~A = 1100 0011
The following table lists the bitwise operators supported by C. Assume variable 'A' holds 60 and
variable 'B' holds 13, then −
10
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Assignment Operators: The following table lists the assignment operators supported by the C
language −
Misc Operators ↦ sizeof & ternary:Besides the operators discussed above, there are a few
other important operators including sizeof and ? : supported by the C Language.
Certain operators have higher precedence than others; for example, the multiplication operator has a
higher precedence than the addition operator.
For example, x = 7 + 3 * 2; here, x is assigned 13, not 20 because operator * has a higher precedence
than +, so it first gets multiplied with 3*2 and then adds into 7.
Here, operators with the highest precedence appear at the top of the table, those with the lowest
appear at the bottom. Within an expression, higher precedence operators will be evaluated first.
11
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
For example, x = 7 + 3 * 2; here, x is assigned 13, not 20 because operator * has a higher precedence
than +, so it first gets multiplied with 3*2 and then adds into 7.
Here, operators with the highest precedence appear at the top of the table, those with the lowest
appear at the bottom. Within an expression, higher precedence operators will be evaluated first.
12
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
How to develop embedded software for LPC 1768 using Keil IDE
About “Project”:
A project is a file in which Keil uVision5 stores all information related to an application. E.g. it stores
the name of ‘C’ and/or Assembler source file, memory size to be used and other options for compiler,
assembler and linker.
Opening a project:
To open an existing project file, select Project / Open Project from the menu.
Start the Keil uVision5 program (i.e. the Integrated Development Environment) from
Step 1
start\Programs\Keil uVision5.
Step 2 From Project menu, select Close project (if any project is open).
From Project menu, select New Project. The Open dialog window will be displayed.Select
the desired path where you wish to create this new project. (For example, C:\SPJ).
Step 3 CAUTION: The path and filename must not contain space or other special characters such
as tab, comma, semicolon etc. In the “File name” field, type the name of the project, without
any extension. For example, you may type “PROG1”. Then click on the “Open” button.
The action in the previous step will display the “Select device for Target ‘Target 1’ ”
dialog window. Here you have to select the micro-controller you are going to use. The target
microcontroller (must be a member of ARM family) is known, You have to load “Legacy
Device Database (RTE)” and then select the device you may select the appropriate
Step 4
Manufacturer from the list; and then select the appropriate micro-controller from the device
list. If the target microcontroller is not known or if you cannot find it in the list, then you
may simply search “ LPC1768”or select “NXP” as the manufacturer and “LPC1768” as the
micro-controller.
Then a dialog box will appear asking for adding Startup.s file in to the project. Click on the
Step 5
“Yes” to it.
13
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Click on “Source Group 1” to display that part of the dialog window. This window will
indicate that IDE has automatically added 1 files in this new project: STARTUP.S The
STARTUP.s file is automatically created by the IDE and is required for all C projects. Now
add the file select “File / New” then a dialog box will appear, give name to your file with
Step 6 extension ( E.g. PROG1.c ) Then add files in this project, then right click on the “Source
Group 1” Folder,click on “Add existing Files to Group ‘Source Group1’ ” select the
desired filename and then click on “Add” button. Now the Project Settings dialog will
indicate that selected file has been added into the project. When all necessary files have been
added to the project, click “OK” button to create this newproject.
Now create the “Target” for the completion of the project, right click on the “Target 1”
folder in the project explorer window. then click on “options for Target ‘Target 1’ ” ,Then
Step 7 a dialog appears having 10 parts first is Device and last Utilities. Now select Output and
Checked the options “Create Hex File”. then go to “Linker” and check the option “Use
memory layout from target dialog.”
From the Target menu, select Build. This will invoke the Compiler to compile the file
PROG1.C;and further (assuming no errors) invoke the linker to create the .HEX file. If there
are any errors or warnings during the process of compiling, assembling or linking, then those
Step 8 will be displayed in the output window (below the editor window). If there are errors, then
you may correct those by making appropriate changes to the program; select Save from File
menu to save the changes and then again select Build from Compile menu. Repeat this until
there are no errors.
You may inspect contents of the folder where your project files reside. When there are no
errors and build has completed successfully and then you will see a file name with same
Step 9 name as the project name and extension .HEX (in above example, PROG1.HEX). This is
the file that you will need to use to program your micro-controller.
14
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
How to download and Run program using Flash Magic into LPC1768
Connect the J1/UART0 connector of ADT V1.1 board to COM1 or COM2 of a PC,
Step 1
using the serial communication cable (supplied with the board).
Keep S2 switch in ON position. (You can keep S2 switch continuously ON) Switch
Step 2
ON power to the ADT V1.1.
Do proper settings in Flash Magic (COM Port: COM1 (if other choose it), Baud Rate:
Step 3 19200,Device: LPC1768, Interface: None (ISP), Enable “Erase blocks used by Hex
File”, Browse the file which you want to download) and click on Start button.
Step 4 Flash Magic will download the program. Wait till Finished comes.
After downloading Flash Magic automatically resets the ADT V1.1 board and
Step 5
program executes. You can see output according to the program.
If again you want to “Reset” the board then press “RST” switch on SM-2148 board.
You can see output according to the program. Note: Flash Magic can be used to
Step 6
download the program into other Philips Micro-controllers also. See the list in Flash
Magic itself.
15
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Unpacking:
You will find following items in the package:
• ADT V1.1 board
• Serial communication cable (Straight 9-Pin)
• Power adapter with cable
• SPJ_TOOLS’ CD-ROM
Powering ON:
After connecting the serial communication cable as described above, you may insert the power
adapter output jack into the on-board power socket. Plug the power adapter into 230VAC mains outlet
and turn it on. Now press on-board power switch, power-on indication Green LED will turn on.
CAUTION: Please do not connect or disconnect the serial communication cable while the board is
powered ON. Doing so can damage the serial port of the ADT V1.1 board and/or PC.
16
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
PIN DESCRIPTION
Pin Number
Pinsel reg
Function
Function
Symbol
Pinsel
Block
Description
I/O
Pin
ix
17
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Test Mode
I TMS JTAG Select for JTAG
interface.
3 TMS/SWDIO
I SWDIO SWDEB Serial wire
UG debug data
input/output.
General purpose
digital
input/output pin.
When
I/ configured as an
0 P0.26 GPIO 0
O ADC input or
DAC output, the
digital section of
pinsel1
P0.26/AD0.3/AO the pad is
6 21:20
UT/RXD3 disabled.
x
A/D converter 0,
1 I AD0.3 ADC
input 3.
D/A converter
2 O AOUT DAC
output.
Receiver input
3 I RXD3 UART 3
for UART3.
General purpose
digital
input/output pin.
When
pinsel1 I/
P0.25/AD0.2/I2S 0 P0.25 GPIO 0 configured as an
7 19:18 O
RX_SDA/TXD3 ADC input,
x digital section of
the pad is
disabled.
18
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
input 2.
Receive data. It
is driven by the
transmitter and
read by the
I/ I2SRX_S
2 I2S receiver.
O DA
Corresponds to
the signal SD in
the I2S bus
specification.
Transmitter
3 O TXD3 UART 3 output for
UART3.
General purpose
digital
input/output pin.
When
I/
0 P0.24 GPIO 0 configured as an
O
ADC input,
digital section of
the pad is
disabled.
A/D converter 0,
1 I AD0.1 ADC
input 1.
pinsel1
P0.24/AD0.1/I2S Receive Word
8 17:16
RX_WS/CAP3.1 Select. It is
x
driven by the
master and
I/ I2SRX_W received by the
2 I2S
O S slave.
Corresponds to
the signal WS in
the I2S bus
specification.
configured as an
ADC input,
digital section of
the pad is
disabled.
A/D converter 0,
1 I AD0.0 ADC
input 0.
Receive Clock.
It is driven by
the master and
received by the
I/ I2SRX_C
2 I2S slave.
O LK
Corresponds to
the signal SCK
in the I2S bus
specification.
analog ground: 0
ADC V reference.
11 VSSA P VSSA This should be
DAC
the same voltage
as VSS, but
20
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
should be
isolated to
minimize noise
and error.
ADC positive
reference
voltage: This
should be
nominally the
same voltage as
VDDA but
should be
isolated to
minimize noise
ADC
12 VREFP I VREFP and error. The
DAC
voltage level on
this pin is used
as a reference
for ADC and
DAC.
Note: this pin
should be tied to
3.3v if the ADC
and DAC are not
used.
This is a 3.3 V
pin. A LOW on
this pin indicates
14 !RSTOUT O !RSTOUT Main
that the
LPC17xx is in a
Reset state.
ADC negative
reference
voltage: This
should be the
ADC same voltage as
15 VREFN I VREFN VSS but should
DAC
be isolated to
minimize noise
and error. Level
on this pin is
used as a
21
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
reference for
ADC and DAC.
External reset
input: A LOW
on this pin resets
the device,
causing I/O ports
and peripherals
to take on their
default states,
17 !RESET I !RESET Main
and processor
execution to
begin at address
0. This is a 5 V
tolerant pad with
a 20 ns glitch
filter, TTL levels
and hysteresis.
RTC domain
power supply:
3.3 V on this pin
19 VBAT I VBAT RTC
supplies the
power to the
RTC peripheral.
General purpose
digital
input/output pin.
When
I/
pinsel3 0 P1.31 GPIO 1 configured as an
P1.31/SCK1/AD O
20 31:30 ADC input,
0.5 digital section of
x
the pad is
disabled.
22
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
A/D converter 0,
3 I AD0.5 ADC
input 5.
General purpose
digital
input/output pin.
When
I/
0 P1.30 GPIO 1 configured as an
O
ADC input,
digital section of
the pad is
pinsel3 disabled.
P1.30/VBUS/AD
21 29:28
0.4 Monitors the
x
presence of USB
bus power. Note:
USB-
2 I VBUS This signal must
Device
be HIGH for
USB reset to
occur.
A/D converter 0,
3 I AD0.4 ADC
input 4.
Input to the
oscillator circuit
22 XTAL1 I XTAL1 Main and internal
clock generator
circuits.
General purpose
digital
input/output pin.
Open-drain 5 V
tolerant digital
pinsel1 I/O pad,
P0.28/SCL0/US I/
24 25:24 0 P0.28 GPIO 0 compatible with
B_SCL O
x I2C-bus
specifications
for 100 kHz
standard mode,
400 kHz Fast
Mode, and 1
23
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
I2C0 clock
input/output.
I/
1 SCL0 I2C 0 Open-drain
O
output (for I2C-
bus compliance).
General purpose
digital
input/output pin.
Open-drain 5 V
tolerant digital
I/O pad,
pinsel1 compatible with
P0.27/SDA0/US I/ I2C-bus
25 23:22 0 P0.27 GPIO 0
B_SDA O specifications
x
for 100 kHz
standard mode,
400 kHz Fast
Mode, and 1
MHz Fast Mode
Plus. This pad
requires an
24
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
external pull-up
to provide output
functionality.
When power is
switched off,
this pin
connected to the
I2C-bus is
floating and does
not disturb the
I2C lines. Open-
drain
configuration
applies to all
functions on this
pin.
I2C0 data
input/output.
I/
1 SDA0 I2C 0 Open-drain
O
output (for I2C-
bus compliance).
General purpose
I/
0 P3.26 GPIO 3 digital
O
input/output pin.
System tick
1 I STCLK Tick timer clock
pinsel7 input.
P3.26/STCLK/M
26 21:20 Match output for
AT0.1/PWM1.3
x 2 O MAT0.1 Timer 0 Timer 0, channel
1.
Pulse Width
Modulator 1,
3 O PWM1.3 PWM
channel 3
output.
25
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Pulse Width
Modulator 1,
3 O PWM1.2 PWM
channel 2
output.
3.3 V supply
voltage: This is
the power supply
VDD(3V3
28 VDD(3V3) I Main voltage for I/O
)
other than pins
in the Vbat
domain.
General purpose
digital
input/output pin.
Pad provides
digital I/O and
USB functions.
I/ It is designed in
0 P0.29 GPIO 0
O accordance with
the USB
pinsel1 specification,
29 P0.29/USB_D+ 27:26 revision 2.0
x (Full-speed and
Low-speed
mode only).
USB-
Device
USB
I/ USB-
1 USB_D+ bidirectional D+
O Host
line.
USB-
OTG
General purpose
digital
pinsel1 input/output pin.
I/ Pad provides
30 P0.30/USB_D- 29:28 0 P0.30 GPIO 0
O digital I/O and
x
USB functions.
It is designed in
accordance with
26
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
the USB
specification,
revision 2.0
(Full-speed and
Low-speed
mode only).
USB-
Device
USB
I/ USB-
1 USB_D- bidirectional D-
O Host
line.
USB-
OTG
ground: 0 V
31 VSS I VSS Main
reference.
General purpose
I/
0 P1.18 GPIO 1 digital
O
input/output pin.
USB GoodLink
LED indicator. It
is LOW when
device is
USB-
configured (non-
Device
control
USB_UP_ USB-
1 O endpoints
LED Host
P1.18/USB_UP_ pinsel3 enabled). It is
USB-
32 LED/PWM1.1/C 5:4 HIGH when the
OTG
AP1.0 x device is not
configured or
during global
suspend.
Pulse Width
Modulator 1,
2 O PWM1.1 PWM
channel 1
output.
27
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Motor control
Motor-
1 O MCOA0 PWM channel 0,
PWM
output A.
Port Power
!USB_PP USB-
2 O enable signal for
WR Host
USB port.
General purpose
I/
0 P1.20 GPIO 1 digital
O
input/output pin.
Motor control
PWM channel 0
input. Also
Motor-
1 I MCI0 Quadrature
pinsel3 PWM
P1.20/MCI0/PW Encoder
34 9:8 Interface PHA
M1.2/SCK0
x input.
Pulse Width
Modulator 1,
2 O PWM1.2 PWM
channel 2
output.
General purpose
I/
0 P1.21 GPIO 1 digital
O
input/output pin.
Motor control
!MCABO Motor-
1 I PWM, active
P1.21/!MCABO pinsel3 RT PWM
low fast abort.
35 RT/PWM1.3/SS 11:10
EL0 x Pulse Width
Modulator 1,
2 O PWM1.3 PWM
channel 3
output.
28
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
General purpose
I/
0 P1.22 GPIO 1 digital
O
input/output pin.
Motor control
Motor-
1 O MCOB0 PWM channel 0,
P1.22/MCOB0/U pinsel3 PWM
output B.
36 SB_PWRD/MA 13:12
T1.0 x Power Status for
USB_PW USB-
2 I USB port (host
RD Host
power switch).
General purpose
I/
0 P1.23 GPIO 1 digital
O
input/output pin.
Motor control
PWM channel 1
input. Also
Motor-
1 I MCI1 Quadrature
pinsel3 PWM
P1.23/MCI1/PW Encoder
37 15:14 Interface PHB
M1.4/MISO0
x input.
Pulse Width
Modulator 1,
2 O PWM1.4 PWM
channel 4
output.
I/ Master In Slave
3 MISO0 SSP 0
O Out for SSP0.
General purpose
I/
0 P1.24 GPIO 1 digital
O
input/output pin.
29
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Pulse Width
Modulator 1,
2 O PWM1.5 PWM
channel 5
output.
Master Out
I/
3 MOSI0 SSP 0 Slave In for
O
SSP0.
General purpose
I/
0 P1.25 GPIO 1 digital
O
input/output pin.
General purpose
I/
0 P1.26 GPIO 1 digital
O
input/output pin.
Motor control
Motor-
1 O MCOB1 PWM channel 1,
PWM
pinsel3 output B.
P1.26/MCOB1/P
40 21:20 Pulse Width
WM1.6/CAP0.0
x Modulator 1,
2 O PWM1.6 PWM
channel 6
output.
ground: 0 V
41 VSS I VSS Main
reference.
3.3 V voltage
regulator supply
voltage: This is
VDD(RE
42 VDD(REG)(3V3) I Main the supply
G)(3V3)
voltage for the
on-chip voltage
regulator only.
30
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
General purpose
I/
0 P1.27 GPIO 1 digital
O
input/output pin.
Clock output
P1.27/CLKOUT/ pinsel3 1 O CLKOUT Main
pin.
43 !USB_OVRCR/ 23:22
CAP0.1 x !USB_OV USB- USB port Over-
2 I
RCR Host Current status.
General purpose
I/
0 P1.28 GPIO 1 digital
O
input/output pin.
Motor control
Motor-
1 O MCOA2 PWM channel 2,
pinsel3 PWM
P1.28/MCOA2/P output A.
44 25:24
CAP1.0/MAT0.0 Capture input for
x
2 I PCAP1.0 PWM PWM1, channel
0.
General purpose
I/
0 P1.29 GPIO 1 digital
O
input/output pin.
Motor control
Motor-
1 O MCOB2 PWM channel 2,
pinsel3 PWM
P1.29/MCOB2/P output B.
45 27:26
CAP1.1/MAT0.1 Capture input for
x
2 I PCAP1.1 PWM PWM1, channel
1.
31
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
General purpose
I/
0 P0.0 GPIO 0 digital
O
input/output pin.
CAN1 receiver
1 I RD1 CAN 1
input.
Transmitter
pinsel0 2 O TXD3 UART 3 output for
P0.0/RD1/TXD3 UART3.
46 1:0
/SDA1
x
I2C1 data
input/output
(this pin is not
I/ fully compliant
3 SDA1 I2C 1
O with the I2C-bus
specification, see
Section 19–4 for
details).
General purpose
I/
0 P0.1 GPIO 0 digital
O
input/output pin.
CAN1
1 O TD1 CAN 1 transmitter
output.
General purpose
I/
0 P0.10 GPIO 0 digital
pinsel0 O
P0.10/TXD2/SD input/output pin.
48 21:20
A2/MAT3.0 Transmitter
x
1 O TXD2 UART 2 output for
UART2.
32
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
I2C2 data
I/ input/output
2 SDA2 I2C 2
O (this is not an
open-drain pin).
General purpose
I/
0 P0.11 GPIO 0 digital
O
input/output pin.
Receiver input
1 I RXD2 UART 2
for UART2.
pinsel0
P0.11/RXD2/SC I2C2 clock
49 23:22
L2/MAT3.1 I/ input/output
x 2 SCL2 I2C 2
O (this is not an
open-drain pin).
General purpose
digital
input/output pin.
5 V tolerant pad
I/ with 5 ns glitch
0 P2.13 GPIO 2
O filter providing
digital I/O
functions with
TTL levels and
pinsel4 hysteresis.
P2.13/!EINT3/I2
50 27:26
STX_SDA External
x 1 I !EINT3 Main
interrupt 3 input.
Transmit data. It
is driven by the
transmitter and
I/ I2STX_S read by the
3 I2S
O DA receiver.
Corresponds to
the signal SD in
the I2S bus
33
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
specification.
General purpose
digital
input/output pin.
5 V tolerant pad
I/ with 5 ns glitch
0 P2.12 GPIO 2
O filter providing
digital I/O
functions with
TTL levels and
hysteresis.
pinsel4
P2.12/!EINT2/I2 External
51 25:24 1 I !EINT2 Main
STX_WS interrupt 2 input.
x
Transmit Word
Select. It is
driven by the
master and
I/ I2STX_W received by the
3 I2S
O S slave.
Corresponds to
the signal WS in
the I2S bus
specification.
General purpose
digital
input/output pin.
5 V tolerant pad
I/ with 5 ns glitch
0 P2.11 GPIO 2
O filter providing
digital I/O
functions with
pinsel4 TTL levels and
P2.11/!EINT1/I2
52 23:22 hysteresis.
STX_CLK
x
External
1 I !EINT1 Main
interrupt 1 input.
Transmit Clock.
It is driven by
I/ I2STX_C the master and
3 I2S
O LK received by the
slave.
Corresponds to
34
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
General purpose
digital
input/output pin.
5 V tolerant pad
with 5 ns glitch
filter providing
digital I/O
functions with
TTL levels and
hysteresis. Note:
I/
0 P2.10 GPIO 2 A LOW on this
O
pin while
pinsel4 !RESET is LOW
P2.10/!EINT0/N
53 21:20 forces the on-
MI
x chip bootloader
to take over
control of the
part after a reset
and go into ISP
mode. See
Section 32–1.
External
1 I !EINT0 Main
interrupt 0 input.
Non-maskable
2 I NMI Main
interrupt input.
3.3 V supply
voltage: This is
the power supply
VDD(3V3
54 VDD(3V3) I Main voltage for I/O
)
other than pins
in the Vbat
domain.
ground: 0 V
55 VSS I VSS Main
reference.
35
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Request to Send
output for
UART1. Can
also be
1 O RTS1 UART 1
configured to be
an RS-485/EIA-
485 output
enable signal.
CAN1
3 O TD1 CAN 1 transmitter
output.
General purpose
I/
0 P0.21 GPIO 0 digital
O
input/output pin.
pinsel1
Ring Indicator
57 P0.21/RI1/RD1 11:10
1 I RI1 UART 1 input for
x
UART1.
CAN1 receiver
3 I RD1 CAN 1
input.
General purpose
I/
0 P0.20 GPIO 0 digital
O
input/output pin.
Data Terminal
Ready output for
UART1. Can
also be
1 O DTR1 UART 1
configured to be
pinsel1 an RS-485/EIA-
P0.20/DTR1/SC
58 9:8 485 output
L1
x enable signal.
I2C1 clock
input/output
(this pin is not
I/ fully compliant
3 SCL1 I2C 1
O with the I2C-bus
specification, see
Section 19–4 for
details).
36
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
A1 x O input/output pin.
I2C1 data
input/output
(this pin is not
I/ fully compliant
3 SDA1 I2C 1
O with the I2C-bus
specification, see
Section 19–4 for
details).
General purpose
I/
0 P0.18 GPIO 0 digital
O
input/output pin.
Data Carrier
pinsel1 1 I DCD1 UART 1 Detect input for
P0.18/DCD1/M UART1.
60 5:4
OSI0/MOSI
x Master Out
I/
2 MOSI0 SSP 0 Slave In for
O
SSP0.
I/ Master Out
3 MOSI SPI
O Slave In for SPI.
General purpose
I/
0 P0.17 GPIO 0 digital
O
input/output pin.
Clear to Send
pinsel1 1 I CTS1 UART 1 input for
P0.17/CTS1/MIS
61 3:2 UART1.
O0/MISO
x
I/ Master In Slave
2 MISO0 SSP 0
O Out for SSP0.
I/ Master In Slave
3 MISO SPI
O Out for SPI.
37
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Transmitter
1 O TXD1 UART 1 output for
UART1.
General purpose
I/
0 P0.16 GPIO 0 digital
O
input/output pin.
General purpose
I/
0 P2.9 GPIO 2 digital
O
input/output pin.
Signal used to
switch an
external 1.5 kΩ
USB_CO USB- resistor under
P2.9/USB_CON pinsel4 1 O
NNECT Device software control.
64 NECT/RXD2/E 19:18 Used with the
NET_MDIO x SoftConnect
USB feature.
Receiver input
2 I RXD2 UART 2
for UART2.
Ethernet MIIM
I/ ENET_M
3 Ethernet data input and
O DIO
output.
General purpose
I/
pinsel4 0 P2.8 GPIO 2 digital
P2.8/TD2/TXD2/ O
65 17:16 input/output pin.
ENET_MDC
x
1 O TD2 CAN 2 CAN2
transmitter
38
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
output.
Transmitter
2 O TXD2 UART 2 output for
UART2.
General purpose
I/
0 P2.7 GPIO 2 digital
O
input/output pin.
CAN2 receiver
1 I RD2 CAN 2
input.
pinsel4
66 P2.7/RD2/RTS1 15:14 Request to Send
x output for
UART1. Can
also be
2 O RTS1 UART 1
configured to be
an RS-485/EIA-
485 output
enable signal.
General purpose
I/
0 P2.6 GPIO 2 digital
O
input/output pin.
68 General purpose
I/
0 P2.5 GPIO 2 digital
O
P2.5/PWM1.6/D pinsel4 input/output pin.
TR1/TRACEDA 11:10 Pulse Width
TA0 x Modulator 1,
1 O PWM1.6 PWM
channel 6
output.
39
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Data Terminal
Ready output for
UART1. Can
also be
2 O DTR1 UART 1
configured to be
an RS-485/EIA-
485 output
enable signal.
TRACED
3 O Trace Trace data, bit 0.
ATA0
69 General purpose
I/
0 P2.4 GPIO 2 digital
O
input/output pin.
Pulse Width
Modulator 1,
P2.4/PWM1.5/D pinsel4 1 O PWM1.5 PWM
channel 5
SR1/TRACEDA 9:8 output.
TA1 x
Data Set Ready
2 I DSR1 UART 1 input for
UART1.
TRACED
3 O Trace Trace data, bit 1.
ATA1
70 General purpose
I/
0 P2.3 GPIO 2 digital
O
input/output pin.
Pulse Width
Modulator 1,
P2.3/PWM1.4/D pinsel4 1 O PWM1.4 PWM
channel 4
CD1/TRACEDA 7:6 output.
TA2 x
Data Carrier
2 I DCD1 UART 1 Detect input for
UART1.
TRACED
3 O Trace Trace data, bit 2.
ATA2
71 3.3 V supply
VDD(3V3 voltage: This is
VDD(3V3) I Main the power supply
)
voltage for I/O
other than pins
40
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
in the Vbat
domain.
72 ground: 0 V
VSS I VSS Main
reference.
73 General purpose
I/
0 P2.2 GPIO 2 digital
O
input/output pin.
Pulse Width
Modulator 1,
P2.2/PWM1.3/C pinsel4 1 O PWM1.3 PWM
channel 3
TS1/TRACEDA 5:4 output.
TA3 x
Clear to Send
2 I CTS1 UART 1 input for
UART1.
TRACED
3 O Trace Trace data, bit 3.
ATA3
74 General purpose
I/
0 P2.1 GPIO 2 digital
O
input/output pin.
Receiver input
2 I RXD1 UART 1
for UART1.
75 General purpose
I/
0 P2.0 GPIO 2 digital
O
input/output pin.
Pulse Width
pinsel4
P2.0/PWM1.1/T Modulator 1,
1:0 1 O PWM1.1 PWM
XD1 channel 1
x
output.
Transmitter
2 O TXD1 UART 1 output for
UART1.
41
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
.3 x O input/output pin.
Transmit data. It
is driven by the
transmitter and
read by the
I/ I2STX_S
1 I2S receiver.
O DA
Corresponds to
the signal SD in
the I2S bus
specification.
Master Out
I/
2 MOSI1 SSP 1 Slave In for
O
SSP1.
77 General purpose
I/
0 P0.8 GPIO 0 digital
O
input/output pin.
Transmit Word
Select. It is
driven by the
master and
I/ I2STX_W received by the
pinsel0 1 I2S
P0.8/I2STX_WS O S slave.
17:16 Corresponds to
/MISO1/MAT2.2
x the signal WS in
the I2S bus
specification.
I/ Master In Slave
2 MISO1 SSP 1
O Out for SSP1.
78 General purpose
I/
P0.7/I2STX_CL pinsel0 0 P0.7 GPIO 0 digital
O
K/SCK1/MAT2. 15:14 input/output pin.
1 x I/ I2STX_C
1 I2S Transmit Clock.
O LK It is driven by
42
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
79 General purpose
I/
0 P0.6 GPIO 0 digital
O
input/output pin.
Receive data. It
is driven by the
transmitter and
read by the
I/ I2SRX_S
P0.6/I2SRX_SD pinsel0 1 I2S receiver.
O DA
A/SSEL1/MAT2 13:12 Corresponds to
.0 x the signal SD in
the I2S bus
specification.
80 General purpose
I/
0 P0.5 GPIO 0 digital
O
input/output pin.
43
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
CAN2
2 O TD2 CAN 2 transmitter
output.
81 General purpose
I/
0 P0.4 GPIO 0 digital
O
input/output pin.
Receive Clock.
It is driven by
the master and
received by the
I/ I2SRX_C
pinsel0 1 I2S slave.
P0.4/I2SRX_CL O LK
9:8 Corresponds to
K/RD2/CAP2.0 the signal SCK
x
in the I2S bus
specification.
CAN2 receiver
2 I RD2 CAN 2
input.
82 General purpose
I/
0 P4.28 GPIO 4 digital
O
input/output pin.
Transmitter
3 O TXD3 UART 3 output for
UART3.
44
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
reference.
84 3.3 V voltage
regulator supply
voltage: This is
VDD(RE
VDD(REG)(3V3) I Main the supply
G)(3V3)
voltage for the
on-chip voltage
regulator only.
85 General purpose
I/
0 P4.29 GPIO 4 digital
O
input/output pin.
Receiver input
3 I RXD3 UART 3
for UART3.
86 General purpose
I/
0 P1.17 GPIO 1 digital
pinsel3 O
P1.17/ENET_M input/output pin.
3:2
DIO Ethernet MIIM
x I/ ENET_M
1 Ethernet data input and
O DIO
output.
87 General purpose
I/
pinsel3 0 P1.16 GPIO 1 digital
P1.16/ENET_M O
1:0 input/output pin.
DC
x ENET_M Ethernet MIIM
1 O Ethernet
DC clock.
88 General purpose
I/
pinsel2 0 P1.15 GPIO 1 digital
P1.15/ENET_RE O
31:30 input/output pin.
F_CLK
x ENET_RE Ethernet
1 I Ethernet
F_CLK reference clock.
45
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
89 General purpose
I/
pinsel2 0 P1.14 GPIO 1 digital
P1.14/ENET_RX O
29:28 input/output pin.
_ER
x ENET_R Ethernet receive
1 I Ethernet
X_ER error.
90 General purpose
I/
pinsel2 0 P1.10 GPIO 1 digital
P1.10/ENET_RX O
21:20 input/output pin.
D1
x ENET_R Ethernet receive
1 I Ethernet
XD1 data.
91 General purpose
I/
pinsel2 0 P1.9 GPIO 1 digital
P1.9/ENET_RX O
19:18 input/output pin.
D0
x ENET_R Ethernet receive
1 I Ethernet
XD0 data.
92 General purpose
I/
pinsel2 0 P1.8 GPIO 1 digital
O
P1.8/ENET_CRS 17:16 input/output pin.
x ENET_C Ethernet carrier
1 I Ethernet
RS sense.
93 General purpose
I/
0 P1.4 GPIO 1 digital
pinsel2 O
P1.4/ENET_TX_ input/output pin.
9:8
EN Ethernet
x ENET_T
1 O Ethernet transmit data
X_EN
enable.
94 General purpose
I/
pinsel2 0 P1.1 GPIO 1 digital
P1.1/ENET_TX O
3:2 input/output pin.
D1
x ENET_T Ethernet
1 O Ethernet
XD1 transmit data 1.
95 General purpose
I/
pinsel2 0 P1.0 GPIO 1 digital
P1.0/ENET_TX O
1:0 input/output pin.
D0
x ENET_T Ethernet
1 O Ethernet
XD0 transmit data 0.
46
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
96 3.3 V supply
voltage: This is
the power supply
VDD(3V3
VDD(3V3) I Main voltage for I/O
)
other than pins
in the Vbat
domain.
97 ground: 0 V
VSS I VSS Main
reference.
98 General purpose
digital
input/output pin.
When
I/
0 P0.2 GPIO 0 configured as an
O
ADC input,
pinsel0 digital section of
P0.2/TXD0/AD0 the pad is
5:4
.7 disabled.
x
Transmitter
1 O TXD0 UART 0 output for
UART0.
A/D converter 0,
2 I AD0.7 ADC
input 7.
99 General purpose
digital
input/output pin.
When
I/
0 P0.3 GPIO 0 configured as an
O
ADC input,
pinsel0 digital section of
P0.3/RXD0/AD0
7:6 the pad is
.6
x disabled.
Receiver input
1 I RXD0 UART 0
for UART0.
A/D converter 0,
2 I AD0.6 ADC
input 6.
47
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
PICTURE OF ADTV1.1
S1: Turn ON this switch to connect NRST and P2.10( PGM pin) to LPC1768.
S4.1: Turn ON this switch to connect UART1 Tx to P2.0 of LPC1768.
S4.2: Turn ON this switch to connect UART1 Rx to P2.1 of LPC1768.
DIP Switches
S4.3: Turn ON this switch to connect 3.3V to RGB PWM of LPC1768.
Details:
S11.1: Turn ON this switch to connect Buzzer to P0.26 of LPC1768.
S11.1: Turn ON this switch to connect DAC/TP2 to DACOut/P0.26 of LPC1768.
S19.1: Turn ON 8 LEDs, It connects 3.3V to VCC of LEDs.
S19.2: Turn ON 8 LEDs, It connects 5V to VCC of LEDs.
48
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
When pressed, the switches are grounded. When Idle, they are pulled:high
Push-Button Signal Name
SW1(RST/RESET) Reset to LPC1768
SW2 to SW17: Matrix Keypad P1.18 to P1.25
SW18 P2.10/ EINT1
SW20 FPGA Interrupt
SW21 P1.18
Push-Button SW22 P1.19
Switches
Details SW23 P1.20
SW24 P1.21
SW25 P1.22
SW26 P1.23
SW27 P1.24
SW28 P1.25
All the LEDs are connected by common anode method. That means the positive leg
of each LED is connected to Vcc and negative leg to the port pins of the
microcontroller. A logic 0 on the port pin will make LED ON and logic 1 will make
it OFF.
UART0
This is a DB9 female connector, used for RS232 serial communication with the PC:
Pin 2 = UART0 RS232 TxD (output of μC)
49
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
This is a 3pin Relimate connector, used for RS232 serial communication with the
UART1 PC:
Pin 1 = UART1 RS232 TxD (output of μC)
Pin 2 = UART1 RS232 RxD (input to μC)
This is a 16 pin, single line connector, designed for connection to standard, text LCD
modules. The pin/signal correspondence is designed to be matching with that
required by such LCD modules.
Pin 1 = GND
Pin 2 = +5V
Pin 3 = Vlcd
Pin 4 = P1.27 (Used as RS of LCD)
Pin 5 = GND
Pin 6 = P1.26 (Used as EN of LCD)
16x2 LCD
Pin 7 = P0.4 (Used as D0 of LCD)
Pin 8 = P0.5 (Used as D1 of LCD)
Pin 9 = P0.6 (Used as D2 of LCD)
Pin 10 = P0.7 (Used as D3 of LCD)
Pin 11 = P0.8 (Used as D4 of LCD)
Pin 12 = P0.9 (Used as D5 of LCD)
Pin 13 = P0.10 (Used as D6 of LCD)
Pin 14 = P0.11 (Used as D7 of LCD)
Pin 15 = Back lighting
Pin 16 = GND
This standard 4 pin I2C connector provides support for interfacing of I2C based
peripherals to LPC21xx.This connector is mounted on middle-bottom side of the
board as shown in figure1. 4 pin straight cable can be used to connect LPC21xx to
the board having I2C based peripheral devices.
I2C
The pin-out of I2C Connector is given below:
Connector
Pin Signal name
1 ------------- P0.20 (SCL1)
2 ------------- P0.19 (SDA1)
3 ------------- +5V
4 ------------- DGND
Stepper This standard 6 pin connector provides support for interfacing Stepper motor to
Motor LPC1768. The pin-out of Stepper motor Connector is given below:
Connector
Pin Signal name
1 ------------- P0.0
50
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
2 ------------- P0.1
3 ------------- P0.16
4 ------------- P2.3
5 ------------- Vcc (+5V)
6 ------------- GND
51
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
_ Copy the RTX configuration file for your target device from the
\Keil\ARM\RL\RTX\Config\ directory and rename it toRTX_Config.c:
_ for ARM7™/ARM9™devices, copy the configuration file for your specific device.
If the file does not exist for your specific device, then copy the RTX_Conf_LPC21xx.c as a
template and modify it to suit your device.
_ for Cortex-M™devices, copy RTX_Conf_CM.c configuration file.
_ Modify the device startup file for ARM7™/ARM9™devices to enable SWI_Handler
function (no change required for Cortex-M™devices):
_ Comment out the following line from the startup file:
SWI_Handler B SWI_Handler
_ Add the following line to the startup file:
IMPORT SWI_Handler
This change prevents the code from sitting in a loop when a SWI interrupt occurs. The change
allows the right function to run when a SWI interrupt occurs.
_ Copy the retarget.c file from \Keil\ARM\Startup\ to your project directory, and add it to
your project. The main purpoof this file is to avoid the use of semihosting SWIs.
#include <rt_misc.h>
#pragma import(__use_no_semihosting_swi)
void _ttywrch(int ch) {
// Not used (No Output)
}
void _sys_exit(int return_code) {
label: goto label; /* endless loop */
}
_ Depending on your application, you might have to retarget more functions. For example if
you use the RL-FlashFS library, you can obtain retarget.c from the
\Keil\ARM\RL\FlashFS\SRC\ directory.
Note
ForMicroLIB run-time library you do not need a retarget.c in your project.
_ Now you must configure the RTX kernel for the needs of your application by making the
required changes in theRTX_Config.c file.
_ Create the application source files if they do not already exist. Add these source files to the
project. You can do this in the project workspace of μVision by right clicking on the Source
Group and selecting Add Files to Group.
_ When you write programs for RL-RTX, you can define RTX tasks using the __task keyword.
You can use the RTX kernel routines whose prototypes are declared in RTL.h.
_ Configuring RL-RTX
The RTX kernel is easy to customize for each application you create. This section describes
how you can configure the RTX kernel's features for your applications. It contains:
52
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
_ Configuration Options
The RTX kernel must be configured for the embedded applications you create. All
configuration settings are found in the RTX_Config.c file, which is located in the
\Keil\ARM\RL\RTX\Config directory. RTX_Config.cis configured differently for the
different ARM devices. Configuration options in RTX_Config.c allow you to:
_ Specify the number of concurrent running task.
_ Specify the number of tasks with user-provided stack
_ Specify the stack size for each task
_ Enable or disable the stack checking
_ Enable or disable running tasks in privileged mode
_ Specify the CPU timer number used as the system tick timer
_ Specify the input clock frequency for the selected timer
_ Specify the timer tick interval
_ Enable or disable the round-robin task switching
_ Specify the time slice for the round-robin task switching
_ Define idle task operations
_ Specify the number of user timers
_ Specify code for the user timer callback function
_ Specify the FIFO Queue size
_ Specify code for the runtime error function
There is no default configuration in the RL-RTX library. Hence, you must add the
RTX_Config.cconfiguration file to each project you create.
To customize the RTX kernel's features, you must change the configurable settings in
RTX_Config.c.
Example:
Note:
_ On some devices, the IDLE blocks debugging via the JTAG interface. Therefore JTAG
debuggers such as ULINK may not work when you are using CPU power-saving modes.
_ For using power-saving modes, some devices may require additional configuration (such as
clock configuration settings).
Some system error conditions can be detected during runtime. If RTX kernel detects a runtime
error, it calls the os_error() runtime error function.
The runtime error function must contain an infinite loop to prevent further program execution.
You can use an emulator to step over infinite loop and trace into the code introducing a runtime
error. For the overflow errors this means you need to increase the size of the object causing an
overflow.
_ Peripheral Timer for generating periodic ticks. It is better to use a peripheral timer with an
autoreload function. RTX also supports timers with manual timer (or counter) reload. However,
this can generate jitter and inaccuracy in the long run. The RTX kernel needs a count-up timer.
If the timer used is a count-down timer, you need to convert the timer value.
_ Timer Interrupts to interrupt the execution of a task and to start the system task scheduler.
54
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
_ Forced Interrupts to force a timer interrupt when isr_ functions are used. If an isr_ function
is called, the kernel forces the timer interrupt immediately after the interrupt ends. The forced
timer interrupt activates the task scheduler. It is possible that a task has become ready. If this
task has a higher priority than the currently running task, a task switch must occur.
All hardware dependent definitions are extracted from the code and defined with configuration
macros.
This makes it possible to customize the configuration without modifying the code.
Note:
The RTX configuration files are located in the \Keil\ARM\RL\RTX\Config directory.
Configuration
To configure an alternate peripheral timer as system tick timer, you have to:
1. implement the os_tick_init() and os_tick_irqack() functions in the RTX_Config.c
configuration file.
2.Replace the alternate timer interrupt vector with the OS_Tick_Handler in the Interrupt
Vector Table in startup file.
Note:
An RTX_Blinky_RIT example, located in \Keil\ARM\Boards\MCB1700 directory, is a demo
example, configured for alternate tick timer in Cortex-M3.
55
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Configuration
The Low Power RTX is controlled from the idle task. The peripheral wake-up timer must be
initialized before the system enters an endless loop.
The function os_suspend() calculates the timeout until the first suspended task becomes ready,
and returns the timeout to the user.
for (;;) {
sleep = os_suspend();
The user sets-up a peripheral timer to sleep timeout and starts the timer. The timeout is
measured in system ticks.
if (sleep) {
/* Setup the wake-up timer ... */
When the wake-up timer is set-up and running, the user puts the system in power-down mode.
The wake-up timer must run also in power-down mode. All other peripherals and the CPU may
power-down to reduce power.
If, for any reason, the system does not wake up immediately after the wake-up interrupt, the
actual sleep time is checked and adjusted.
RTX_LowPower demo examples configured for low power RTX:
_ Usage of the WFE instruction for entering sleep mode is demonstrated in the
RTX_LowPower example located in the directory
\Keil\ARM\Boards\Keil\MCBSTM32F200.
_ Usage of the WFI instruction for entering sleep mode and early wake-up mechanism is
demonstrated in RTX_LowPower example located in the directory
\Keil\ARM\Boards\MCB1000\MCB11U10.
Hence, you can implement these activities as two separate tasks, called task1 and task2:
1. Place the code for the two activities into two separate functions (task1 and task2). Declare
the two functions as tasks using the keyword __task (defined in RTL.H) which indicates a
RTX task.
2. When the system starts up, the RTK kernel must start before running any task. To do this,
call the os_sys_init function in the C main function. Pass the function name of the first task as
the parameter to the os_sys_init function. This ensures that after the RTX kernel initializes, the
task starts executing rather than continuing program execution in themain function. In this
example, task1 starts first. Hence, task1 must create task2. You can do this using
the os_tsk_create function.
__task void task1 (void) {
os_tsk_create (task2, 0);
.... place code of task 1 here ....
}
__task void task2 (void) {
.... place code of task 2 here ....
}
void main (void) {
os_sys_init (task1);
}
3. Now implement the timing requirements. Since both activities must repeat indefinitely, place
the code in an endless loop in each task. After the task1 activity finishes, it must send a signal
to task2, and it must wait for task2 to complete. Then it must wait for 50 ms before it can
perform the activity again. You can use the os_dly_wait function to wait for a number of
system intervals.
The RTX kernel starts a system timer by programming one of the on-chip hardware timers of
the ARM processors. By default, the system interval is 10 ms and timer 0 is used (this is
configurable). You can use the os_evt_wait_or function to make task1 wait for completion of
task2, and you can use the os_evt_setfunction to send the signal to task2. This examples uses
bit 2 (position 3) of the event flags to inform the other task when it completes.
task2 must start 20 ms after task1 completes. You can use the same functions in task2 to wait
and send signals to task1. The listing below shows all the statements required to run the
example:
s completed. */
os_evt_set(0x0004, id2);
/* 0xFFFF makes it wait without timeout. */
/* 0x0004 represents bit 2. */
os_evt_wait_or(0x0004, 0xFFFF);
/*Wait for 50 ms before restarting task1 activity. */
os_dly_wait(5);
}
}
__task void task2 (void) {
for (;;) {
/*Wait for completion of task1 activity. */
/* 0xFFFF makes it wait without timeout. */
/* 0x0004 represents bit 2. */
os_evt_wait_or(0x0004, 0xFFFF);
/*Wait for 20 ms before starting task2 activity. */
os_dly_wait(2);
/* ... place code for task2 activity here ... */
/* Signal to task1 that task2 has completed. */
os_evt_set(0x0004, id1);
}
}
void main (void) {
/* Start the RTX kernel, and then create and execute task1. */
os_sys_init(task1);
}
4. Finally, to compile the code and link it with the RTX library, you must select the RTX
operating system for the project. From the main menu, select Project —> Options for Target.
Select the Target tab. Select RTX Kernel for the Operating system. Build the project to
generate the absolute file. You can run the object file output from the linker either on your
target or on the μVision Simulator
58
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Aim :
To interface the LEDs with LPC1768
Algorithm :
Step 1: Start the program
Step 2: Configure Port0 as GPI0
Step 3: Interfacing Port0 as Output
Step 4: Logic High on Port0
Step 5: Call Delay
Step 6: Logic Low on Port0
Step 7: Call Delay
Step 8: Go to step 4
Flow Chart:
Start
Call Delay
Call Delay
59
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Program:
#include "LPC17xx.h"
while(1)
{
LPC_GPIO0->FIOCLR = ~((LPC_GPIO1->FIOPIN & 0x03FC0000)>>14);
// Status of Input Switches are copied to LEDs,
//
Respected LEDs pressed switched are On.
Peripheral Interface: Keep SW19.2 switch in ON position. 8 LEDs (D11 to D18) present on ADT
are connected to P0.4,P0.5,P0.6,P0.7,P0.8,P0.9,P0.10 and P0.11 respectively by Common Anode
method.
Output:
You can see blinking of LEDs.
Note: Keep SW19.2 switch in OFF position to save power, after execution of program.
Result:
Thus interfacing of leds with LPC1768 is executed and verified successfully.
Exercise:
1. Develop an embedded C code to blink LED with different delays (5 secs ,10 secs ) using the
software delay.
2. Develop an embedded C code to blink LED with different sequence.
60
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Aim :
To interface Buzzer (ON-OFF) with LPC1768.
Algorithm :
Step 1: Start the program
Step 2: Configure PORT0 as output
Step 3: Set logic high on PORT0
Step 4: Call Delay
Step 5: Set logic low on PORT0
Step 6: Call Delay
Step 7: Go to step3
Program:
#include "LPC17xx.h"
#include <stdio.h>
volatile unsigned int delay;
void MyDelay(void)
{
int i;
for(i=0;i<10;i++)
for(delay=0;delay<65000;delay++);
}
int main (void)
{
while(1)
{
LPC_GPIO0->FIOSET = 0x04000000 ; //Buzzer ON
MyDelay();
LPC_GPIO0->FIOCLR = 0x04000000 ; //Buzzer OFF
MyDelay();
}
}
Output:
Buzzer will turn ON and OFF.
Note: Keep S11.1 switch in OFF position, after execution of program.
Result:
Thus, interfacing of Buzzer with LPC1768 is executed and verified successfully.
Exercise:
1. Develop an embedded C code to enable buzzer with different tones.
61
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Aim :
To interface Digital Input and Output with LPC1768.
Algorithm :
Step 1: Start the program
Step 2: Configure P0.16 to P0.23 as GPIO
Step 3: Configure P0.16 to P0.23 as GPIO using LPC_PINCON structure and PINSEL3 element
Step 4: Configure pins P0.16 to P0.23 as input
Step 5: Configure pins P0.16 to P0.23 as GPIO
Step 6: Configure pins P0.16 to P0.23 as output
Step 7: Copy the states of the input switches to LED’s
Step 8: Stop
Program:
#include "LPC17xx.h"
while(1)
{
LPC_GPIO0->FIOCLR = ~((LPC_GPIO1->FIOPIN & 0x03FC0000)>>14);
// Status of Input Switches are copied to LEDs,
62
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Output:
After pressing any switch from SW21 to SW28, its corresponding LED (D11 to D18) will become
ON otherwise it will be OFF.
Result:
Thus interfacing of digital inputs and outputs with LPC1768 is executed and verified successfully.
Exercise:
63
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Aim :
To interface ADC with LPC 1768.
Algorithm :
Step 1: Start the program
Step 2: Declare the variable to hold ADC converted value
Step 3: Function is declared and defined for ADC initialization
Step 4: Configure PO.23 as ADC input using PINSELI
Step 5: Declare the variable ADC data
Step 6: Select clock for ADC to start of conversion
Step 7: Check end of conversion and read result
Step 8: Return the 12 bit result to main function
Step 9: Call the functions TargetResetInit(), ADC_Init(), InitUART0()
Step 10: Display ADC test
Step 11: Read the ADC value to convert
Step 12: Convert to volts using adc=(5*adc)/1023
Step 13: Display the result on UART
Step 14: Stop
Program:
#include "LPC17xx.h"
#include "stdio.h"
#include "UART0.h"
#include "target.h"
#define PCADC 0x00001000
LPC_ADC->ADCR =0x01200301 ;
// Select AD0.0, Select clock for ADC, Start of conversion,
}
int main (void)
{
unsigned int delay;
float adc;
TargetResetInit();
ADC_Init() ; // Initiate ADC Setting
InitUart0();
printf("ADC Test"); // Display ADC Test
while(1)
{
adc = ADC_GetAdcReading(); // Read AD0.7 reading
adc=(5*adc)/1023;// Convertion of ADC value in Volts
sprintf(adcreading,"\n ADC0 CH1= %.2f V",adc);
// Convert result into ASCII to display it on LCD
UART0Puts(adcreading) ;// Display result on UART
for(delay=0;delay<60000;delay++);
}
}
Peripheral Interface:
To give analog input from Potentiometer R15 present in Analog Input region on
ADTV1.1. Analog input range is from 0 to 1023.
Output:
You can see output on Hyper Terminal.
Therefore Open Hyper Terminal. Go to Start->All Programs->Accessories->Communications-
>Hyper Terminal->Assign the Respective port-> Settings. Do proper settings (Baud Rate: 19200,
Data
Bits: 8, Stop Bits: 1, Echo: Off, Parity: None, Com Port: Com 1 (if other choose it)). Click on OK. Go
to
Port -> Open. If required Reset the ADT board. Now vary the R15 POT and hence see the change in
voltage on Hyper Terminal.
Result:
Exercise:
65
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Aim :
To interface DAC with LPC1768.
Algorithm :
Step 1: Start the program
Step 2: Declare the variable to store output of DAC
Step 3: Call Target Reset Init() function
Step 4: Clock selection for DAC is done
Step 5: Select the DAC output pin
Step 6: Call delay for sometime
Step 7: Aout value is shifted right by 6bits for the loop to count from 0 to 1024
Step 8: Call Delay
Step 9: Again the loop count for 1024 times
Step 10: Aout value is again shifted right by 6times
Step 11: Stop
Program:
#include "LPC17xx.h"
#include <stdio.h>
#include "target.h"
unsigned int delay,AoutValue = 0 ;
// Variable to store the output value of DAC
66
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Output:
You can see ramp wave on oscilloscope.
Note: Keep S11.2 switch in OFF position, after execution of program
Result:
Exercise:
67
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Aim :
To interface LED and PWM(RGB) with LPC1768 .
Algorithm :
Step 1: Start the program
Step 2: Set the GPIO for all pins by PINSEL on PWM2 for RED color in PWM_Init() function
Step 3: Read the Latch enable resistor and enable PWM2 by setting PWM control resister
Step 4: If the color is Green set the pins on PWM4
Step 5: Load the LED and enable PWM4 by setting PWM control register
Step 6: If the color is Blue, set the pins of PWM on PWM6
Step 7: Load LED and enable PWM6 by control register
Step 8: If the color is equal to all set the pins on AWM0
Step 9: Load LED and enable PWM2, PWM4 by setting PWM control register
Step 10: Control is Reset and count frequency = Fp clks
Step 11: For some Cycle one color is enabled and i+ continuously changing for every clock cycle
Step 12: Stop
Program:
#include "LPC17xx.h"
#include <stdint.h>
#include "PWM.h"
#include "lpc_types.h"
68
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
// TC if PWM0 matches
LPC_PWM1->MR0 = cycle;// set PWM cycle
LPC_PWM1->MR1 = cycle * 5/6;
LPC_PWM1->MR2 = cycle * 5/6; // cycle * 2/3;
LPC_PWM1->MR3 = cycle * 5/6 ;// cycle * 1/2;
LPC_PWM1->TCR = TCR_CNT_EN | TCR_PWM_EN;
// counter enable, PWM enable
return (1);
}
Peripheral Interface:
Output:
You can see RED,BLUE,GREEN color blinking on RGB Led.
Note: Keep S4.3 switch in OFF position, after execution of program
Result:
Thus interfacing of LEDS and PWM(RGB) with LPC1768 is executed and verified successfully
69
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Aim :
To interface Real Time Clock on Serial UART with LPC1768.
Algorithm :
Step 1: Start the program
Step 2: Enable Divisor latch access ,set 8 bit word length, stop bit no parity, disable break
transmission
Step 3: Set UPB bus clock divisor
Step 4: Set UART0 divisor latch(LSB)
Step 5: Set UART0 divisor latch(MSB)
Step 6: Clear TxFIFO and enable Rx and TxFIFOS
Step 7: Wait until Trasnsmit holding register is empty
Step 8: Store to transmit holding register.
Step 9: Wait until Trasnsmit holding register is empty
Step 10: Then Store to transmit holding register.
Step 11: Wait until there’s a character table read
Step 12: Then read from the receiver buffer register.
Program:
#include "LPC17xx.h"
#include "target.h"
#include "UART0.h"
#include <stdio.h>
#include <string.H>
#include "I2C_RTC.h"
#include "Timer.h"
char MAIN_u8buffer1[20];
char MAIN_u8buffer2[20];
#define PCF8523 1
#ifdef PCF8523
#define OFFSET 3
#endif
#ifdef DS1307
#define OFFSET 0
#endif
#define CONTROL_ADDR0 0
#define CONTROL_ADDR1 1
#define CONTROL_ADDR2 2
#define SECONDS_ADDR 3
#define MINUTES_ADDR 4
#define HOURS_ADDR 5
#define DATE_ADDR 6
#define DAY_ADDR 7
#define MONTH_ADDR 8
#define YEAR_ADDR 9
70
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
int main(void)
{
TargetResetInit();
InitUart0();
I2C_Init();
TIMER_Init();
printf("Clock:\nPress 'S' (to set RTC) Within 5 seconds, any other to discard") ;
for(delay=0; delay<=800000;delay++)
{
if (UART0_IsReady())
break;
}
I2C_WriteToRTC(HOURS_ADDR,hh,1) ;
I2C_WriteToRTC(MINUTES_ADDR,mm,1) ;
I2C_WriteToRTC(SECONDS_ADDR,ss,1) ;
}
else;
}
printf("\n");
while(1)
{
if (!(I2C_ReadFromRTC(OFFSET, MAIN_u8buffer, 7)))
printf("Main Buffer %s \n",MAIN_u8buffer);
printf("\r\nClock : ");
printf("Date : %02x",MAIN_u8buffer[DATE_ADDR-OFFSET]& 0x3F);
printf("-%02x",MAIN_u8buffer[MONTH_ADDR-OFFSET]& 0x1F);
printf("-%02x",MAIN_u8buffer[YEAR_ADDR-OFFSET]);
printf(" Time : %02x",MAIN_u8buffer[HOURS_ADDR-OFFSET]& 0x1F);
printf(":%02x",MAIN_u8buffer[MINUTES_ADDR-OFFSET]& 0x7F);
printf(":%02x",MAIN_u8buffer[SECONDS_ADDR-OFFSET]& 0x7F);
while(1)
{
ss = MAIN_u8buffer[SECONDS_ADDR-OFFSET] & 0x7F;
if (!I2C_ReadFromRTC(OFFSET, MAIN_u8buffer, 7))
printf("\nMemory Read error..$");
if (ss != (MAIN_u8buffer[SECONDS_ADDR-OFFSET] & 0x7F))
break;
}
}
}
72
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Peripheral Interface:
No switches are there to turn ON/OFF I2C RTC
Output:
You can see output on Hyper Terminal.
Therefore Open Hyper Terminal. Go to Start->All Programs->Accessories->Communications-
>Hyper Terminal->Assign the Respective port-> Settings. Do proper settings (Baud Rate: 19200,
Data Bits: 8, Stop Bits: 1, Echo: Off, Parity: None, Com Port: Com 1 (if other choose it)). Click on
OK. Go to Port -> Open. If required Reset the ADT board.On terminal after reset, press “Shift-S’ to
set DD MM YY HH MM SS format and press enter. To save the RTC press “Shift-Y”,now you can
see the RTC getting updated.
Result:
Thus interfacing of real time clock on serial UART with LPC1768 is executed and verified
successfully.
Exercise:
73
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Aim :
To interface I2C based EEPROM with LPC1768.
Algorithm :
Step 1: Start the program
Step 2: Power on LPCI2C TO I2peripheral
Step 3: Initialize timer, define port pin as SDA&SCL
Step 4: Clear all I2C configure bits and set I2EN
Step 5: Wait for the status if status returns true or false
Step 6: Read data from RTC
Step 7: Ready for device address & ready for data bytes
Step 8: Transmit start address and if received return ACK
Step 9: Clear SI flag
Step 10: Write data to RTC
Step 11: Check the upper limit & write data byte wise
Step 12: After writing clear all except I2REN
Step 13: Clear all except I2N
Step 14: Transmit start address & port for write down
Step 15: Generate stop condition
Program:
#include "LPC17xx.h"
#include <Stdio.h>
#include "UART0.h"
#include "I2C.h"
#include "TIMER.h"
#include "target.h"
unsigned char *MAIN_u8buffer1;
unsigned char MAIN_u8buffer2[20] ;
unsigned char MAIN_u8temp = 0;
unsigned char MAIN_u8temp12[2][2]={0,1,2,3};
int main()
{
TargetResetInit();
LPC_PINCON->PINSEL0 |= 0x00000005 ;
InitUart0();
I2C_Init();
TIMER_Init();
MAIN_u8temp=MAIN_u8temp12[0][0];
MAIN_u8buffer1 = (unsigned char*)MAIN_u8temp12;
while(1)
{
if (!I2C_WriteToEEPROM(0, MAIN_u8buffer1, 10))
printf("\nMemory write error..");
printf("\n%x",MAIN_u8buffer2[1]);
printf("\n%x",MAIN_u8buffer2[2]);
printf("\n%x",MAIN_u8buffer2[3]);
while(1);
}
}
Peripheral Interface:
Output:
You can see output on Hyper Terminal.
Therefore Open Hyper Terminal. Go to Start->All Programs->Accessories->Communications-
>Hyper Terminal->Assign the Respective port-> Settings. Do proper settings (Baud Rate: 19200,
Data
Bits: 8, Stop Bits: 1, Echo: Off, Parity: None, Com Port: Com 1 (if other choose it)). Click on OK.
Go to Port -> Open. If required Reset the ADT board. It will display 2 option Read and Write. We
have to first select Write. Type something max of 20 character length. And reset the board and
select Read option.
Result:
Thus interfacing I2C based EEPROM with LPC1768 is executed and verified successfully
Exercise:
1.Develop an embedded C code to transfer image file & store it in EEPROM & retrieve it
75
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Aim :
To interface LCD with LPC1768
Algorithm :
Step 1: Start the pogram
Step 2: Write delay function for small delay and large delay
Step 3: Send command on the data lines
Step 4: Clear Reset (RS) and enable (EN)
Step 5: Set the enable PIN and call delay
Step 6: Clear the enable (EN) and call delay
Step 7: Send the data on data lines (D0 to D7)
Step 8: After sending the data Reset (RS) is set and call delay
Step 9: Clear the pin EN and call delay
Step 10: Set the pin EN and Call delay
Step 11: Clear the pin EN and call delay
Step 12: Configure the pins PO.15 (D4), PO.17 (D5), PO.22 (D6) and
PO.30 (D7) as output
Step 13: Clear all the pins and configure the pins as GPIO and clear all pins
Step 14: Call the function LCD cmd and call delay
Step 15: Delay function is written which has pass pointer to character string
Step 16: Display the character using display data
Step 17: Stop
Program:
/*
This file contains LCD related sub-routines for EDU-ARM7-2148 Trainer Kit.
LCD connections:
P1.26 P1.27 P0.11 P0.10 P0.9 P0.8 P0.7 P0.6 P0.5 P0.4
RS EN D7 D6 D5 D4
D3 D2 D1 D0
8 bit interface is used.
*/
#include "LPC17xx.h"
#include <stdio.h>
#include "LCD.h"
#include "target.h"
int main ()
{
volatile int l;
TargetResetInit();
LcdInit();
while(1)
{
DisplayRow (1," SPJ EMBEDDED ");
DisplayRow (2," Technologies ");
}
76
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Peripheral Interface:
Output:
In this program after pressing any key from SW2 to SW17, its code will be displayed on 16x2 Text
LCD.
Result:
Exercise:
1. Develop an embedded C code to scroll the text from left to right in LCD display.
77
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Aim :
To interface External Interrupt with LPC1768.
Algorithm :
Step 1: Start the program
Step 2: Main function
Step 3: Initialize INIT interrupt pin
Step 4: Level sensitive mode on EINT1
Step 5: Low active or negative edge sensitive
Step 6: Clear EINT0 interrupt flag
Step 7: Set flag
Step 8: Clear EINT1 interrupt flag
Step 9: Check flag and clear flag
Step 10: Stop
Program:
#include "LPC17xx.h"
#include "target.h"
//#define EINT0_IRQn (1<<18)
void EINT0_IRQHandler(void)__irq;
unsigned char Eint0Detect = 0;
unsigned int DisplayTime = 0 ;
void InitEint0(void)
{
void EINT0_IRQHandler(void)__irq
{
LPC_GPIO0->FIOCLR |= 0x00000010;
Eint0Detect = 1 ; // Set flag
LPC_SC->EXTINT = 0x01; // Clear EINT1 interrupt flag
78
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
NVIC_EnableIRQ(EINT0_IRQn);
while(1)
{
if(Eint0Detect) // Check flag
{
Eint0Detect = 0 ; // Clear flag
LPC_GPIO0->FIOSET = (LPC_GPIO0->FIOSET | 0x00000010);
}
}
}
Peripheral Interface:
To connect SW19.2 switch to EINT1 of LPC1768, keep it in ON position
Output:
EINT1 is configured as Low-active, Level Sensitive. Therefore if SW18 switch is pressed then D11
LED
will glow for that much of time only.
Note: Keep SW19.2 switch in OFF position, after execution of program.
Result:
Thus interfacing of external interrupt with LPC1768 is executed and verified successfully
Exercise:
79
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Aim :
To interface Stepper Motor with LPC1768.
Algorithm :
Step 1: Start the program
Step 2: Assign the values for the phase A,B,C,D
Step 3: Configure the pins as GPIO and assign the pin as output in Port0 and set the LED as OFF
Step 4: Configure the pins P0.28 to P0.31 as GPIO and also as output
Step 5: Set the LED OFF in Port1
Step 6: Configure the pins P0.28 to p0.31 as GPIO and as output in Port2
Step 7: Set the LEDs OFF
Step 8: Move the Stepper Motor in clockwise direction
Step 9: Phase D is excited to rotate in clockwise direction
Step 10: Phase C is excited to rotate motor and call delay
Step 11: Phase B is excited to rotate the motor and call delay
Step 12: Phase A is excited to rotate motor and call delay
Step 13: Stop
Program:
#include "LPC17xx.h"
int main(void)
{
LPC_PINCON->PINSEL0 = LPC_PINCON->PINSEL0 & ~ 0x0000000F ;
// Configure P0.28 to P0.31 as GPIO
LPC_GPIO0->FIODIR = LPC_GPIO0->FIODIR | 0x00000003 ;
// Configure P0.28 to P0.31 as Output
LPC_GPIO0->FIOSET = LPC_GPIO0->FIOSET | 0x00000003 ;
// SET (1) P0.28 to P0.31, LEDs OFF
LPC_PINCON->PINSEL1 = LPC_PINCON->PINSEL1 & ~ 0x00000003 ;
// Configure P0.28 to P0.31 as GPIO
LPC_GPIO0->FIODIR = LPC_GPIO0->FIODIR | 0x00010000 ;
// Configure P0.28 to P0.31 as Output
LPC_GPIO0->FIOSET = LPC_GPIO0->FIOSET | 0x00010000 ;
// SET (1) P0.28 to P0.31, LEDs OFF
while(1)
{
// Move stepper motor in anti clockwise direction
//LPC_GPIO2->FIOSET = PHASEC ;
// Phase C is excited to rotate the motor
//LPC_GPIO2->FIOCLR = (~PHASEC) & 0x0000000F ;
// Phase C is cleared
for(delay=0; delay<80000; delay++) ;
// Small time Delay
//LPC_GPIO2->FIOSET = PHASEB ;
// Phase B is excited to rotate the motor
//LPC_GPIO2->FIOCLR = (~PHASEB) & 0x0000000F ;
// Phase B is cleared
for(delay=0; delay<80000; delay++) ;
// Small time Delay
Peripheral Interface:
No Switches are there to Stepper Motor is connected to P0.28, P0.29, P0.30 and P0.31 through
LEDs D7 to D10.Connect the Stepper motor at connector X3.
Output:
You can see stepper motor moving in a particular direction and corresponding phase changes you
can observe on LEDs D7 to D10.
Result:
Thus interfacing of stepper motor with LPC1768 is executed and verified successfully
Exercise:
82
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Aim :
To interface LM35 (Temperature Sensor) with LPC1768.
Algorithm :
Step 1: Start the program
Step 2: Declare the variables delay, ADC, Temp and Temperature
Step 3: Call the function TargetResetInit()
Step 4: Call the function InitUART0()
Step 5: Call the function ADC_Init()
Step 6: UART0 puts (“ADC LM 35 Test”) function is called
Step 7: Read ADC value
Step 8: Calculate Temperature using Temp, (adc*3.3)
Temperature = (Temp/1023)*100
Step 9: Display the temperature on LCD convert the result for ASCII to delay
Step 10: Delay
Program:
#include "LPC17xx.h"
#include "stdio.h"
#include "UART0.h"
#include "target.h"
LPC_ADC->ADCR = 0x01200302 ;// Select AD0.7, Select clock for ADC, Start of conversion,
while(!((adcdata = LPC_ADC->ADGDR) & 0x80000000))
// Check end of conversion (Done bit) and read result
{
}
return((adcdata >> 6) & 0x3ff) ; // Return 10 bit result
}
int main (void)
{
unsigned int delay,adc;
float Temp, Temperature;
83
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
//float adc;
TargetResetInit();
InitUart0();
ADC_Init() ;
// Initiate ADC Setting
UART0Puts("ADC LM35 Test");
// Display ADC Test
while(1)
{
adc = ADC_GetAdcReading(); //
Read AD0.7 reading
// Calculate Temperature
Temp = (adc * 3.3);
Temperature = (Temp / 1023) * 100;
for(delay=0;delay<60000;delay++);
}
}
Peripheral Interface:
To interface LM35 (present in Analog Input region on ADT Board) with P0.24 .
Output:
You can see output on Hyper Terminal.
Therefore Open Hyper Terminal. Go to Start->All Programs->Accessories->Communications-
>Hyper Terminal->Assign the Respective port-> Settings. Do proper settings (Baud Rate: 19200,
Data Bits: 8, Stop Bits: 1, Echo: Off, Parity: None, Com Port: Com 1 (if other choose it)). Click on
OK. Go to Port -> Open. If required Reset the ADT board. You can see the temperature on Hyper
Terminal changing if you give some heat(even rubbing the sensor produces heat).
Result:
Thus interfacing of LM35 (Temperature Sensor) with LPC1768 is executed and verified
successfully
Exercise:
84
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Aim :
To Interface ZIGBEE on Serial UART with LPC1768.
Algorithm :
Step 1: Start the program
Step 2: Enable divisor latch access set 8bit word length, 1 stop bit, no parity bit
Step 3: Disable break transmission
Step 4: Enable bus clock divider
Step 5: Enable divisor latch (LSC)&(MSB)
Step 6: Disable divisor latch access
Step 7: Clear TxFIFO and enable Tx and Tx FIFOs
Step 8: Wait until transmit holding register is empty
Step 9:Then store to transmit holding register and wait until character is to be read
Step 10:Then read from the receiver buffer register
Step 11:stop
Program:
#include "LPC17xx.h"
#include <stdio.h>
#include <string.h>
#include "target.h"
#include "UART0.h"
#include "UART1.h"
#include "lpc_types.h"
int main(void)
{ //char ch1;
char ch;
TargetResetInit();
InitUart0();
InitUart1();
UART0Puts("\nWelcome to Xee-Bee Testing\n");
while(1)
{
if(UART1_IsReady())
{
UART0putchar(UART1_getchar());
}
if(UART0_IsReady())
{
ch = UART0getchar();
printf("%c",ch);
}
}
}
85
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Output:
You can see output on Hyper Terminal.
Therefore Open Hyper Terminal. Go to Start->All Programs->Accessories->Communications-
>Hyper Terminal->Assign the Respective port-> Settings. Do proper settings (Baud Rate: 19200,
Data
Bits: 8, Stop Bits: 1, Echo: Off, Parity: None, Com Port: Com 1 (if other choose it)). Click on OK.
Go to
Port -> Open. If required Reset the ADT board.
Press reset on both boards type something on keyboard of PC that respective key pressed is
transmitted from that PC to another PC using Zigbee.
Result:
Thus interfacing of ZIGBEE on Serial UART with LPC1768 is executed and verified successfully
86
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Aim :
To interface Matrix Keyboard with LPC1768.
Algorithm :
Step 1: Start the program
Step 2: Define the ports P1.21, P1.20, P1.19, P1.18 for RET pins
Step 3: For scanning assign pins P2.25, p1.26, P1.23, P1.22
Step 4: Assign crystal frequency 12KHz and PLL multiplier as 1
Step 5: Direct the Rs, Rw of LCD as GPIO
Step 6: Call the delay
Step 7: Check whether the key is down or up
Step 8: If the key is down return 1
Step 9: If key is not pressed check for other key
Step 10: if already the key is pressed wait until it is pressed
Step 11: Return the key has been released and it is enable 10-1 also return 0
Step 12: Stop
Program:
#include "LPC17xx.h"
#include <stdio.h>
#include <string.h>
#include "target.h"
#include "UART0.h"
#include "KBD.h"
int i8ch ;
char szTemp[16] ;
int main (void)
{
TargetResetInit();
InitUart0();
UART0Puts("Keypad Test \n");
while(1)
{
i8ch = KBD_rdkbd() ; // Read Keyboard
sprintf(szTemp,"\nKeyCode = %02X",i8ch); // Convert keycode into ASCII to display
it on LCD
UART0Puts(szTemp) ; // Display keycode on 2nd line of LCD
}
}
Result:
87
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
ADDITIONAL EXPERIMENTS
Ex. No. 1 INTERFACING BLUETOOTH MODULE
DATE:
Aim :
To write an embedded C code for interfacing Bluetooth Module with ARM CORTEX M3-
LPC2148.
Circuitdiagram
Procedure:
Give +3.3V power supply to LPC2148 Primer Board; connect the 5V adapter with
Bluetooth module which is connected with the LPC2148 Primer Board. There are two
Bluetooth modules are required. One is connected with LPC2148 Primer Board; other one is
connected with PC.First connect the serial cable between LPC2148 Primer board & PC.
Then open the Hyper Terminal screen, select which port you are using and set the default
settings. Now the screen should show some text messages. If the messages are correctly
displayed in Hyper Terminal, then only connect the Bluetooth modules in LPC2148 Primer
Board UART0 & PC.If you are not reading any data from UART0, then you just check the
jumper connections & just check the serial cable is working. Otherwise you just check the
code with debugging mode in Keil.
88
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Program:
#define CR 0x0D
#include <LPC21xx.H>
void init_serial (void);
int putchar (int ch);
int getchar (void);
unsigned char test;
int main(void)
{
char *Ptr = "*** UART0 Demo ***\n\n\rType Characters to be echoed!!\n\n\r";
VPBDIV = 0x02; // Divide Pclk by two
init_serial();
while(1)
{
while (*Ptr) { putchar(*Ptr++);
} putchar(getchar()); // Echo terminal
}
}
void init_serial (void)
{
PINSEL0 = 0x00000005; // Enable RxD0 and TxD0
U0LCR = 0x00000083; //8 bits, no Parity, 1 Stop bit
U0DLL = 0x000000C3; //9600 Baud Rate @ 30MHz VPB Clock
U0LCR = 0x00000003;
}
int putchar (int ch)
{
if (ch == '\n')
{
while (!(U0LSR & 0x20));
U0THR = CR;
}
while (!(U0LSR & 0x20));
return (U0THR = ch);
}
int getchar (void)
{
while (!(U0LSR & 0x01));
return (U0RBR);
}
Result:
Thus, interfacing of GSM module with ARM CORTEX M3- LPC2148 using embedded C
code was executed and verified successfully.
Ex. No. 2 INTERFACING GSM MODULE
DATE:
89
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Aim :
To write an embedded C code for interfacing GSM Module with ARM CORTEX M3-
LPC2148.
Circuit Diagram
Procedure:
Give +3.3V power supply to LPC2148 Primer Board; connect the +5V adapter with GSM
module which is connected with LPC2148 Primer Board through UART0. Open the Hyper
Terminal screen, select which port you are using and set the default settings. Now the
screen should show some text messages.
The following Commands and sequence of events performed for sending text message to a
mobile phone through GSM Modem interfaced with microcontroller:
First select the text mode for SMS by sending the following AT Command to GSM
Modem : AT+CMGF = 1 . This command configures the GSM modem in text mode.
Send the following AT Command for sending SMS message in text mode along with
mobile number to the GSM Modem : AT+CMGS =+923005281046 . This command
sends the mobile number of the recipient mobile to the GSM modem.
Send the text message string ("hello!") to the GSM Modem This is a test message
from UART".
Send ASCII code for CTRL+Z i.e., 0x1A to GSM Modem to transmit the message to
mobile phone. After message string has been sent to the modem, send CTRL+Z to the
micro-controller, which is equivalent to 0x1A (ASCII value).
90
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
If you not reading any text from UART0, then you just check the jumper connections & just
check the serial cable is working. Otherwise you just check the code with debugging mode
in Keil. If you want to see more details about debugging just see the videos in below link.
Program:
#define CR 0x0D
#include <LPC21xx.H>
#include <stdio.h>
void getstring(unsigned char *);
int getchar (void) /* Read character from Serial Port */
void status_ok(void);
void Serial_Init(void);
void delay(unsigned int n);
void main(void)
{
unsigned int
cnt=0x80,m; char xx;
Serial_Init();
delay(50);
while(1)
{
printf("AT\r"); // AT COMMAND FOR INITIALING status_ok();
printf("AT+IPR=9600\r"); // AT COMMAND FOR BAUD RATE status_ok();
printf("AT+CMGR=2\r"); // Reading the message detail // at Index 1 with phone
number, data and time status_ok(); delay(250); printf("ATD9790550124;\r");//AT
COMMAND FOR CALL DIALING delay(250); status_ok();
delay(500);
delay(500);
delay(500);
delay(500);
delay(500);
delay(500);
printf("ATH\r"); // AT COMMAND FOR CALL DISCONNECTING delay(250);
status_ok();
delay(500);
delay(500);
printf("ATDL\r"); // AT COMMAND FOR REDIALING delay(250); status_ok();
delay(500);
delay(500);
printf("ATH\r"); // AT COMMAND FOR ANSWERING THE CALL delay(250);
status_ok();
delay(500);
delay(500);
}
}
void getstring(unsigned char *array)
{
unsigned char temp=0, i=0;
do { temp = getchar();
*array++ = temp;
}
while((temp != '\r') && (temp != '\n'));
91
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
*array = '\0';
}
int getchar (void) /* Read character from Serial Port */
{
while (!(U0LSR & 0x01));
return (U0RBR);
}
void status_ok(void)
{
getstring(y);
while(!(strstr(y,"OK")))
getstring(y);
pointr = strstr(y,"OK");
lcd_cmd(0xc0);
lcd_data(*pointr++);
lcd_data(*pointr);
delay(500);
lcd_cmd(0x01);
}
void Serial_Init(void)
{
PINSEL0 |= 0X00000005; //Enable Txd0 and Rxd0
U0LCR = 0x00000083; //8-bit data, no parity, 1-stop bit
U0DLL = 0x00000061; //for Baud rate=9600,DLL=82
U0LCR = 0x00000003; //DLAB = 0;
}
void delay(unsigned int n)
{
unsigned int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<12000;j++)
{;
}
}
Result:
Thus ,interfacing of GSM module with ARM CORTEX M3- LPC2148 using embedded C
code was executed and verified successfully
DATE:
Aim :
To write an embedded C code for interfacing GPS Module with ARM CORTEX M3-
LPC2148.
Circuit diagram
Procedure:
Give +3.3V power supply to LPC2148 Primer Board; connect +5V adapter with GPS
module is connected with the LPC2148 Primer Board. Open the Hyper Terminal screen,
select which port you are using and set the default settings. Now the screen should show
some text messages.
If you are not reading any data from UART0, then you just check the jumper connections &
just check the serial cable is working. Otherwise you just check the code with debugging
mode in Keil. If you want to see more details about debugging just see the videos in below
link.
Program:
93
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
#define CR 0x0D
#include <LPC21xx.H>
void init_serial (void);
int putchar (int ch);
int getchar (void);
unsigned char test;
int main(void)
{
char *Ptr = "*** UART0 Demo ***\n\n\rType Characters to be echoed!!\n\n\r";
VPBDIV = 0x02; // Divide Pclk by two init_serial();
while(1)
{
while (*Ptr)
{
putchar(*Ptr++);
}
putchar(getchar()); // Echo terminal
}
}
void init_serial (void)
{
PINSEL0 = 0x00000005; // Enable RxD0 and TxD0
U0LCR = 0x00000083; //8 bits, no Parity, 1 Stop bit
U0DLL = 0x000000C3; //9600 Baud Rate @ 30MHz VPB Clock
U0LCR = 0x00000003;
}
int putchar (int ch)
{
if (ch == '\n')
{
while (!(U0LSR & 0x20));
U0THR = CR;
}
while (!(U0LSR & 0x20));
return (U0THR = ch);
}
int getchar (void)
{
while (!(U0LSR & 0x01));
return (U0RBR);
}
Result:
Thus ,interfacing of GPS module with ARM CORTEX M3- LPC2148 using embedded C
code was executed and verified successfully
Introduction :
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 an unique
accelerator architecture enable 32-bit code execution at the maximum clock rate. In-
System Programming/In-Application Programming (ISP/IAP) via on-chip boot loader
software. 10-bit ADCs provide a total of 6/14 analog inputs, with conversion times as low
as 2.44 μs per channel. Single 10-bit DAC provides variable analog output Two 32-bit
timers/external event counters (with four capture and four compare channels each), PWM
unit (six outputs) and watchdog. Low power Real-Time Clock (RTC) with independent
power and 32 kHz clock input. Multiple serial interfaces including two UARTs, two Fast
I2C-bus (400 kbit/s), SPI and SSP with buffering and variable data length capabilities.
Vectored Interrupt Controller (VIC) with configurable priorities and vector addresses. Up
to 5 V tolerant fast general purpose I/O pins in a tiny LQFP64 package.
Onboard Features:
2. All port’s Break-out
3. Power supply pin Break-out
4. 2 Analog potentiometer connected to ADC
5. 4 General Purpose Switches
6. 4 General Purpose LEDs
95
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
7. 16 *2 LCD
8. PS\2 Keyboard connector
9. UART0 and UART1 connector
10. Reset and Boot switches
11. RTC back-up Battery Cell
12. USB B type Connector
13. ULN2003 Stepper Motor driver
14. I2C based EEPROM
15. Micro-SD card connector
16. Buzzer and Relay
17. Relay connector
18. Stepper motor driver connector
19. XBEE
20. On-chip boot loader
LED: LEDs are connected to Port P0.19 – P0.22 in active LOW Configuration so to turn
ON the LED user has to apply logic low (0) signal at the LED PIN and to turn OFF the
LED apply logic high (1) signal at the LED pin.
96
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Buzzer: To enable Buzzer have to connect the jumper as shown. Buzzer is connected to
pin P1.24.
97
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Analog Input: This board is features with two external Potentiometers which used to give
precision analog input to ADC pins of ARM microcontroller. These potentiometer can be
connected through jumper(JP3 and JP4) connected to ADC pins P0.28 – AD0.1 and P0.29
– AD0.2.
Switches: Switches are connected to Port P0.10 – P0.13 in active LOW Configuration,
Pulled up by Resistor network, when pressed logic ‘0’ gives else logic ‘1’.
UART0 and UART1: UART0 is used for programming the LPC2148 with on chip boot
loader. It can also be used as general purpose Communication Port/serial port.
UART1 is general purpose Communication Port/serial port.
98
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Relay: To enable Relay have to connect the jumper as shown. Buzzer is connected to pin
P1.25.
Stepper motor driver: to enable stepper motor driver change the jumper (JP11 – JP14) as
shown in figure.
99
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Python interpreters are available for many operating systems, allowing Python code to run on a
wide variety of systems. Using third-party tools, such as Py2exe or Pyinstaller, Python code can be
packaged into stand-alone executable programs for some of the most popular operating systems, so
Python-based software can be distributed to, and used on, those environments with no need to
install a Python interpreter.
Invoking the interpreter without passing a script file as a parameter brings up the following prompt
−
$ python
Python 2.4.3 (#1, Nov 11 2010, 13:34:43)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
Type the following text at the Python prompt and press the Enter:
If you are running new version of Python, then you would need to use print statement with
parenthesis as in print ("Hello, Python!");. However in Python version 2.4.3, this produces the
following result:
Hello, Python!
100
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Example Project :1
# import module
import calendar
Example Project : 2
Program to make a simple calculator that can add, subtract, multiply and divide using functions
# define functions
def add(x, y):
"""This function adds two numbers"""
return x + y
return x - y
return x * y
return x / y
if choice == '1':
101
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
print(num1,"+",num2,"=", add(num1,num2))
Example Project :3
# Python program to convert decimal number into binary, octal and hexadecimal number system
Example Project :4
X = [[12,7,3],
[4 ,5,6],
[7 ,8,9]]
Y = [[5,8,1],
[6,7,3],
[4,5,9]]
result = [[0,0,0],
[0,0,0],
[0,0,0]]
for r in result:
print(r)
102
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Example Project :5
import random
guesses_made = 0
guesses_made += 1
if guess == number:
break
if guess == number:
print 'Good job, {0}! You guessed my number in {1} guesses!'.format(name, guesses_made)
else:
print 'Nope. The number I was thinking of was {0}'.format(number)
103
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
VIVA-VOCE QUESTIONS
With embedded system, it is possible to replace dozens or even more of hardware logic gates,
input buffers, timing circuits, output drivers, etc. with a relatively cheap microprocessor.
104
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Microcontroller have I/O, memory, etc. built into it and specifically designed for control
10) Mention what are buses used for communication in embedded system?
While ISA, EISA, PCI are standard buses for parallel communication used in PCs, computer
network devices, etc.
13) Explain what is the need for an infinite loop in embedded systems?
Embedded systems require infinite loops for repeatedly processing or monitoring the state of
the program. For instance, the case of a program state continuously being verified for any
exceptional errors that might just happen during run-time such as memory outage or divide
by zero, etc.
105
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
14) List out some of the commonly found errors in Embedded Systems?
Some of the commonly found errors in embedded systems are
16) When one must use recursion function? Mention what happens when recursion
functions are declared inline?
Recursion function can be used when you are aware of the number of recursive calls is not
excessive. Inline functions property says whenever it will call; it will copy the complete
definition of that function. Recursive function declared as inline creates the burden on the
compilers execution.
- Infinite Loops are those program constructs where in there is no break statement so as to get
out of the loop, it just keeps looping over the statements within the block defined.
Example:
106
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Embedded systems avoid lots of electronic components and they have rich built in
functionality. They reduce the cost and maintenance cost and the probability of failure of
embedded system is less so embedded system are in very much use now a days.
Assembly language and C are basically used for embedded system. Java and ADA are also
preferred.
107
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
Embedded software is computer software, written to control machines or devices that are not
typically thought of as computers. It is typically specialized for the particular hardware that it
runs on and has time and memory constraints.
27)What is embedded c?
The C standard doesn't care about embedded, but vendors of embedded systems usually
provide standalone implementations with whatever amount of libraries they're willing to
provide. C is a widely used general purpose high level programming language mainly
intended for system programming.
As, embedded C is generally an extension of the C language, they are more or less similar.
However, some differences do exist, such as: C is generally used for desktop computers,
while embedded C is for microcontroller based applications. C can use the resources of a
desktop PC like memory, OS, etc.
108
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
109
Panimalar Engineering College Dept of ECE EC6711-Embedded Laboratory
110