100% found this document useful (1 vote)
2K views

Embedded System Design IPCC Lab Manual BEC601

The document is a lab manual for the Embedded System Design course (BEC601) at Acharya Institute of Technology for the academic year 2024-25. It outlines the course objectives, outcomes, program educational objectives, and includes a detailed syllabus with various assembly language programming experiments using the ARM Cortex M3 evaluation board. Additionally, it provides information on the Keil software development tool necessary for programming and simulating embedded applications.

Uploaded by

Raghunath B H
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
2K views

Embedded System Design IPCC Lab Manual BEC601

The document is a lab manual for the Embedded System Design course (BEC601) at Acharya Institute of Technology for the academic year 2024-25. It outlines the course objectives, outcomes, program educational objectives, and includes a detailed syllabus with various assembly language programming experiments using the ARM Cortex M3 evaluation board. Additionally, it provides information on the Keil software development tool necessary for programming and simulating embedded applications.

Uploaded by

Raghunath B H
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 60

Acharya Institute of Technology

Bengaluru – 560 107.

Department of Electronics and


Communication Engineering
LAB MANUAL
Academic Year : 2024 – 25 (EVEN SEMESTER)

Programme (UG/PG) : UG

Year / Semester : VI

Course Code : BEC601

Course Title : Embedded System Design

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

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

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.

Program Outcomes (POs)

Engineering Graduates will be able to:

1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering


fundamentals, and an engineering specialization to the solution of complex engineering
problems.
2. Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of mathematics,
natural sciences, and engineering sciences.
3. Design/development of solutions: Design solutions for complex engineering problems and
design system components or processes that meet the specified needs with appropriate
consideration for the public health and safety, and the cultural, societal, and environmental
considerations.
4. Conduct investigations of complex problems: Use research-based knowledge and research
methods including design of experiments, analysis and interpretation of data, and synthesis of
the information to provide valid conclusions.

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25

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.

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25
Program Specific Outcomes (PSOs)

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.

Program Educational Objectives (PEOs)

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.

PEO3: Engage in life-long learning and professional development.

PEO4: Become effective global collaborators, leading or participating to address technical,


business, environmental and societal challenges.

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25

Course Details
Course Name : Embedded System Design

Course Code : BEC601

Course prerequisite : Basic Knowledge of ARM processor and assembly language

Course Objectives

▪ Understand the architecture and instruction set of ARM Cortex M3.

▪ Understand the assembly language programming of ARM processor.

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

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25

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.

3. Write an ALP to find factorial of a number.

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.

6. Write an ALP to find the largest/smallest number in an array of 32 numbers.

7. Write an ALP to arrange a series of 32-bit numbers in ascending/descending order.

8. Write an ALP to count the number of ones and zeros in two consecutive memory locations.

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

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

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.

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25

Introduction to Keil Software


Keil is a software development tool for embedded microcontroller applications.

In Keil’s µVision IDE, the toolsets provide a powerful, easy to use and easy to learn environment for
developing embedded applications.

The minimum hardware and software requirements for installation:

• A standard PC running Microsoft Windows XP, or Windows Vista


• 1GB RAM and 500 MB of available hard-disk space is recommended
• 1024x768 or higher screen resolution; a mouse or other pointing device
• download from www.keil.com.

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25
To launch µVision, click the µVision icon on desktop or select µVision from the start menu.

Three windows in the screen:

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

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25

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

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25
1. Write an ALP to find the sum of first 10 integer numbers.

AREA CODE1, CODE, READONLY


EXPORT __main
__main
MOV R0, #10 ; number of elements in an array
MOV R1, #00 ; initially sum=0
LOOP
ADD R1, R0 ; R1=R1+R0
SUBS R0, #1 ; Decrement R0
BNE LOOP ; Branch if R0 is not equal to 0
STOP
B STOP
END

Output:

R1 = 10+9+8+7+6+5+4+3+2+1 = (55)d = (37)H

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25
2. Write an ALP to
i) multiply two 16-bit binary numbers. ii) add two 32-bit numbers.
• ALP to multiply two 16-bit binary numbers.
AREA Multiply, CODE, READONLY
EXPORT __main
__main
LDR R0, =NUM1 ; Load address of first number in R0
LDR R1, [R0] ; Load first number in R1
LDR R0,=NUM2 ; Load address of second number in R0
LDR R2, [R0] ; Load second number in R1
MUL R3, R2, R1 ; Multiply contents of R2 and R1, Save result in R3
LDR R7,=SUM ; Load address of memory location
STR R3,[R7] ; Store result at memory location

