Embedded System Design IPCC Lab Manual BEC601
Embedded System Design IPCC Lab Manual BEC601
Programme (UG/PG) : UG
Year / Semester : VI
Prepared By
Dr. Raghunath B H.
Reviewed By
Dr. Jayalaxmi H
Assoc. Prof., Dept. of ECE, AIT
Approved By:
Dr. Rajeswari
Prof and Head, Department of ECE, AIT
Embedded System Design (BEC601) 2024-25
VISION STATEMENT
“To be a premier engineering department with excellence in teaching, research and innovation, to meet
the global industrial standards and to have significant impact on the wellbeing of the society”.
MISSION STATEMENT
1. To provide student centric learning environment, inculcate profound knowledge in both
fundamental and applied areas of science and technology.
2. To train and mentor the students in developing leadership qualities and team building skills.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities
with an understanding of the limitations.
6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to
the professional engineering practice.
7. Environment and sustainability: Understand the impact of the professional engineering
solutions in societal and environmental contexts, and demonstrate the knowledge of, and need
for sustainable development.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms
of the engineering practice.
9. Individual and team work: Function effectively as an individual, and as a member or leader in
diverse teams, and in multidisciplinary settings.
10. Communication: Communicate effectively on complex engineering activities with the
engineering community and with society at large, such as, being able to comprehend and write
effective reports and design documentation, make effective presentations, and give and receive
clear instructions.
11. Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a member and
leader in a team, to manage projects and in multidisciplinary environments.
12. Life-long learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.
PSO1: Analog / Digital Circuit Design: Apply the conceptual knowledge in the analysis and/or
design, evaluate analog/digital circuits and systems.
PSO2: VLSI , Signal Processing and Embedded Systems : Demonstrate technical competency
in the analysis, design , and validation of components in VLSI , Signal Processing, and
Embedded Systems
PSO3: Communication and Networking: Apply the domain knowledge in the implementation
and performance analysis of Communication Systems and Computer Networks.
PEO1: Students shall have a successful professional career in industry, academia, R & D organization or
entrepreneur in specialized field of Electronics & Communication engineering and allied
disciplines.
PEO2: Students shall be competent, creative and valued professional in the chosen field.
Course Details
Course Name : Embedded System Design
Course Objectives
Course outcomes
After the successful completion of the course, the student will be able to
CO6 : Write Assembly Level program and verify the results using Keil software.
CO7 : Interface input and output devices with ARM Cortex M3 evaluation board
Syllabus
Conduct the following experiments on an ARM CORTEX M3 evaluation board to learn Assembly
Language Program and using evaluation version of Embedded 'C' & Keil uVision-4 tool/compiler. 1.
1. Write an ALP to find the sum of first 10 integer numbers.
2. Write an Assembly Language Program (ALP) to i) Multiply two 16-bit numbers. ii) Add two 32-
bit numbers.
4. Write an ALP to add an array of 16-bit numbers and store the 32-bit result in internal RAM.
5. Write an ALP to find the square of a number (1 to 10) using look-up table.
8. Write an ALP to count the number of ones and zeros in two consecutive memory locations.
11. Display the Hex digits 0 to F on a 7-segment LED interface, with a suitable delay in between.
12. Interface a simple Switch and display its status through Relay, Buzzer and LED.
In Keil’s µVision IDE, the toolsets provide a powerful, easy to use and easy to learn environment for
developing embedded applications.
1. Project work space window – it shows all the related files connected with your project.
2. Editing window – Used to edit the code
3. Output window – It shows the output after compiling/building/running the project
• Start the Keil software. Go to the Project > New Project then choose a location to store your
program, and give a name without extension, then click on Save.
• Now in the next window select the device from different manufacturers. Select NXP, and then by
expanding select LPC1768 device and click ok.
• Open startup_LPC17xx.s file in the project window
• Comment 5 lines of it. i.e line # 127, 129, 130, 272 and 273 by putting ; [semicolon] in the
beginning of each line.
• Right click on source group and select add new item to the source group
• Select ASM file (.s)
• Go to the Project > Build Target to build the project. If there is some error the building will be
failed, after correcting the errors it can be build.
• Click on the Target1 from the left panel and select Options for Target ‘Target1’. Then go to the
output tab. In this tab check Use simulator, and click OK. Then build it again.
Output:
Output :
66666666
+ 55555555
BBBBBBBB
EXPORT __main
__main
FACT
BNE FACT
STOP
END
Output:
Num=0x09
Factorial=0x58980
EXPORT __main
__main
LOOP
LDR R2, [R1], #2 ; WORD ALIGN T0 ARRAY ELEMENT
LDR R3, MASK ; MASK TO GET 16 BIT
AND R2, R2, R3 ; MASK MSB
CMP R5, #0
HERE
B HERE
Output:
R0=1111+2222+3333+AAAA+BBBB+CCCC = (29997)H
SUB R1, #1
STOP B STOP
TABLE DCB 1,4,9,16,25,36,49,64,81,100
END
Output:
,0X99999999
After Execution :
0X99999999
After Execution:
After Execution:
After Execution:
0x11111111 = 00010001000100010001000100010001
0xAA55AA55 = 10101010010101011010101001010101
Number of ones R2 = 0x00000018
Number of zeros R3 = 0x00000028
Embedded C Programs
Step 1. Open the Keil IDE, under main menu goto “Project -> New uVision Project…” and a window
prompt will open asking a name to save the new project. Type your desired project name and save.
Step 2. After that, a new window will appear as shown below. Make sure “Software Packs” is selected for
the 1st drop down. In the search box below it, type “lpc1768” and then select the device from list below.
Finally click “OK”.
Embedded Systems Lab
Step 3. Now, inside the “Manage Run-Time Environment Window” select the check boxes for “CORE” under
“CMSIS” and “Startup” under “Device”. If you want to select any other libraries you can do so by selecting the
respective checkboxes. Selecting “Startup” will automatically added all the necessary startup/boot files required for
LPC17xx device, so we don’t have to import them from external sources. The selection of libraries can be
changed any time later.
Step 5. Now, click on the “Output” tab. If you want to generate hex file then you can check “Create HEX File”.
Step 6. Then click on the “Linker” tab and under that tab check the checkbox option which says “Use Memory
Layout from Target Dialog”.
Step 7. Now, under the “Debug” tab, change the values for “Dialog DLL” and “Parameter” under both
simulation and hardware debugger settings group. You can select “Use Simulator” to debug your code using
simulator itself.
Step 8. Right click on “Source Group 1” and select “Add New Item to Group ‘Source Group 1”.
Step 10. Write code in the editor. To compile the program Press “F7” key or in the main menu go to “Project-
>Build Target”. To check for any compilation errors, you can have a look at the build output at the bottom
of main window. A screenshot of the Keil MDK uVision 5 is given below. The top red box shows the
Source Tree Navigation and the bottom red box shows the build output.
Now open the flash magic software and follow the below steps.
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 (where 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
Selects Pin Function Configure Pin Direction Access the Port Pin
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.
Values Direction
0 Input
1 Output
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
This register controls the state of output pins. Writing 1s produces lows at the corresponding port pins. Writing 0s
has no effect.
0 No Effect
PINSEL0 Register
3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 9 8 7 6 5 4 3 2 1 0
1 0 9 8 7 6 5 4 3 2 1 0 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 Register
3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 9 8 7 6 5 4 3 2 1 0
1 0 9 8 7 6 5 4 3 2 1 0 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.2 P0.1 P0.1 P0.1 P0.1
0 9 8 7 6
Example : Port 0.0 pin’s function is decided by contents of PINSEL0 register bit 0 and bit 1
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.
Example #1
Configure Pin 4 of Port 0 i.e P0.4 as Output and SET it High (Logic 1)
LPC_GPIO0->FIODIR = 0x0000 0010; // in 32 bit form 0000 0000 0000 0000 0000 0000 0001 0000; 4th bit is 1
Alternate way is
0000 0000 0000 0000 0000 0000 0000 0001 left shit by 4 times results as
0000 0000 0000 0000 0000 0000 0001 0000. which Configures P0.4 as Ouput
LPC_GPIO0->FIOSET = (1<< 4); // SET High for P0.4 pin
LPC_GPIO0->FIODIR = 0x0000 0010; // omitting left side zeros ; we can write as 0x10 ; x stands for Hexadecimal number
Example #2
Configure Pin 17 of Port 1 [ P1.17] as output and then SET that Pin and CLEAR it:
Example #3
Configure Pin 3 and 5 of port 0 as output and SET them Logic High.
i.e Configuring P0.3 and P0.5 as Output and Setting them High:
LPC_GPIO0->FIODIR = (1<<3) | (1<<5) // 1 left shift 3 logically ORed with 1 left shift by 5
LOGIC OR with 0000 0000 0000 0000 0000 0000 0010 0000 [ 1 <<
5]
0000 0000 0000 0000 0000 0000 0010 10003rd and 5th bits are 1. So P0.3
and
Example #4
Configuring 1st 8 Pins of Port 0 (P0.0 to P0.7) as Ouput and Setting them High:
LPC_GPIO0->FIODIR = 0x000000FF; // Config P0.0 to P0.7 as Ouput. 0000 0000 0000 0000 0000 1111 1111
Example #5
Configuring Pins of Port 0 (P0.4 to P0.11) as Output andSetting them High: and Low.
LPC_GPIO0->FIODIR = 0xFF0; // Config P0.4 to P0.11 as Ouput. 0000 0000 0000 0000 0000 1111 1111 0000
LPC_GPIO0->FIOSET = 0xFF0; // 1111 1111 0000 Make output High for P0.4 to
P0.11 LPC_GPIO0->FIOCLR = 0xFF0; // Make output LOW for P0.4 to P0.11\
#include<LPC17xx.h>
unsigned int i, k, z;
LPC_GPIO1->FIODIR = (1<< 22)|(1<< 23)|(1<< 24)|(1<< 25); // P1.22 to P1.25 configure as O/P
while (1)
#include<LPC17xx.H>
unsigned int i, k, z;
LPC_GPIO1->FIODIR = (1<< 22)|(1<< 23)|(1<< 24)|(1<< 25); // configure P1.22 to P1.25 as o/p
while (1)
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.
A 39 P1.22
B 37 P1.23
C 38 P1.24
D 39 P1.25
1 0 0 0 Stepper motor
0 1 0 0 rotates Clockwise
0 0 1 0
0 0 0 1
0 1 0 0
1 0 0 0
#include <LPC17xx.H>
int i, m;
LPC_PINCON->PINSEL1 = (1<< 21); // make PINSEL1.21 pin high to Select AOUT for P0.26
while(1)
for (i = 0; i <= 1023; i++) //send value start from 0 to 1023 in steps of 1
#include<LPC17xx.h>
while (1)
{
LPC_DAC -> DACR = (1024 << 6); // 10bit = 1024 Vmax = 3.3 V
for (i = 120000; i > 1; i--); // maintain this value for some delay
ARM Cortex-M3 LPC176x MCUs incorporate a 10-bi t DAC and provide buffered analog output. As per the
datasheet, it is implemented as a string DAC which is the simplest form of DAC consisting of 2N resistors in series
where N = no. of bits which simply forms a Kelvin-Varley Divider. LPC176x DAC has only 1 output pin, referred
to as AOUT. The Analog voltage at the output of this pin is given as:
Where VALUE is the 10-bit digital value which is to be converted into its Analog counterpart and VREF is
the input reference voltage.
Pin Description
Analog Output pin. Provides the converted Analog signal which is referenced to VSSA i.e. the Analog
AOUT (P0.26)
GND. Set Bits[21:20] in PINSEL1 register to [10] to enable this function.
These are reference voltage input pins used for both ADC and DAC. VREFP is positive reference
voltage and VREFN is negative reference voltage pin. In example shown below we will use
VREFP,
VREFN=0V(GND).
VREFN
VDDA is Analog Power pin and VSSA is Ground pin used to power the ADC module. These are
VDDA, VSSA
generally same as VCC and GND but with additional filtering to reduce noise.
The DAC module in ARM LPC1768/LPC1769 has 3 registers viz. DACR, DACCTRL, DACCNTVAL. In this tutorial
we will only go through to DACR register since the other two are related with DMA operation, explaining
which is not in the scope of this tutorial. Just note that DMA is used to update new values to DACR from
memory without the intervention of CPU. This is particularly useful when generation different types of
waveforms using DAC. We will cover this in another tutorial.
Also note that the DAC doesn’t have a power control it in PCONP register. Simply select the AOUT alternate function
The field containing bits [15:6] is used to feed a digital value which needs to be converted and bit
16 is used to select settling time. The bit significance is as shown below:
1. Bit[5:0]: Reserved.
2. Bit[15:6] – VALUE starts from bit 6
3. Bit[16] – BIAS: Setting this bit to 0 selects settling time of 1us max with max current
consumption of 700uA at max 1Mhz update rate. Setting it to 1 will select settling time of 2.5us
but with reduce max current consumption of 300uA at max 400Khz update rate.
4. Bits[31:17]: Reserved
The total voltage provided by the DACOUT pin is function of binary number written on to bits 6 (D0) to
bit 15(D9) of DAC Register(DACR) and the reference voltage Vref(3.3V).
unsigned int i, j;
unsigned int count=0; // Initially count=0;
LPC_GPIO2->FIODIR = 0x000000FF; // Seven seg on PORT2 P2.0 to P2.7 as o/p
LPC_GPIO1->FIODIR = 0x3C000000; // Configure PORT1 P1.26 to P1.29 as o/p
LPC_GPIO1->FIOSET = 0x20000000; // 26 for first Seven segment
while(1)
LPC_GPIO2->FIOPIN = data7seg[count];
for (j=0; j<1000; j++) //change to brightness of display
LPC_GPIO1->FIOCLR = (1<<26);
}
When the LPC-1768 device drives logic ‘0’ the corresponding segment turns on.
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 Port
P2.0 P2.1 P2.2 P2.3 P2.4 P2.5 P2.6 P2.7
No
LPC-1768 Pin No 40 43 44 45
Hex
Digits to display Display Segments
code
G f a b p c d e
0 1 0 0 0 1 0 0 0 88
1 1 1 1 0 1 0 1 1 EB
2 0 1 0 0 1 1 0 0 4C
3 0 1 0 0 1 0 0 1 49
4 0 0 1 0 1 0 1 1 2B
5 0 0 0 1 1 0 0 1 19
6 0 0 0 1 1 1 1 0 18
7 1 1 0 0 1 0 1 1 CB
8 0 0 0 0 1 0 0 0 08
9 0 0 0 0 1 0 0 1 09
A 0 0 0 0 1 0 1 0 0A
B 0 0 1 1 1 0 0 0 38
C 1 0 0 1 1 0 0 0 98
D 0 1 1 0 1 0 0 0 68
E 0 0 0 1 1 1 0 0 1C
F 0 0 0 1 1 1 1 0 1E
Pin No Port No
Relay 07 P0.25
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