NUM1 DCD &1234


NUM2 DCD &2345

AREA Multi, DATA, READWRITE


SUM DCD 0X0
END
Output:
0x1234 * 0x2345 = 0x02820404

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25

• ALP to add two 32-bit numbers.


AREA SUMARRAY, CODE, READONLY
EXPORT __main
__main
LDR R0, =NUM1 ; Read the address of NUM1 into R0
LDR R1, [R0] ; Read lower 32bit data of NUM1 into R1
LDR R0, =NUM2 ; Read the address of NUM2 into R0
LDR R3, [R0] ; Read lower 32bit data of NUM2 into R3
ADDS R6, R1, R3 ; Add the contents of R2 and R4 store the result in R6
LDR R0, =RESULT ; Read the address of RESULT onto R0
STR R6, [R0] ; Store the contents of R5 to address pointed by R0

NUM1 DCD &66666666


NUM2 DCD &5555555
AREA ADDITION, DATA, READWRITE
RESULT DCD &0
END

Output :

66666666

+ 55555555

BBBBBBBB

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25
3. Write an ALP to find factorial of a number.

AREA FACTORIAL, CODE, READONLY

EXPORT __main

__main

MOV R0, #9 ; Take the number

MOV R1, R0 ; Copy the number to R1

FACT

SUBS R1, R1, #1 ; Subtract 1 from R1 and store result in R1

CMP R1, #1 ; Compare contents of R1 with 1

BEQ STOP ; Branch if it equal to label STOP

MUL R3, R0, R1 ; Multiply contents of R0 and R1, store result in R3

MOV R0, R3 ; Store result in R0

BNE FACT

STOP

END

Output:

Num=0x09

Factorial=0x58980

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25
4. Write an ALP to add an array of 16-bit numbers and store the 32-bit result in internal RAM.

AREA ADDITION, CODE, READONLY

EXPORT __main

__main

MOV R5, #6 ; INTIALISE COUNTER TO 6(i.e. N=6)

MOV R0, #0 ; INTIALISE SUM TO ZERO

LDR R1, =VALUE1 ; LOADS THE ADDRESS OF FIRST VALUE

LOOP
LDR R2, [R1], #2 ; WORD ALIGN T0 ARRAY ELEMENT
LDR R3, MASK ; MASK TO GET 16 BIT
AND R2, R2, R3 ; MASK MSB

ADD R0, R0, R2 ; ADD THE ELEMENTS

SUBS R5, R5, #1 ; DECREMENT COUNTER

CMP R5, #0

BNE LOOP ; LOOK BACK TILL ARRAY ENDS

LDR R4, =RESULT ; LOADS THE ADDRESS OF RESULT

STR R0, [R4] ; STORES THE RESULT IN R1

HERE

B HERE

MASK DCD 0X0000FFFF ; MASK MSB

VALUE1 DCW 0X1111,0X2222,0X3333,0XAAAA,0XBBBB,0XCCCC ; ARRAY OF 16 BIT

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25
AREA DATA2, DATA, READWRITE ; TO STORE RESULT IN GIVEN ADDRESS

RESULT DCD 0X0

END ; Mark end of file

Output:

R0=1111+2222+3333+AAAA+BBBB+CCCC = (29997)H

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25
5.Write an ALP to find the square of a number (1 to 10) using look-up table.

AREA SQUARE, CODE, READONLY


EXPORT __main
__main

LDR R0, =TABLE ; Load base address of table in R0

LDR R1, =9 ; Load number in R1

SUB R1, #1

ADD R0, R0, R1 ; Add contents of R0 and R1, store result in R0

LDRB R2, [R0] ; Load the square of number (byte) in R2

STOP B STOP
TABLE DCB 1,4,9,16,25,36,49,64,81,100
END
Output:

Number = 9 Square of 9 = (81)D = (51)H

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25

6. Write an ALP to find the largest/smallest number in an array of 32 numbers.

• ALP to find the largest number in an array of 32 numbers.

AREA LARGEST, CODE, READONLY


EXPORT __main
__main

MOV R5, #6 ; INTIALISE COUNTER TO 6(i.e. N=7)


LDR R1, =VALUE1 ; LOADS THE ADDRESS OF FIRST VALUE
LDR R2, [R1], #4 ; WORD ALIGN T0 ARRAY ELEMENT
LOOP
LDR R4, [R1], #4 ; WORD ALIGN T0 ARRAY ELEMENT
CMP R2, R4 ; COMPARE NUMBERS

BHI LOOP1 ; IF THE FIRST NUMBER IS > THEN GOTO LOOP1


MOV R2, R4 ; IF THE FIRST NUMBER IS < THEN MOV CONTENT R4 TO R2
LOOP1
SUBS R5, R5, #1 ; DECREMENT COUNTER

CMP R5, #0 ; COMPARE COUNTER TO 0

BNE LOOP ; LOOP BACK TILL ARRAY ENDS

LDR R4, =RESULT ; LOADS THE ADDRESS OF RESULT

STR R2, [R4] ; STORES THE RESULT IN R1

VALUE1 DCD 0X44444444, 0Xbcdbffff ,0X11111111 ,0X33333333 ,0XAAAAAAAA ,0X88888888

,0X99999999

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25
AREA DATA2, DATA, READWRITE
RESULT DCD 0X0
END
Output :
Largest number, R4 = 0xbcdbffff
Before Execution :

After Execution :

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25

• ALP to find the smallest number in an array of 32 numbers.

AREA SMALLEST , CODE, READONLY


EXPORT __main
__main

MOV R5, #6 ; INTIALISE COUNTER TO 6(i.e. N=7)


LDR R1, =VALUE1 ; LOADS THE ADDRESS OF FIRST VALUE
LDR R2, [R1], #4 ; WORD ALIGN T0 ARRAY ELEMENT
LOOP
LDR R4, [R1], #4 ; WORD ALIGN T0 ARRAY ELEMENT
CMP R2, R4 ; COMPARE NUMBERS
BLS LOOP1 ; IF THE FIRST NUMBER IS < THEN GOTO
MOV R2, R4 ; IF THE FIRST NUMBER IS > THEN MOV CONTENT R4 TO R2
LOOP1
SUBS R5, R5, #1 ; DECREMENT COUNTER
CMP R5, #0 ; COMPARE COUNTER TO 0
BNE LOOP ; LOOP BACK TILL ARRAY ENDS
LDR R4, =RESULT ; LOADS THE ADDRESS OF RESULT
STR R2, [R4] ; STORES THE RESULT IN R1
; ARRAY OF 32 BIT NUMBERS(N=7)

VALUE1 DCD 0X44444444, 0X22222222, 0X11111111, 0X22222222, 0X00122442, 0X88888888,

0X99999999

AREA DATA2, DATA, READWRITE ; TO STORE RESULT IN GIVEN ADDRESS


RESULT DCD 0X0
END

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25
Output:
Smallest number, R4 = 0X00122442
Before Execution:

After Execution:

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25
7. Write an ALP to arrange a series of 32-bit numbers in ascending/descending order.

• Write an ALP to arrange a series of 32-bit numbers in ascending order.

AREA ASC, CODE, READONLY


EXPORT __main
__main
LDR R0, =0X10000000
MOV R1, #5 ; number of elements in an array
SUBS R1, R1, #1 ; decrement r1 by 1
OUTLOOP
MOV R3, R1 ;R3 is used as counter
MOV R0, #0X10000000
INLOOP
LDR R2, [R0] ;R2 load with first num
LDR R4, [R0, #4] ;R4 is load with second array Number
CMP R4, R2 ;Compare first and second numbers
BCS SKIP ;If first element < second element go to label
STR R4, [R0] ;If first element > second element, exchange both
STR R2, [R0, #4]
SKIP
ADD R0, #4
SUBS R3, R3, #1 ;Decrement R3
BNE INLOOP ; Repeat INLOOP if R3 ≠ 0
SUBS R1, R1, #1 ; Decrement R1
BNE OUTLOOP ; Repeat outloop if R1 ≠ 0
END1 B END1

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25
END
Output:
Before Execution – 55555555 11111111 33333333 22222222 44444444
After Execution - 11111111 22222222 33333333 44444444 55555555
Before Execution:

After Execution:

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25

• Write an ALP to arrange a series of 32-bit numbers in descending order.

AREA ASC, CODE, READONLY


EXPORT __main
__main
LDR R0, =0X10000000
MOV R1, #5 ; number of elements in an array
SUBS R1, R1, #1 ; decrement r1 by 1
OUTLOOP
MOV R3, R1 ; R3 is used as counter
MOV R0, #0X10000000
INLOOP
LDR R2, [R0] ;R2 load with first number
LDR R4, [R0, #4] ;R4 is load with second array Number
CMP R4, R2 ;Compare first and second numbers
BCC SKIP ;If first element > second element go to label
STR R4, [R0] ;If first element < second element, exchange both
STR R2, [R0, #4]
SKIP
ADD R0, #4
SUBS R3, R3, #1 ; Decrement R3
BNE INLOOP ; Repeat INLOOP if R3 ≠ 0
SUBS R1, R1, #1 ; Decrement R1
BNE OUTLOOP ; Repeat outloop if R1 ≠ 0
END1 B END1
END
Output:
Before Execution – 33333333 55555555 11111111 44444444 22222222

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25
After Execution - 55555555 44444444 33333333 22222222 11111111
Before Execution:

After Execution:

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25
8. Write an ALP to count the number of ones and zeros in two consecutive memory locations.

AREA ONEZERO, CODE, READONLY


EXPORT __main
__main
MOV R2, #0 ; COUNTER FOR ONES
MOV R3, #0 ; COUNTER FOR ZEROS
MOV R7, #2 ; COUNTER TO GET TWO WORDS
LDR R6, =VALUE ; LOADS THE ADDRESS OF VALUE
LOOP
MOV R1, #32 ; 32 BITS COUNTER
LDR R0, [R6], #4 ; GET THE 32 BIT VALUE
LOOP0
MOVS R0, R0, ROR #1 ; RIGHT SHIFT TO CHECK CARRY BIT (1's/0's)
BHI ONES ; IF CARRY BIT IS 1 GOTO ONES BRANCH OTHERWISE NEXT
ZEROS
ADD R3, R3, #1 ; IF CARRY BIT IS 0 THEN INCREMENT THE COUNTER BY
1(R3)
B LOOP1 ; BRANCH TO LOOP1
ONES
ADD R2, R2, #1 ; IF CARRY BIT IS 1 THEN INCREMENT THE COUNTER BY
1(R2)
LOOP1
SUBS R1, R1, #1 ; COUNTER VALUE DECREMENTED BY 1
BNE LOOP0 ; IF NOT EQUAL GOTO TO LOOP0 CHECKS 32BIT
SUBS R7, R7, #1 ; COUNTER VALUE DECREMENTED BY 1
CMP R7, #0 ; COMPARE COUNTER R7 TO 0

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25
BNE LOOP ; IF NOT EQUAL GOTO TO LOOP
VALUE DCD 0X11111111, 0XAA55AA55 ; TWO VALUES IN AN ARRAY
END ; Mark end of file
Output:

0x11111111 = 00010001000100010001000100010001
0xAA55AA55 = 10101010010101011010101001010101
Number of ones R2 = 0x00000018
Number of zeros R3 = 0x00000028

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25

PART - B : Hardware Interfacing using

Embedded C Programs

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25

Open Keil 5 IDE tool

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.

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25

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.

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25

Step 4. Now click on “Options for Target” button as shown below:

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25

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

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25

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.

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25
Click “OK” to apply settings and close window.

Step 8. Right click on “Source Group 1” and select “Add New Item to Group ‘Source Group 1”.

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25

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.

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25
Step 11. To initiate a debug session using simulator or debug hardware/probe click “Debug->Start/Stop
Debug Session” or you can hit “Ctrl+F5” as shown below:

Now open the flash magic software and follow the below steps.

1. Select the Device as LPC1768 from Select Menu.


2. Select the COM Port. Check the device manager for detected COM port.
3. Select the Baud rate from 9600-115200. Ex: Set as 115200
4. Select None ISP Option.
5. Oscillator Frequency 12Mhz
6. Check the Erase all Flash + Code Rd Prot
7. Browse and Select the desired hex file. [project.hex file]
8. Press the Start Button to flash the hex file.

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25

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

PINSEL FIODIR FIOSET, FIOCLR,


FIOPIN

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.

Value Function Enumeration

00 Primary (default) function, typically GPIO port PINSEL_FUNC_0

01 First alternate function PINSEL_FUNC_1

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25
10 Second alternate function PINSEL_FUNC_2

11 Third alternate function PINSEL_FUNC_3

FIODIR: Fast GPIO Direction Control Register.

This register individually controls the direction of each port pin.

Values Direction

0 Input

1 Output

FIOSET: Fast Port Output Set Register.

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

Values FIOSET

0 No Effect

1 Sets High on Pin

FIOCLR: Fast Port Output Clear Register.

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

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25
Values FIOCLR

0 No Effect

1 Sets Low on Pin

FIOPIN: Fast Port Pin Value Register

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

P0.0 function decided by P0.0 Function as


PINSEL0.1 PINSEL0.0

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


0 1 when PINSEL0.1= 0, PINSEL0.0= 1 Then P0.0 Function as RD1
1 0 when PINSEL0.1= 1, PINSEL0.0= 0 Then P0.0 function as TXD3

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25
1 1 when PINSEL0.1= 1, PINSEL0.0= 1 Then P0.0 function as SDA1

Since by default all pins are configured as GPIOs we don’t need to explicitly assign a ‘0’ value to PINSEL register in
Programming examples.
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

Port Number Pin number

Alternate way is

LPC_GPIO0->FIODIR = (1<< 4); // 1 in 32 bit binary form left shift by 4 times.

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

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25

LPC_GPIO0->FIODIR = 0x0000 0010; // omitting left side zeros ; we can write as 0x10 ; x stands for Hexadecimal number

LPC_GPIO->FIODIR = 0x10; // Configure pin 4 of port 0 as Output


LPC_GPIO->FIOSET=0x10; //pin 4 of port 0 is made HIGH

Example #2

Configure Pin 17 of Port 1 [ P1.17] as output and then SET that Pin and CLEAR it:

LPC_GPIO1->FIODIR = (1<<17); // configuring 17th pin of port 1 [P1.17] as Output pin


LPC_GPIO1->FIOSET = (1<<17); // Output for P1.17 becomes High
LPC_GPIO1->FIOCLR = (1<<17); // Output for P1.17 becomes Low

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

0000 0000 0000 0000 0000 0000 0000 1000 [ 1 << 3 ]

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

P0.5 configures as output

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25
Alternate way is
LPC_GPIO0->FIODIR =0x0000 0028; // grouping above terms or we can also write as 0x28
LPC_GPIO0->FIOSET = (1<<3) | (1<<5) // Make output High for P0.3 and P0.5

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

LPC_GPIO0->FIOSET = 0x000000FF; // Make output High for P0.0 to P0.7 Example

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\

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25
9.a. Interface a Stepper motor and rotate it in clockwise direction.

#include<LPC17xx.h>

int main (void)


{

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)

k = 1<< 22; // k = 0x02000000 , initially P.25 =1 [ 1000 ]

for(z=0; z<4; z++) // four coils to be made high one by one

LPC_GPIO1->FIOPIN =k; //Port1 pins assigned with Ka value

for ( i=120000; i >0 ; i - - ) ; // Delay , value of i decides speed of rotation.


k = k<<1; // k content rotate right 1 time. [0100] [0010] [0001]
}
}

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25
9.b. Interface a Stepper motor and rotate it in anti-clockwise direction.

#include<LPC17xx.H>

int main (void)


{

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)

k = 1 << 25; //k =0x00400000 ,initialize P1.22 as high [0001]


for(z=0; z < 4; z ++) // executes 4 times
{

LPC_GPIO1->FIOPIN = k //Port 1 pins assigned with k value


for (i=120000 ; i >0 ; i--) ; //delay
k = k>>1; // rotate left shift by 1 [0010] , [0100], [1000]

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25

Stepper Motor Configuration:


A stepper motor is a special type of electric motor that moves in increments, or steps, rather than turning smoothly
as a conventional motor does. Typical increments are 0.9 or 1.8 degrees, with 400 or 200 increments thus
representing a full circle. The speed of the motor is determined by the time delay between each incremental
movement.

U8 is a Driver Buffer (ULN2003) device connected to LPC-1768 Device and can be used for driving
Stepper Motor. On the LPC-1768, P1.22 to P1.25 is used to generate the pulse sequence required to run the
stepper Motor. Also, the Stepper Motor is powered by its own power supply pin (COM), which is
connected to a 12V supply. Table shows connections for stepper Motor.

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25
Stepper Motor Pin connection table.

Stepper Motor Coil LPC-1768 Pin LPC-1768 Port No


No

A 39 P1.22

B 37 P1.23

C 38 P1.24

D 39 P1.25

P1.25 P1.24 P1.23 P1.22

1 0 0 0 Stepper motor
0 1 0 0 rotates Clockwise

0 0 1 0
0 0 0 1

P1.25 P1.24 P1.23 P1.22

0 0 0 1 Stepper motor rotates


Anti Clockwise
0 0 1 0

0 1 0 0

1 0 0 0

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25

10 a. Interface a DAC and generate Triangular waveform.

#include <LPC17xx.H>

int main (void)

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

LPC_DAC->DACR = (i << 6) // DACR register value should placed in 15:6

for(m = 10; m > 1; m--) ; //delay to vary frequency


}
for (i = 1023 ; i > 0; i - -) //once reaches max of 3.3v starts decreasing

LPC_DAC->DACR = (i << 6);

for(m = 10; m > 1; m--);

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25

10 b. Interface a DAC and generate square waveforms.

#include<LPC17xx.h>

int main (void)


{
int i;
LPC_PINCON->PINSEL1 = (1<<21) ; //Select AOUT function for P0.26

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

LPC_DAC -> DACR = (512 << 6); // for Vmax/2 = 1.74V

for (i = 120000; i > 1; i--) ; // delay

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25

LPC1768/LPC1769 DAC Block

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:

VAOUT = VALUE * (VREFP-VREFN)/ 1024

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25

When VREFN = 0, the equation boils down to:

VAOUT = (VALUE * VREFP)/1024

Where VALUE is the 10-bit digital value which is to be converted into its Analog counterpart and VREF is
the input reference voltage.

Pins relating to LPC1768 DAC block:

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.

DAC Registers in ARM Cortex-M3 LPC176x

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

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25
for pin P0.26 using PINSEL1 register to enable DAC output.

The DACR register in LPC1768

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

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25
11.Display the Hex digits 0 to F on a 7-segment LED interface, with an appropriate delay in between.
#include <LPC17xx.H>

unsigned char data7seg[] = {0x88,0xeb,0x4c,0x49,0x2b,0x19,0x18,0xcb,0x8,0x9,0xa,0x38,0x9C,0x68, 0x1c,0x1e};


int main (void)

unsigned int i, j;
unsigned int count=0; // 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)

if (count > 0xF)


count = 0; // if count Greater than F, re- initialize to 0
for (i=0; i < 20000; i++) //change to increment/decrement speed
{

LPC_GPIO2->FIOPIN = data7seg[count];
for (j=0; j<1000; j++) //change to brightness of display
LPC_GPIO1->FIOCLR = (1<<26);
}

count++; //count = count+1

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25

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

Seven Segment Selection table.

Seven Segment Disp1 Disp2 Disp3 Disp4


Selection Lines (D9) (D10) (D11) (D12)

LPC-1768 Pin No 40 43 44 45

LPC-1768 Port No P1.26 P1.27 P1.28 P1.29

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25

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

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25
12.Interface a simple Switch and display its status through Relay, Buzzer and LED.
#include <LPC17xx.h>
int main(void)
{
LPC_GPIO3->FIODIR |= (1<<25);
LPC_GPIO1->FIODIR &= ~ (1<<21) | ~(1<<20) | ~(1<<19);
LPC_GPIO0->FIODIR = (1<<25) | (1<<4);
while(1)
{
if (!(LPC_GPIO1->FIOPIN & (1<<21)))
LPC_GPIO3->FIOSET= 1<<25; //Buzzer
else
LPC_GPIO3->FIOCLR= 1<<25;

if (!(LPC_GPIO1->FIOPIN & (1<<20)))


LPC_GPIO0->FIOSET= 1<<25; // Relay
else
LPC_GPIO0->FIOCLR= 1<<25;
if (!(LPC_GPIO1->FIOPIN & (1<<19)))
LPC_GPIO0->FIOSET=0x00000010;
else
LPC_GPIO0->FIOCLR= 0x00000010;
}
}

Dept. of ECE, AIT


Embedded System Design (BEC601) 2024-25
Relay: Send logic ‘1’ to switch on relay

Relay connection table.

Relay coil LPC-1768 LPC-1768

Pin No Port No

Relay 07 P0.25

Buzzer: Send Logic ‘1’ to generate beep.

Buzzer pin connection table.


Speaker/ LPC-1768 LPC-1768
Buzzer Pin Pin No Port No
1 27 P3.25

LED: Send Logic ‘1’ the corresponding LED turns on.

LED pin connection table


LED D1 D2 D3 D4 D5 D6 D7 D8

LPC-1768
81 80 79 78 77 76 48 49
Pin No

LPC-1768
P0.4 P0.5 P0.6 P0.7 P0.8 P0.9 P0.10 P0.11
Port No

Dept. of ECE, AIT

You might also like