0% found this document useful (0 votes)
123 views70 pages

Es - It - 2022

Here are a few data transfer and arithmetic programs to explore ARM addressing modes: 1. Immediate Addressing Mode MOV R0, #10 ; Move immediate value 10 into R0 ADD R1, R0, #5 ; Add immediate value 5 to R0 and store in R1 2. Register Addressing Mode MOV R2, R1 ; Move content of R1 into R2 ADD R3, R2, R0 ; Add content of R0 and R2 and store in R3 3. Pre-indexed Addressing Mode LDR R4, [R0], #4 ; Load value from memory address R0, post-increment R0

Uploaded by

Anushka
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
0% found this document useful (0 votes)
123 views70 pages

Es - It - 2022

Here are a few data transfer and arithmetic programs to explore ARM addressing modes: 1. Immediate Addressing Mode MOV R0, #10 ; Move immediate value 10 into R0 ADD R1, R0, #5 ; Add immediate value 5 to R0 and store in R1 2. Register Addressing Mode MOV R2, R1 ; Move content of R1 into R2 ADD R3, R2, R0 ; Add content of R0 and R2 and store in R3 3. Pre-indexed Addressing Mode LDR R4, [R0], #4 ; Load value from memory address R0, post-increment R0

Uploaded by

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

DEPARTMENT OF INFORMATION &

COMMUNICATION TECHNOLOGY

Embedded Systems
Lab Manual
[ICT 3164]

Semester: V
B. Tech (IT)
CONTENTS

LAB TITLE PAGENO. MARKS SIGN


NO

COURSE OBJECTIVES AND OUTCOMES II

INSTRUCTION TO THE STUDENTS III

0 START- UP KEIL UVISION4 1

1 DATA TRANSFER PROGRAMS 10

2 ARITHMETIC PROGRAMS 14

3 CODE CONVERSION PROGRAMS 18

4 PROGRAMS ON SORTING, SEARCHING AND STACK 20

5 INTERFACING LED TO ARM MICROCONTROLLER 22

6 PROGRAMS ON MULTIPLEXED SEVEN SEGMENT DISPLAY 28

7 LCD AND KEYBOARD INTERFACING 33

8 ADC AND DAC INTERFACING 46

9 PWM INTERFACING 50

10 FAMILIARIZATION WITH ARM MBED PROTOTYPING BOARD 53

11 FAMILIARIZATION WITH ARM MBED PROTOTYPING BOARD 57


EXERCISE

APPENDIX A 62

APPENDIX B 65

APPENDIX C 69

i
Course Objectives
 To develop skills in real world interfacing circuits.
 To efficiently design software for embedded systems.
 To design software for IoT applications.
Course Outcomes
At the end of this course, students will be able to
 Design real world interfacing circuits to a microcontroller
 Develop software for embedded systems.
 Propose architectural solutions for IoT applications.
 Develop software for IoT applications.

INSTRUCTIONS TO THE STUDENTS


Pre- Lab Session Instructions
1. Students should carry the Lab Manual Book and the required stationery to every
lab session.
2. Be in time and follow the institution dress code.
3. Must sign in the log register provided.
4. Make sure to occupy the allotted seat and answer the attendance.
5. Adhere to the rules and maintain the decorum.

In- Lab Session Instructions


 Follow the instructions on the allotted exercises.
 Show the program and results to the instructors on completion of experiments.
 On receiving approval from the instructor, write the program and results in the lab
record.
 Prescribed textbooks and class notes can be kept ready for reference, if required.

General Instructions for the exercises in Lab


 Implement the given exercise individually as well as in allotted teams.
 The programs should meet the following criteria:
o Programs should be interactive with appropriate prompt messages, error
messages if any, and descriptive messages for outputs.
o Comments should be used to give the statement of the problem.
ii
o Statements within the program should be properly indented.
 Plagiarism (copying from others) is strictly prohibited and would invite severe
penalty during evaluation.
 The exercises for each lab are divided under three sets:
o Solved exercise,
o Lab exercises - to be completed during lab hours,
o Additional Exercises - to be completed outside the lab or in the lab to
enhance the skill.
 In case a student misses a lab class, he/ she must ensure that the experiment is
completed during the repetition class with the permission of the faculty concerned,
but credit will be given only to one day’s experiment(s).

iii
ES LAB MANUAL Start up Keil U Vision4

Start up Keil uVision4


Aim: Understand the usage of Keil u Vision 4 software for assembly language.

Before you start up, you are recommended that you create a folder to hold all your project
files. For example: you can create a folder "FirstARM-Project" ready before hand.

Step1:

You can start up uVision4 by clicking on the icon from the desktop or from the
"Start" menu or "All Programs" on a lab PC. The following screen is what you will see:

Step2: Create a project

To create a project, click on the "Project" menu from the uVision4 screen and select "New
uVision Project...".

1|Page
ES LAB MANUAL Start up Keil U Vision4

Then, select a folder, give project a name and save.

From the "Select Device for Target" window, select "NXP" as the vendor. In that select
LPC1768 ARM controller , then click on OK button

2|Page
ES LAB MANUAL Start up Keil U Vision4

Make sure you click on "NO" for the following pop up window.

Step3: Create Source File

From the "File" menu, select "New", you will see the "Text1*" text edit window. That is
the place you will write your ARM Assembly language program. You can write the
program into this window. (Note: give a tab space at the beginning)

3|Page
ES LAB MANUAL Start up Keil U Vision4

Save the program by clicking on the "Save" or "Save As" from the "File" menu and give
it a name.

4|Page
ES LAB MANUAL Start up Keil U Vision4

Add Source File to the Project

Right click on the "Source Group 1", select "Add Files to Group 'Source Group 1'".

Select "Files of type" as "asm Source file (*.s*;*.src*;*.a*), then select the file
"FirstARM.s" for example. Click on "Add", and then click on "Close".

Step4: Build your project

Click on the "+" beside the "Source Group 1", you will see the program "FirstARM.s".
Click on the "Build" button or from the "Project" menu, you will see the following screen.

5|Page
ES LAB MANUAL Start up Keil U Vision4

Run the program in your project

Run the program through "Debug" menu.

Click on "OK" for the pop up window showing "EVALUATION MODE, Running with
Code Size Limit: 32K".

Open uVision4 to full screen to have a better and complete view. The left hand side
window shows the registers and the right side window shows the program code. There
are some other windows open. Adjust the size of them to have better view.
Run the program step by step; observe the change of the values in the registers.

6|Page
ES LAB MANUAL Start up Keil U Vision4

To trace the program use the Step Over button or click on Step Over from the Debug
menu. It executes the instructions of the program one after another. To trace the program
one can use the Step button, as well. The difference between the Step Over and Step is
in executing functions. While Step goes into the function and executes its instructions
one by one, Step Over executes the function completely and goes to the instruction next
to the function. To see the difference between them, trace the program once with Step
Over and then with Step. When PC executing the function and want the function to be
executed completely one can use Step Out. In the case, the instructions of the function
will be executed, it returns from the function, and goes to the instruction which is next to
the function call.

7|Page
ES LAB MANUAL Start up Keil U Vision4

Click on the "Start/Stop Debug Session" again to stop execution of the program.

An example ARM assembly language module

An ARM assembly language module has several constituent parts.

These are:

 Extensible Linking Format (ELF) sections (defined by the AREA directive).


 Application entry (defined by the ENTRY directive).
 Application execution.
 Program end (defined by the END directive).
Consider the following example

 AREA ARMex, CODE, READONLY


 ; Name this block of code ARMex
 ENTRY ; Mark first instruction to execute
 start
 MOV r0, #10 ; Set up parameters
 MOV r1, #3
 ADD r0, r0, r1 ; r0 = r0 + r1
 END ; Mark end of file

8|Page
ES LAB MANUAL Start up Keil U Vision4

Application entry

The ENTRY directive declares an entry point to the program. It marks the first instruction
to be executed. In applications using the C library, an entry point is also contained within
the C library initialization code. Initialization code and exception handlers also contain
entry points.

Application execution

The application code begins executing at the label start, where it loads the decimal values
10 and 3 into registers R0 and R1. These registers are added together and the result placed
in R0.

Program end

The END directive instructs the assembler to stop processing the source file. Every
assembly language source module must finish with an END directive on a last line. Any
lines following the END directive are ignored by the assembler.

9|Page
ES LAB MANUAL LAB 1: Data Transfer and Arithmetic Programs

Lab 1
Data Transfer and Arithmetic Programs

Aim: Familiarization of ARM data transfer instructions.


Introduction to ARM addressing modes: Data can be transferred into and out of ARM
controller using different addressing modes. There are different ways to specify the
address of the operands for any given operations such as load, add or branch. The different
ways of determining the address of the operands are called addressing modes. In this lab,
we are going to explore different data transfer instructions of ARM processor and learn
how all instructions can fit into a single word (32 bits).

Appendix A gives the different addressing modes used in ARM

Question: Write a ARM assembly language program to copy 16 bit variable from code
memory to data memory.

Input : SRC = 0X00000008 at location pointed by R0

Output : DST = 0X00000008 At location pointed by R1

AREA RESET, DATA, READONLY


EXPORT __Vectors

__Vectors
DCD 0x10001000 ; stack pointer value when stack is empty
DCD Reset_Handler ; reset vector

ALIGN

AREA mycode, CODE, READONLY


ENTRY
EXPORT Reset_Handler

Reset_Handler
10 | P a g e
ES LAB MANUAL LAB 1: Data Transfer and Arithmetic Programs

LDR R0, =SRC; Load address of SRC into R0


LDR R1, =DST; Load the address of DST onto R1
LDR R3, [R0]; Load data pointed by R0 into R3
STR R3,[R1] ; Store data from R3 into the address pointed by R1
STOP
B STOP

SRC DCD 8,0x123456; SRC location in code segment


AREA DATASEG, DATA, READWRITE

DST DCD 0 ;DST location in Data segment

END

Observations to be made

1. Data storage into the memory: Click on Memory window you get label
Memory1 option type address pointed by R0 in address space and observe how
the data are stored into the memory.
2. Data movement from one memory to another memory: Click on Memory
window you get label Memory2 option type address pointed by R1 in address
space and observe data movement to another location before execution and after
execution.

Exercise questions
1. Write an ARM assembly language program to transfer block of ten 32 bit numbers
from one memory to another
a. When the source and destination blocks are non-overlapping
b. When the source and destination blocks are overlapping
Hint: Use Register indirect addressing mode or indexed addressing mode

2. Reverse an array of ten 32 bit numbers in the memory.

11 | P a g e
ES LAB MANUAL Lab 2: Arithmetic Programs

Lab 1
Arithmetic Programs

Aim: Familiarization of Arithmetic operations - addition and subtraction


Please refer to appendix A for arithmetic instructions.

Question: Write a program to add two 32 bit numbers.

AREA RESET, DATA, READONLY


EXPORT __Vectors

__Vectors
DCD 0x40001000 ; stack pointer value when stack is empty
DCD Reset_Handler ; reset vector

ALIGN
AREA mycode, CODE, READONLY
ENTRY
EXPORT Reset_Handler

Reset_Handler
LDR R0, =VALUE1 ;pointer to the first value1
LDR R1,[R0] ;load the first value into R1
LDR R0,=VALU2 ;pointer to the second value
LDR R3, [R0] ;load second number into r3
ADDS R6, R1,R3 ;add two numbers and store the result in r6
LDR R2, =RESULT
STR R6,[R2]
STOP
B STOP
VALUE1 DCD 0X12345678 ; First 32 bit number
VALUE2 DCD 0XABCDEF12 ; Second 32 bit number
AREA data, DATA, READWRITE
RESULT DCD 0
12 | P a g e
ES LAB MANUAL Lab 2: Arithmetic Programs

Exercise questions

1. Write a program to add ten 32 bit numbers stored in code segment and store
the result in data segment
2. Write a program to add two 128 bit numbers stored in code segment and store
the result in data segment.
Hint: Use indexed addressing mode.
3. Write a program to subtract two 128 bit numbers

Additional Exercise questions


1. Write a program to subtract two 32 bit numbers

13 | P a g e
ES LAB MANUAL Lab 2: Arithmetic Programs

Lab 2
Arithmetic Programs

Aim: Familiarization of Arithmetic operations - multiplication and division.

Question: Write an assembly program to multiply two 32 bit numbers


AREA RESET, DATA, READONLY
EXPORT __Vectors

__Vectors
DCD 0x40001000 ; stack pointer value when stack is empty
DCD Reset_Handler ; reset vector

ALIGN

AREA mycode, CODE, READONLY


ENTRY
EXPORT Reset_Handler

Reset_Handler
LDR R0, =VALUE1 ;pointer to the first value1
LDRH R1,[R0] ;load the first value into r1
LDR R0,=VALU2 ;pointer to the second value
LDRH R3, [R0] ;load second number into r3
MUL R6, R1,R3 ;Multiply the values from R1 and R3 and store
;least significant 32 bit number into R6.
LDR R2, =RESULT
STR R6,[R2] ; store result in r6
STOP
B STOP
14 | P a g e
ES LAB MANUAL Lab 2: Arithmetic Programs

VALUE1 DCD 0X1234 ; First 32 bit number


VALUE2 DCD 0X5678 ; Second 32 bit number
AREA data, DATA, READWRITE
RESULT DCD 0
Note: If the result is more than 32 bits, use UMULL instruction.
Question: Write a program to divide a 32 bit number by 16 bit number

 . We follow repetitive subtraction method to divide two numbers.

AREA RESET, DATA, READONLY


EXPORT __Vectors

__Vectors
DCD 0x40001000 ; stack pointer value when stack is empty
DCD Reset_Handler ; reset vector

ALIGN
AREA mycode, CODE, READONLY
ENTRY
EXPORT Reset_Handler

Reset_Handler
MOV R2,#00
LDR R0, =VALUE1 ;pointer to the first value1
LDR R1,[R0] ;load the first value into r1
LDR R0,=VALUE2 ;pointer to the second value
LDR R3, [R0] ;load second number into r3
up SUB R1, R3 ;Subtract two numbers
ADD R2,#01 ;increment a counter
CMP R1,R3 ;compare two numbers
BCS up ;check R1is greater than R3 or not, if yes loop
LDR R6, =RESULT ;Quotient
STR R2,[R6,#4]
STR R1,[R6] ;Store remainder.
STOP
15 | P a g e
ES LAB MANUAL Lab 2: Arithmetic Programs

B STOP
VALUE1 DCD 0x200000000 ;First 32 bit number
VALUE2 DCD 0x00050000 ;Second 16 bit number
AREA data, DATA, READWRITE
RESULT DCD 0,0

Exercise questions

1. Find the sum of ‘n’ natural numbers using MLA instruction.


2. Write an assembly language program to find GCD of two numbers
Hint:
While(a!=b)
{
If(a>b)
a=a-b;
else
b=b-a;

} Return (a);

3. Write an assembly language program to find LCM of two numbers


Hint: i=1
do{
remainder= i*a mod b;
If (remainder==0)
Exit;
Else
i++;
} while(remainder!=0);
Return (i*a);

16 | P a g e
ES LAB MANUAL Lab 2: Arithmetic Programs

Additional Exercise Questions


1. Write a program to multiply two 32 bit numbers using repetitive addition
Hint: If two numbers are in R0 and R1 Registers then use following algorithm
Sum=0;
do { sum=sum+R0; R1--; ;Use ADS instruction for addition and use ADD
;instruction to increment a register by 1
if carry then
R2++; ;Increment carry value by one.
} while(R1!=0); ;Use Compare instruction to check greater
;than or not. And Brach instructions for loop
Result= R2 and R0
2. Write a program for BCD multiplication

17 | P a g e
ESLAB MANUAL LAB3: Code Conversion Programs

Lab 3
Code Conversion Programs

Aim: Familiarization of logical instructions and code conversion programs.

Question: Write an assembly program to convert a 2 digit hexadecimal number into


unpacked ASCII.
AREA RESET, DATA, READONLY
EXPORT __Vectors

__Vectors
DCD 0x40001000 ; stack pointer value when stack is empty
DCD Reset_Handler ; reset vector
ALIGN
AREA mycode, CODE, READONLY
ENTRY
EXPORT Reset_Handler

Reset_Handler

LDR R0,=NUM
LDR R3,=RESULT
LDRB R1,[R0] ; load hex number into register R1
AND R2,R1,#0x0F ; mask upper 4 bits
CMP R2,#09 ; compare the digit with 09
BLO DOWN ; if it is lower than 9 then jump to down
; lable
ADD R2,#07 ;else add 07 to that number
DOWN
ADD R2,#0x30 ; Add 30H to the number, Ascii value of first
STRB R2,[R3] ; digit
AND R3,R1,#0xF0 ; Mask the second digit
MOV R3,R3,LSR#04 ; Shift right by 4 bits
CMP R3,#09 ; check for >9 or not
BLO DOWN1
18 | P a g e
ESLAB MANUAL LAB3: Code Conversion Programs

ADD R3,#07
DOWN1
ADD R3,#0x30 ; Ascii value of second digit
STRB R3,[R2,#01]
END
NUM DCD 0x000003A
AREA data, DATA, READWRITE
RESULT DCD 0
Exercise programs

1. Write an ARM assembly language program to covert 2-digit hexadecimal


number in ASCII
2. Write an assembly language program to convert a 2-digit BCD number in to its
equivalent hexadecimal number.
3. Write an assembly language program to convert a 2-digit hex number in to its
equivalent BCD number

Additional Exercise

1. Write an ARM assembly language program to covert 2-digit hexadecimal


number in ASCII unpacked form into its equivalent packed hexadecimal number
2. Write a program to convert a 32 bit number in the unpacked form into packed
form.

19 | P a g e
ES LAB MANUAL LAB5: Interfacing LED to ARM Controller

Lab 4
Programs on Sorting, Searching and Stack

Aim: To understand the logic of looping and sorting

Question: Write an ARM program to sort a list using bubble sort.

AREA RESET, DATA, READONLY


EXPORT __Vectors

__Vectors
DCD 0x40001000 ; stack pointer value when stack is empty
DCD Reset_Handler ; reset vector

ALIGN
AREA ascend, code, readonly
ENTRY
Reset_Handler
mov r4,#0
mov r1,#10
ldr r0, =list
ldr r2, =result
up ldr r3, [r0,r4]
str r3, [r2,r4]
add r4, #04
sub r1,#01
cmp r1,#00
bhi up
ldr r0, =result
; inner loop counter
mov r3, #10
sub r3, r3, #1
mov r9, r3 ; R9 contain no of passes
; outer loop counter
outer_loop
mov r5, r0
20 | P a g e
ES LAB MANUAL LAB5: Interfacing LED to ARM Controller

mov r4, r3 ; R4 contains no of compare in a pass


inner_loop
ldr r6, [r5], #4
ldr r7, [r5]
cmp r7, r6
; swap without swp instruction
strls r6, [r5]
strls r7, [r5, #-4]

subs r4, r4, #1


bne inner_loop
sub r3, #1
subs r9, r9, #1
bne outer_loop

list dcd 0x10,0x05,0x33,0x24,0x56,0x77,0x21,0x04,0x87,0x01


AREA data1, data, readwrite
result DCW 0,0,0,0,0,0,0,0,0,0
end

Exercise questions:

1. Write an assembly program to sort an array using selection sort


2. Write an assembly program to find the factorial of a unsigned number using
recursion
3. Write an assembly program to search an element in an array of ten 32 bit numbers
using linear search.

Additional Exercise

1. Assume that ten 32 bit numbers are stored in registers R0-R10. Sort these numbers
in the fully ascending stack using selection sort and store the sorted array back
into the registers. Use STM and LDMDB instructions wherever necessary.
2. Repeat the above question (4) for fully descending stack using STMDB and LDM
instruction wherever necessary.

21 | P a g e
ES LAB MANUAL LAB5: Interfacing LED to ARM Controller

Lab 5
Interfacing LED to ARM Microcontroller

Aim: Interface LEDs to the ARM cortex LPC1768 microcontroller using ALS interfacing
board.

Steps to be followed:
Project Creation in Keil uvision4 IDE:
• Create a project folder before creating NEW project.
• Use separate folder for each project
• Open Keil uVision4 IDE software by double clicking on “Keil Uvision4” icon.
• Select “Project” then to “New Project” and save it with a name in the respective
Project folder, which is already you created.
• Select the device as “NXP (founded by Philips)” Select “LPC1768” then Press
“OK” and then press “YES” button to add “system_LPC17xx.s” file.
• Go to “File” select “New” to open an editor window. Create a source file and use
the header file “LPC17xx.h” in the source file and save the file. Color syntax
highlighting will be enabled once the file is saved with a Recognized extension
such as “.C “.
• Right click on “Source Group 1” and select the option “Add Files to Group 'Source
Group 1' “add the. C source file(s) to the group.
• Again right click on Source Group 1 and select the option “Add Files to
Group 'Source Group 1' “add the file -
C:Keil\ARM\startup\NXP\LPC17xx\system_LPC17xx.c
• Any changes made to this file at current project will directly change the
source system_LPC17xx.C file. As a result other project settings may get
altered. So it is recommended to copy the file
C:Keil\ARM\startup\NXP\LPC17xx\system_LPC17xx.c to the project folder
and add to the source group.
• Important: This file should be added during each project creation.
• Select “Project” then select “Translate” to compile the File (s).
• Select “Project” , select “Build Target” for building all source files such as
“.C”,”.ASM”, “.h”, files, etc…This will create the hex file if there are no warnings
& no errors.

22 | P a g e
ES LAB MANUAL LAB5: Interfacing LED to ARM Controller

Sample program to turn on/off LED serially.

Note: Before writing the program please check GPIO port pins available in the kit
(Refer Appendix C.)

#include <LPC17xx.h>

unsigned int i,j;


unsigned long LED = 0x00000010;

int main(void)
{
SystemInit() ;Add these two function for its

;internal operation

SystemCoreClockUpdate();

LPC_PINCON->PINSEL0 &= 0xFF0000FF

;Configure Port0 PINS P0.4-P0.11


;as GPIO function

LPC_GPIO0->FIODIR |= 0x00000FF0;
;Configure P0.4-P0.11 as output
;port
while(1)
{
LED = 0x00000010; Initial value on LED
for(i=1;i<9;i++) //On the LED's serially
{
LPC_GPIO0->FIOSET = LED;

; Turn ON LED at LSB(LED

;connected ;to p0.4)

for(j=0;j<10000;j++);a random delay


LED <<= 1; Shift the LED to the left by one

23 | P a g e
ES LAB MANUAL LAB5: Interfacing LED to ARM Controller

;unit.

} ; loop for 9 times

LED = 0x00000010;

for(i=1;i<9;i++) //Off the LED's serially


{
LPC_GPIO0->FIOCLR = LED;
;Turn OFF LED at LSB(LED
connected ;to p0.4)
for(j=0;j<10000;j++);
LED <<= 1;
}

}
}

Some Settings to be done in KEILUV4 for Executing C programs :

 In Project Window Right click “TARGET1” and select “options for target
‘TARGET1’ select to option “Target” in that select
1. XTAL 12.0MHz
2. Select IROM1 (starting 0×0 size 0×8000).
3. Select IRAM1 (starting 0×10000000 size 0×8000).
 Then go to option “Output”
Select “Create Hex file”.
 Then go to option “Linker”
Select use memory layout from target dialog

24 | P a g e
ES LAB MANUAL LAB5: Interfacing LED to ARM Controller

Settings to be done at configuration wizard of system_LPC17xx.c file

• There are three clock sources for CPU. Select Oscillator clock out of three.
This selection is done by CLKSRCSEL register.
• If we disable the PLL0 System clock will be bypassed directly into CPU clock
divider register.
• Use CCLKCFG register for choosing the division factor of 4 to get 3MHz out
of 12 MHz Oscillator frequency
• For any other peripherals use the PCLK same as CCLK.

Follow the steps specified below to carry out the settings.

• Double click on system_LPC17xx.c file at project window


• Select the configuration wizard at the bottom
• Expand the icons
• Select Clock configuration
• Under System controls and Status registers
OSCRANGE: Main Oscillator range select 1MHz to 20MHz
OSCEN: Main oscillator enable √
• Under Clock source select register (CLKSRCSEL)
CLKSRC: PLL clock source selection Main oscillator
• Disable PLL0 configuration and PLL1 configuration
• Under CPU Clock Configuration register(CCLKCFG)
CCLKSEL: Divide value for CPU clock for PLL0 4
• Under USB Clock configuration register (USBCLKCFG)
USBSEL: Divide value for USB clock for PLL0 4
• Under Peripheral clock selection register 0 (PCLKSEL0) and 1 (PCLKSEL1)
select Pclk = Cclk for all.
• Under Power control for peripherals (PCONP)
Enable the power for required peripherals
• If CLKOUT to be studied configure the Clock output configuration register
as
below
CLKOUTSEL : Main Oscillator
CLKOUTDIV : 1
CLKOUT_EN : √
25 | P a g e
ES LAB MANUAL LAB5: Interfacing LED to ARM Controller

• Call the functions


SystemInit();
SystemCoreClockUpdate(); at the beginning of the main function without
missing. These functions are defined in system_LPC17xx.c where the actual
clock and other system control registers are configured.
• A small change is required in the file system_LPC17xx.c after installation. Go
to text editor:
#define PLL0_SETUP 0
#define PLL1_SETUP 0
if the above #defines are 1 then make 0

Components required
• ALS-SDA-ARMCTXM3-01 : 1 No.
• Power supply (+5V) : 1 No.
• Cross cable for programming and serial communication : 1 No
• One working USB port in the host computer system and PC for
downloading the software.
• 10 core FRC cables of 8 inch length 2 No
• USB to B type cable 1 No

Some Settings for downloading the program in FLASH MAGIC:


Step1.Connect 9 pin DSUB cross cable from PC to CN9 at the board.
Step2.On the 2 way dip switch SW21. Short jumper JP3
Step3.Open flash magic 6.01

Step4.Make following setting in Flash magic(Only once)


a. Communications:
Device: LPC1768
Com Port: COM1
Baud Rate: 9600
Interface: None(ISP)

26 | P a g e
ES LAB MANUAL LAB5: Interfacing LED to ARM Controller

Oscillator: 12MHz
b. ERASE:
Select “Erase Blocks Used by Hex File”.
c. Hex file:
Browse and select the Hex file which you want to download.
d. Options:
Select “Verify After Programming”.
Go to Options -> Advanced Options->communications.
Do not select High Speed Communications, keep baud rate 115200.
Options -> Advanced Options->Hardware config
Select Use DTR & RTS to control RST & ISP Pin.
Select Keep RTS asserted while COM Port open.
T1 = 50ms. T2 = 100ms.
Step5.Start:
Click “Start” to download the hex file to the controller.
Step6. Connect one end of 10 pin FRC cable to CNA1, Short other end to CNA
Step7. Press reset controller switch SW1 and Check output on the LEDs
connected to CNA1.

Exercise Questions:
1. Write a C program to display 8-bit binary up counter on the LEDs.
2. Write a C program to read a key and display an 8-bit up/down counter on the LEDs.
Hint: Use key SW2(if SW2=1, up counter else down counter), which is available
at CNB1 pin 7. Connect CNB1 to any controller connector like CNB, CNC etc.
Configure corresponding port pin as GPIO using corresponding PINSEL register
and input pin using corresponding FIODIR register.
Additional Exercise:
3. Write a program to simulate an 8- bit ring counter with key press (SW2).

27 | P a g e
ES LAB MANUAL LAB6: Programs on multiplexed seven segment

Lab 6
Programs on Multiplexed Seven Segment Display

Aim: To interface and understand the working of multiplexed seven segments display.

Introduction:
There are four multiplexed 7-segment display units (U8, U9, U10 and U11) on the
board. Each display has 8-inputs SEG_A (Pin-7), SEG_B (Pin-6), SEG_C (Pin-4),
SEG_D (Pin-2), SEG_E (Pin-1), SEG_F (Pin-9), SEG_G (Pin-10) and SEG_H (Pin-
5) and the remaining pins pin-3 & pin-8 are Common Cathode CC. These
segments are common cathode type hence active high devices.
At power on all the segments are pulled up. A four bits input through CNB2 is used
for multiplexing operation. A 1-of-10 Decoder/Driver U7 is used to accept BCD inputs
and provide appropriate outputs for enabling the required display.
8 bits data is provided in this block using CNA2. All the data lines are taken buffered
at U12 before giving to the displays.

28 | P a g e
ES LAB MANUAL LAB6: Programs on multiplexed seven segment

At controller end any 2 connector are required for interfacing this block.

29 | P a g e
ES LAB MANUAL LAB6: Programs on multiplexed seven segment

Lookup Table for displaying 0,1,2,3 to 9

value= h g f e d c b a On 7-SEG U8,U9,U10 & U11.


* 0x3F = 0 0 1 1 1 1 1 1 -> Displaying '0'
* 0x06 = 0 0 0 0 0 1 1 0 -> Displaying '1'
* 0x5B = 0 1 0 1 1 0 1 1 -> Displaying '2'
* 0x4F = 0 1 0 0 1 1 1 1 -> Displaying '3'
* 0x66 = 0 1 1 0 0 1 1 0 -> Displaying '4'
* 0x6D = 0 1 1 0 1 1 0 1 -> Displaying '5'
* 0x7D = 0 1 1 1 1 1 0 1 -> Displaying '6'
* 0x07 = 0 0 0 0 0 1 1 1 -> Displaying '7'
* 0x7F = 0 1 1 1 1 1 1 1 -> Displaying '8'
* 0x6F = 0 1 1 0 1 1 1 1 -> Displaying '9'

Sample program : To simulate 4-digit BCD up counter on the multiplexed seven


segment display.

#include <LPC17xx.h>
#include <stdio.h>

#define FIRST_SEG 0xF87FFFFF


#define SECOND_SEG 0xF8FFFFFF
#define THIRD_SEG 0xF97FFFFF
#define FOURTH_SEG 0xF9FFFFFF
#define DISABLE_ALL 0xFA7FFFFF

unsigned int dig1=0x00,dig2=0x00,dig3=0x00,dig4=0x00;


unsigned int twenty_count = 0x00,dig_count=0x00,temp1=0x00;
unsigned char
array_dec[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F
};
unsigned char tmr0_flg = 0x00,one_sec_flg = 0x00;
unsigned long int temp2 = 0x00000000,i=0;
unsigned int temp3=0x00;
void delay(void);
void display(void);

int main(void)
{
SystemInit();
SystemCoreClockUpdate();

30 | P a g e
ES LAB MANUAL LAB6: Programs on multiplexed seven segment

LPC_PINCON->PINSEL0 &= 0xFF0000FF; //P0.4 to P0.11


//GPIO data lines
LPC_PINCON->PINSEL3 &= 0xFFC03FFF; //P1.23 to P1.26
//GPIO enable lines

LPC_GPIO0->FIODIR |= 0x00000FF0; //P0.4 to P0.11 output


LPC_GPIO1->FIODIR |= 0x07800000; //P1.23 to P1.26 output

while(1)
{
Delay();
dig_count +=1;
if(dig_count == 0x05)
{ dig_count = 0x00;
}
if(one_sec_flg == 0xFF)
{
one_sec_flg = 0x00;
dig1 +=1;

if(dig1 == 0x0A)
{
dig1 = 0;
dig2 +=1;

if(dig2 == 0x0A)
{
dig2 = 0;
dig3+=1;

if(dig3 == 0x0A)
{
dig3 = 0;
dig4 += 1;

if(dig4 == 0x0A)
{
dig4 = 0;
} //end of dig4

} //end of dig3

} //end of dig2
31 | P a g e
ES LAB MANUAL LAB6: Programs on multiplexed seven segment

} //end of dig1

} //end of one_sec if

Display();

} //end of while(1)

}//end of main

void Display(void) //To Display on 7-segments


{

if(dig_count == 0x01) // For Segment U8


{
temp1 = dig1;
LPC_GPIO1->FIOPIN = FIRST_SEG;

else if(dig_count == 0x02) // For Segment U9


{
temp1 = dig2;
LPC_GPIO1->FIOPIN = SECOND_SEG;

else if(dig_count == 0x03) // For Segment U10


{
temp1 = dig3;
LPC_GPIO1->FIOPIN = THIRD_SEG;
}
else if(dig_count == 0x04) // For Segment U11
{
temp1 = dig4;
LPC_GPIO1->FIOPIN = FOURTH_SEG;

}
temp1 &= 0x0F;
temp2 = array_dec[temp1]; // Decoding to 7-segment
temp2 = temp2 << 4;
LPC_GPIO0->FIOPIN = temp2; // Taking Data Lines for 7-Seg
32 | P a g e
ES LAB MANUAL LAB6: Programs on multiplexed seven segment

for(i=0;i<500;i++);
LPC_GPIO0->FIOCLR = 0x00000FF0;
// LPC_GPIO1->FIOPIN = DISABLE_ALL;//disable all the segments
}
Void delay(void)
{ unsigned int i;
For(i=0;i<1000;i++);
if(twenty_count ==1000) //multiplied by 500x2msec for
//1 Sec
{
one_sec_flg = 0xFF;
twenty_count = 0x00;
}
else twenty_count += 1;

Components required
• ALS-SDA-ARMCTXM3-01 : 1 No.
• Power supply (+5V) : 1 No.
• Cross cable for programming and serial communication : 1 No
• One working USB in the host computer system and PC for downloading
the software.
• 10 core FRC cables of 8 inch length 2 No
• USB to B type cable 1 No

Hardware setup: Connect a 10 core FRC cable from CNA to CNA2 and CNB to CNB2.

Working procedure: After software download and hardware setup, press the reset,
Observe the count from 0000 to 9999 on the display.

Exercise Questions:
1. Write a C program for 4 digit BCD up/down counter on seven segment using a
switch and timer with a delay of 1-second between each count.
Additional Exercise:
1. Write a C program to simulate a 4 digit BCD down counter. Use timer for a delay

33 | P a g e
ES LAB MANUAL LAB6: Programs on multiplexed seven segment

2. Write a program for 4 digit Hexadecimal up/down counter on seven segment using
a switch and timer with a delay of 1-second between each count.

34 | P a g e
ES LAB MANUAL LAB 7: LCD and KEYBOARD Interfacing

Lab 7
Liquid Crystal Display (LCD) and Keyboard Interfacing

Aim: To interface and understand the working of LCD and matrix keyboard.

Introduction:
LCD: A 16×2 alphanumeric LCD can be used to display the message from controller.
16 pin small LCD has to be mounted to the connector CN11. 10 pin connector CNAD is
used to interface this LCD from controller. Only higher 4 data lines are used among the
8 LCD data lines. Use POT3 for contrast adjustment and Short the jumper JP16 to use
this LCD. LCD connector CN11 is described in this table. CN11 is single row 16 pin
female berg.

Connection from CNAD to LCD connector CN11 is shown below

35 | P a g e
ES LAB MANUAL LAB 7: LCD and KEYBOARD Interfacing

36 | P a g e
ES LAB MANUAL LAB 7: LCD and KEYBOARD Interfacing

Sample program: To display message on LCD

#include <lpc17xx.h>

#define RS_CTRL 0x08000000 //P0.27


#define EN_CTRL 0x10000000 //P0.28
#define DT_CTRL 0x07800000 //P0.23 to P0.26 data lines

void lcd_init(void);
void wr_cn(void);
void clr_disp(void);
void delay_lcd(unsigned int);
void lcd_com(void);
void wr_dn(void);
void lcd_data(void);
void clear_ports(void);
void lcd_puts(unsigned char *);

extern unsigned long int temp1 , temp2;

unsigned long int temp1=0, temp2=0 ;

int main(void)
{
unsigned long adc_temp;
unsigned int i;
float in_vtg;
unsigned char vtg[7],dval[7];
unsigned char Msg3[11] = {"MIT"};
unsigned char Msg4[12] = {"Department of ICT:"};

SystemInit();
SystemCoreClockUpdate();
lcd_init();
temp1 = 0x80;
lcd_com();
delay_lcd(800);
lcd_puts(&Msg3[0]);

temp1 = 0xC0;
lcd_com();
delay_lcd(800);
lcd_puts(&Msg4[0]);

37 | P a g e
ES LAB MANUAL LAB 7: LCD and KEYBOARD Interfacing

}
//lcd initialization
void lcd_init()
{
/* Ports initialized as GPIO */
LPC_PINCON->PINSEL3 &= 0xFC003FFF; //P0.23 to P0.28

/* Setting the directions as output */


LPC_GPIO0->FIODIR |= DT_CTRL;
LPC_GPIO0->FIODIR |= RS_CTRL;
LPC_GPIO0->FIODIR |= EN_CTRL;

clear_ports();
delay_lcd(3200);

temp2 = (0x30<<19);
wr_cn();
delay_lcd(30000);

temp2 = (0x30<<19);
wr_cn();
delay_lcd(30000);

temp2 = (0x30<<19);
wr_cn();
delay_lcd(30000);

temp2 = (0x20<<19);
wr_cn();
delay_lcd(30000);

temp1 = 0x28;
lcd_com();
delay_lcd(30000);

temp1 = 0x0c;
lcd_com();
delay_lcd(800);

temp1 = 0x06;
lcd_com();
delay_lcd(800);

temp1 = 0x01;
38 | P a g e
ES LAB MANUAL LAB 7: LCD and KEYBOARD Interfacing

lcd_com();
delay_lcd(10000);

temp1 = 0x80;
lcd_com();
delay_lcd(800);
return;
}

void lcd_com(void)
{
temp2 = temp1 & 0xf0;//move data (26-8+1) times : 26 - HN
//place, 4 - Bits
temp2 = temp2 << 19; //data lines from 23 to 26
wr_cn();
temp2 = temp1 & 0x0f; //26-4+1
temp2 = temp2 << 23;
wr_cn();
delay_lcd(1000);
return;
}

// command nibble o/p routine


void wr_cn(void) //write command reg
{
clear_ports();
LPC_GPIO0->FIOPIN = temp2; // Assign the value to the data
//lines
LPC_GPIO0->FIOCLR = RS_CTRL; // clear bit RS
LPC_GPIO0->FIOSET = EN_CTRL; // EN=1
delay_lcd(25);
LPC_GPIO0->FIOCLR = EN_CTRL; // EN =0
return;

// data o/p routine which also outputs high nibble first


// and lower nibble next
void lcd_data(void)
{
temp2 = temp1 & 0xf0;
temp2 = temp2 << 19;
wr_dn();
temp2= temp1 & 0x0f;
39 | P a g e
ES LAB MANUAL LAB 7: LCD and KEYBOARD Interfacing

temp2= temp2 << 23;


wr_dn();
delay_lcd(1000);
return;
}

// data nibble o/p routine


void wr_dn(void)
{
clear_ports();

LPC_GPIO0->FIOPIN = temp2; // Assign the value to the


//data lines
LPC_GPIO0->FIOSET = RS_CTRL; // set bit RS
LPC_GPIO0->FIOSET = EN_CTRL; // EN=1
delay_lcd(25);
LPC_GPIO0->FIOCLR = EN_CTRL; // EN =0
return;
}

void delay_lcd(unsigned int r1)


{
unsigned int r;
for(r=0;r<r1;r++);
return;
}

void clr_disp(void)
{
temp1 = 0x01;
lcd_com();
delay_lcd(10000);
return;
}
void clear_ports(void)
{
/* Clearing the lines at power on */
LPC_GPIO0->FIOCLR = DT_CTRL; //Clearing data lines
LPC_GPIO0->FIOCLR = RS_CTRL; //Clearing RS line
LPC_GPIO0->FIOCLR = EN_CTRL; //Clearing Enable line

return;
}

40 | P a g e
ES LAB MANUAL LAB 7: LCD and KEYBOARD Interfacing

void lcd_puts(unsigned char *buf1)


{
unsigned int i=0;

while(buf1[i]!='\0')
{
temp1 = buf1[i];
lcd_data();
i++;
if(i==16)
{
temp1 = 0xc0;
lcd_com();
}

}
return;
}

Components required
• ALS-SDA-ARMCTXM3-01 : 1 No.
• Power supply (+5V) : 1 No.
• Cross cable for programming and serial communication: 1 No
• One working USB port in the host computer system and PC for downloading
the software.
• 10 core FRC cables of 8 inch length 2 No
• USB to B type cable 1 No

Hardware setup:
Connect 10 pin FRC cable from CND to CNAD. Short the jumper JP16 & JP5.
Use POT3 for contrast adjustment.
Working procedure: After software download and hardware setup, press the
reset. A fixed message will display on LCD.
Exercise Questions:
1. Simulate DIE tossing on LCD
Hint: Program reads the external interrupt using the key SW2. A random number
between 0-6 should be displayed on the LCD upon keypress.

41 | P a g e
ES LAB MANUAL LAB 7: LCD and KEYBOARD Interfacing

Keyboard connection: The switches SW3 to SW18 are organized as 4 rows X 4


columns matrix. One end of all the switches are configured as columns. The other end
of the matrix configured as rows. A row line will be always an output from the
controller. Column lines are pulled to ground. A high level sent from the row will
appear at column end if the switch is pressed.
Connector CNB3 is used for interfacing this block with controller. At the controller
end any connector can be used to interact this connector CNB3.

42 | P a g e
ES LAB MANUAL LAB 7: LCD and KEYBOARD Interfacing

Sample program: To read a key from the matrix keyboard and display its key code on
the LCD.

#include <LPC17xx.h>
void scan(void);

unsigned char col,row,var,flag,key,*ptr;


unsigned long int i,var1,temp,temp3;
int main(void)
{
SystemInit();
SystemCoreClockUpdate();

LPC_PINCON->PINSEL3 &= 0xFFC03FFF; //P1.23 to P1.26 MADE


//GPIO
LPC_PINCON->PINSEL3 &= 0xF00FFFFF; //P2.10 t P2.13 made
//GPIO
LPC_GPIO2->FIODIR |= 0x00003C00; //made output P2.10 to
//P2.13 (rows)
LPC_GPIO1->FIODIR &= 0xF87FFFFF; //made input P1.23 to
//P1.26 (cols)
while(1)
{
while(1)
{
for(row=1;row<5;row++)
{
if(row == 1)
var1 = 0x00000400;
else if(row == 2)
var1 = 0x00000800;
else if(row == 3)
var1 = 0x00001000;
else if(row == 4)
var1 = 0x00002000;

temp = var1;

LPC_GPIO2->FIOCLR = 0x00003C00;
LPC_GPIO2->FIOSET = var1;

flag = 0;
scan();
43 | P a g e
ES LAB MANUAL LAB 7: LCD and KEYBOARD Interfacing

if(flag == 1)
break;

} //end for(row=1;row<5;row++)

if(flag == 1)
break;

} //2nd while(1)

void scan(void)
{
unsigned long temp3;

temp3 = LPC_GPIO0->FIOPIN;
temp3 &= 0x0780000;
if(temp3 != 0x00000000)
{
flag = 1;
if (temp3 ==0x0080000)
col=0;
else if (temp3==0x0100000)
col=1;
else if (temp3==0x00200000)
col=2;
else if (temp3==0x0400000)
col=3;

}//1st if(temp3 != 0x00000000)


}//end scan
Display(key) //write display function to display the keycode
//on the LCD or on seven segment display
}
Components required
• ALS-SDA-ARMCTXM3-01 : 1 No.
• Power supply (+5V) : 1 No.
• Cross cable for programming and serial communication : 1 No
• One working USB port in the host computer system and PC for downloading
the software.
• 10 core FRC cables of 8 inch length 2 No
• USB to B type cable 1 No
44 | P a g e
ES LAB MANUAL LAB 7: LCD and KEYBOARD Interfacing

Hardware setup: Connect 10 core FRC cable from CNB to CNB3, short JP4(1, 2)
Connect another 10 core FRC cable from CND to CNAD, Short the jumper JP16
& JP5. Use POT3 for contrast.
Working procedure: After software download and hardware setup, use the reset.
Identity of key pressed (0 to F) will be displayed on LCD.

Exercise questions:
1. Write a program to input an expression of the type A operator B =, from the key
board, where A and B are the single digit BCD numbers and operator may be + or
- .Display the result on the LCD.

45 | P a g e
ES LAB MANUAL LAB 9: PWM Interfacing

Lab 8
Analog to Digital Convertor (ADC)

Aim: To understand the working of a 12 bit internal Analog-to-Digital Converter


(ADC).

Introduction: The LPC1768 contains a single 12-bit successive approximation


ADC with eight channels and DMA support. 12-bit ADC with input multiplexing
among eight pins, conversion rates up to 200 kHz, and multiple result registers.
The 12-bit ADC can be used with the GPDMA controller. On board there are two
interfaces for internal ADC’s. AD0.5 (pin P1.31) of controller is used to convert the
analog input voltage varied using POT1 to digital value. AD0.4(Pin 1.30) used convert
the analog voltage varied using POT4. A input voltage range of 0 to 3.3V is accepted.
000 to FFF is the converted digital voltage range here. Short JP18 (2, 3) to use
AD0.4.

Sample program: To configure and read analog data from ADC channel no 5, and
display the digital data on the LCD

#include<LPC17xx.h>
#include<stdio.h>
#include"AN_LCD.h"
#define Ref_Vtg 3.300
#define Full_Scale 0xFFF //12 bit ADC

int main(void)
{
unsigned long adc_temp;
unsigned int i;
float in_vtg;
unsigned char vtg[7],dval[7];
unsigned char Msg3[11] = {"ANALOG IP:"};
unsigned char Msg4[12] = {"ADC OUTPUT:"};

SystemInit();
SystemCoreClockUpdate();

LPC_SC->PCONP |= (1<<15); //Power for GPIO block


lcd_init();

46 | P a g e
ES LAB MANUAL LAB 9: PWM Interfacing

LPC_PINCON->PINSEL3 |= 0xC0000000; //P1.31 as AD0.5


LPC_SC->PCONP |= (1<<12); //enable the peripheral ADC

SystemCoreClockUpdate();

temp1 = 0x80;
lcd_com();
delay_lcd(800);
lcd_puts(&Msg3[0]);

temp1 = 0xC0;
lcd_com();
delay_lcd(800);
lcd_puts(&Msg4[0]);

while(1)
{
LPC_ADC->ADCR = (1<<5)|(1<<21)|(1<<24);//0x01200001;
//ADC0.5, start conversion and operational
//for(i=0;i<2000;i++); //delay for conversion
while((adc_temp = LPC_ADC->ADGDR) == 0x80000000);
//wait till 'done' bit is 1, indicates conversion complete
adc_temp = LPC_ADC->ADGDR;
adc_temp >>= 4;
adc_temp &= 0x00000FFF; //12 bit ADC
in_vtg = (((float)adc_temp *
(float)Ref_Vtg))/((float)Full_Scale); //calculating input analog
//voltage
sprintf(vtg,"%3.2fV",in_vtg);
//convert the readings into string to display on LCD
sprintf(dval,"%x",adc_temp);
for(i=0;i<2000;i++);

temp1 = 0x8A;
lcd_com();
delay_lcd(800);
lcd_puts(&vtg[0]);

temp1 = 0xCB;
lcd_com();
delay_lcd(800);
lcd_puts(&dval[0]);

for(i=0;i<200000;i++);
47 | P a g e
ES LAB MANUAL LAB 9: PWM Interfacing

for(i=0;i<7;i++)
vtg[i] = dval[i] = 0x00;
adc_temp = 0;
in_vtg = 0;
}
}

Components required
 ALS-SDA-ARMCTXM3-01 : 1 No.
 Power supply (+5V) : 1 No.
 Cross cable for programming and serial communication : 1 No
 One working COM port (Ex: COM1) in the host computer system and PC
for downloading the software.
 10 core FRC cables of 8 inch length 2 No
 USB to B type cable 1 No

Hardware Setup: Do the setup related to LCD


Working procedure: Vary POT1 and observe the corresponding analog and digital
voltage values on LCD.

Exercise question
a. Write a c program to display the digital value representing the difference in analog
voltages at ADC channel 4 and channel 5 on LCD.

48 | P a g e
ES LAB MANUAL LAB 9: PWM Interfacing

Lab 9
Pulse Width Modulation (PWM) Interfacing

Aim: To interface and understand the working of PWM.

Introduction: The PWM is based on the standard Timer block and inherits all of
its features, although only the PWM function is pinned out on theLPC1768. The Timer
is designed to count cycles of the system derived clock and optionally switch pins,
generate interrupts or perform other actions when the specified timer values occur, based
on seven match registers. The PWM function is in addition to these features, and is based
on match register events. A PWM output from the controller can be observed as an
intensity variation of the LED LD10.

Sample program: To vary the intensity of an LED using PWM.


#include <LPC17xx.H>
void pwm_init(void);
void PWM1_IRQHandler(void);

unsigned long int i;


unsigned char flag,flag1;

int main(void)
{
SystemInit();
SystemCoreClockUpdate();
pwm_init();

while(1)
{
for(i=0;i<=1000;i++); // delay
}//end of while

49 | P a g e
ES LAB MANUAL LAB 9: PWM Interfacing

}//end of main
void pwm_init(void)
{
LPC_SC->PCONP |= (1<<6); //PWM1 is powered
LPC_PINCON->PINSEL3 &= ~(0x0000C000); //cleared if any other
//functions are enabled
LPC_PINCON->PINSEL3 |= 0x00008000; //pwm1.4 is selected for the pin
//P1.23

//LPC_PWM1->PR = 0x00000000; //Count frequency : Fpclk


LPC_PWM1->PCR = 0x00001000; //select PWM1 single edge
LPC_PWM1->MCR = 0x00000003; //Reset and interrupt on PWMMR0
LPC_PWM1->MR0 = 30000; //setup match register 0 count
LPC_PWM1->MR4 = 0x00000100; //setup match register MR1
LPC_PWM1->LER = 0x000000FF; //enable shadow copy register
LPC_PWM1->TCR = 0x00000002; //RESET COUNTER AND PRESCALER
LPC_PWM1->TCR = 0x00000009; //enable PWM and counter

NVIC_EnableIRQ(PWM1_IRQn);
return;
}

void PWM1_IRQHandler(void)
{
LPC_PWM1->IR = 0xff; //clear the interrupts

if(flag == 0x00)
{
LPC_PWM1->MR4 += 100;
LPC_PWM1->LER = 0x000000FF;

if(LPC_PWM1->MR4 >= 27000)


50 | P a g e
ES LAB MANUAL LAB 9: PWM Interfacing

{
flag1 = 0xff;
flag = 0xff;
LPC_PWM1->LER = 0x000000fF;
}
}
else if(flag1 == 0xff)
{
LPC_PWM1->MR4 -= 100;
LPC_PWM1->LER = 0x000000fF;

if(LPC_PWM1->MR4 <= 0x500)


{
flag = 0x00;
flag1 = 0x00;
LPC_PWM1->LER = 0X000000fF;
}
}
}

Hardware setup: Connect 10 pin FRC cable from CNB to CNB1.


Working procedure: As the pulse width varies, intensity of LED LD10 varies.
Observe the pulses at TP5. Observe the amplitude level at TP6.

Exercise question:
Write a program to set the following intensity levels to the LED connected to PWM
output. Use ROW-0 of keyboard for intensity variation
Intensity level Key pressed
10% 0
25% 1
50% 2
75% 3
51 | P a g e
ES LAB MANUAL LAB 10, LAB11: Familiarization with ARM mbed Board

Lab 10 , Lab11
Familiarization with ARM mbed Prototyping Board

Aim: Familiarize with ARM mbed NXP LPC1768 prototyping board by interfacing with
LEDs.

Introduction: The mbed Microcontrollers are a series of ARM microcontroller


development boards designed for rapid prototyping. The mbed NXP LPC1768
Microcontroller is designed for prototyping all sorts of devices, especially those including
Ethernet, USB, and the flexibility of lots of peripheral interfaces and FLASH memory. It
is packaged as a small DIP form-factor for prototyping with through-hole PCBs,
stripboard, and breadboard. It includes a built-in USB FLASH programmer. The pinout
diagram in Figure 12.1 shows the commonly used interfaces and their locations. Note that
all the numbered pins (p5-p30) can also be used as DigitalIn and DigitalOut interfaces.

Figure 12.1 Pinout Diagram of mbed LPC1768 Board

52 | P a g e
ES LAB MANUAL LAB 10, LAB11: Familiarization with ARM mbed Board

Components Required:
• An mbed microcontroller
• A USB cable for connecting the microcontroller and PC.
• A PC with one working USB port for flashing the code.

To build the programs either using the ARM mbed Online Compiler or ARM mbed Studio
could be used.
Steps to be followed for using the online compiler:
1. Connect the mbed microcontroller to a PC. The status light will glow, indicating
power on.The PC will recognize the mbed microcontroller as a standard USB
drive.
2. Go to the new USB drive, and click on MBED.HTML to open it in a web browser.
3. Create an mbed account using your learner id (Username: your registration
number). To use the online compiler, you will need to verify your email address.
URL: https://os.mbed.com/account/signup/
4. Click on the “Compiler” tab in the dashboard page, as shown in Figure 12.2.

Figure 12.2 Mbed Dashboard

5. Create a new program by selecting “New Program” in the “New” tab of the online
IDE. As shown in Figure 12.3, type in the program name and click “OK”.

53 | P a g e
ES LAB MANUAL LAB 10, LAB11: Familiarization with ARM mbed Board

Figure 12.3 Creation of a New Program

6. In the Program Workspace, a main.cpp file will be created. Clicking on that file
will reveal a sample program to blink a LED. Insert your own code in place of
that. Alternatively, you could import your code into the workspace. Save your
program.
7. Compile the code by clicking on the “Compile” tab, or press CTRL-D. The Online
Compiler compiles the code into an executable file, which will be downloaded.
When prompted, save the file(.bin) in mbed board's USB device folder.
8. Press reset switch on the board to complete the flashing/programming process.

54 | P a g e
ES LAB MANUAL LAB 10, LAB11: Familiarization with ARM mbed Board

Sample Question: Write a CPP program to blink all four LEDs in the mbed LPC1768
board.

//******************************************************
// Program written using C++ for mbed LPC1768 board.
// Program to blink all four onboard LEDs.
// Author: *****
// Date: DD-Mon-YYYY
//******************************************************
#include "mbed.h"
DigitalOut myled1(LED1);
DigitalOut myled2(LED2);
DigitalOut myled3(LED3);
DigitalOut myled4(LED4);
int main()
{
while(1) {
//turn on LED1 through LED4
myled1 = 1;
myled2 = 1;
myled3 = 1;
myled4 = 1;
wait(0.5); // delay of 0.5 seconds
//turn off LED1 through LED4
myled1 = 0;
myled2 = 0;
myled3 = 0;
myled4 = 0;
wait(0.5); //delay of 0.5 seconds
}
}

55 | P a g e
ES LAB MANUAL LAB 10, LAB11: Familiarization with ARM mbed Board

Exercise Programs
1. Write a CPP program to display a 4-bit binary up counter on the LEDs.
2. Write a CPP program to display a 4-bit binary down counter on the LEDs.
3. Write a CPP program to display a ring counter on the LEDs.

56 | P a g e
ES LAB MANUAL Appendix A

Appendix A: Instructions

Instruction Set Summary

Mnemonic Operation Description

ADC Rd := Rn + Op2 + C Add with carry


ADD Rd := Rn + Op2 Add
ADDS Rd: = Rn+ Op2 Add and update falgs
ADR Rd: = Rn, label Load register with adress
AND Rd := Rn AND Op2 AND
ANDS Rd := Rn AND Op2 AND update flags
ASR Rd: = Rn,#LSB,#width Arithmetic shift right
B R15 := address Branch
BIC Rd := Rn AND NOT Op2 Bit Clear
BL R14 := address of next Branch with Link
instruction, R15 :=address
BX R15 := Rn, change to Thumb Branch and Exchange
if address bit 0 is 1
CLZ Rd := number of leading Count Leading Zeroes
zeroes in Rm
CMN CPSR flags := Rn + Op2 Compare Negative
CMP CPSR flags := Rn - Op2 Compare
EOR Rd:= Rn EOR Op2 Exclusive OR
LDM Stack manipulation (Pop) Load multiple Registers (refer last
paragraph of this appendix)
LDMIA LDMIA Rn!, {reglist} Load multiple registers from memory
LDR Rd := [address][31:0] Load 32-bit word from memory.
LDRB Rd := ZeroExtend Load register byte value to Memory.
([address][7:0])
LDRH Rd := ZeroExtend Load register 16-bit halfword value to
([address][15:0]) Memory.
MCR cRn:=rRn {<op>cRm} Move CPU register to coprocessor register
MLA Rd := (Rm * Rs) + Rn Multiply Accumulate
MOV Rd := Op2 Move register or constant
MRS Rn := PSR Move PSR status flags to register

57 | P a g e
ES LAB MANUAL Appendix A

MSR PSR := Rm Move register to PSR status flags


MUL Rd := Rm * Rs Multiply
MVN Rd := NOT Rm Move inverted register or constant
NOP None No operation
ORR Rd:=Rn OR Op2 OR
PUSH PUSH {reg list} Push registers on to the stack pointed by
R13
POP POP{reg. list} Pop registers from the stack pointed by R13
RSB Rd := Op2 – Rn Reverse Subtract
RSC Rd := Op2 - Rn - 1+Carry Reverse Subtract with Carry
RBIT RBIT Rd, Rn Reverse the bit order in a 32-bit word
REV REV Rd, Rn converts 32-bit big-endian data into little-
endian data or 32-bit little-endian data into
big-endian data
ROR Rd: = Rd, Rs Rotate Rd register by Rs bits
RRX Rd: = Rd, Rm Rotate Right with Extend
SBC Rd := Rn - Op2 - 1+Carry Subtract with Carry
STM stack manipulation (Push) Store Multiple (refer last paragraph of this
appendix
STR <address>:=Rd Store register to memory
STRB [address][7:0] := Rd[7:0] Store register byte value to Memory.
STRH [address][15:0] :=Rd[15:0] Store register 16-bit halfword value to
Memory
SUB Rd := Rn - Op2 Subtract
TEQ CPSR flags:= Rn EOR Op2 Test bitwise equality
TST CPSR flags:= Rn AND Op2 Test bits
UMULL UMULL r0, r4, r5, r6 Unsigned Long Multiply

58 | P a g e
ES LAB MANUAL Appendix A

A conditional instruction is only executed on match of the condition flags in the Program
Status Register. For example, the BEQ (B instruction with EQ condition) branches only
if the Z flag is set. If the {cond} field is empty the instruction is always executed.
{cond} Suffix Tested Status Flags Description

EQ Z set equal
NE Z clear not equal
CS/HS C set unsigned higher or same
CC/LO C clear unsigned lower
MI N set negative
PL N clear positive or zero
VS V set overflow
VC V clear no overflow
HI C set and Z clear unsigned higher
LS C clear or Z set unsigned lower or same
GE N equals V signed greater or equal
LT N not equal to V signed less than
GT Z clear AND (N equals V) signed greater than
LE Z set OR (N not equal to V) signed less than or equal
AL (ignored) always (usually omitted)

Addressing Mode for LDM and STM

The instructions LDM and STM provide four different addressing modes. The addressing
mode specifies the behavior of the base register and is explained in the following table.

Addressing Mode Description


IA Increment base register after instruction execution.
IB Increment base register before instruction execution.
DA Decrement base register after instruction execution.
DB Decrement base register before instruction execution.

Examples:

STMDB R2!,{R4,R5,LR}
LDMIA R0!,{R1-R5}
STMDB R6!,{R0,R1,R5}

59 | P a g e
ES LAB MANUAL Appendix B

Appendix B: Addressing modes

Name Alternative Name ARM Examples


------------------------------------------------------------------------
Register to register Register direct MOV R0, R1
------------------------------------------------------------------------
Absolute Direct LDR R0, MEM
------------------------------------------------------------------------
Literal Immediate MOV R0, #15
ADD R1, R2, #12
------------------------------------------------------------------------
Indexed, base Register indirect LDR R0, [R1]
------------------------------------------------------------------------
Pre-indexed, Register indirect LDR R0, [R1, #4]
base with displacement with offset
------------------------------------------------------------------------
Pre-indexed, Register indirect LDR R0, [R1, #4]!
autoindexing pre-incrementing
------------------------------------------------------------------------
Post-indexing, Register indirect LDR R0, [R1], #4
autoindexed post-increment
------------------------------------------------------------------------
Double Reg indirect Register indirect LDR R0, [R1, R2]
Register indexed
------------------------------------------------------------------------
Double Reg indirect Register indirect LDR R0, [R1, r2, LSL #2]
with scaling indexed with scaling
------------------------------------------------------------------------
Program counter relative LDR R0, [PC, #offset]
---------------------------------------------------------------------

Literal Addressing

In this addressing mode data is a part of instruction. ‘#’ symbol is used to indiacate the
data. ARM and Thumb instructions can only be 32 bits wide. You can use a MOV or
MVN instruction to load a register with an immediate value from a range that depends on
the instruction set. Certain 32-bit values cannot be represented as an immediate operand
to a single 32-bit instruction, although you can load these values from memory in a single
60 | P a g e
ES LAB MANUAL Appendix B

instruction. you can load any 32-bit immediate value into a register with two instructions,
a MOV followed by a MOVT. Or, you can use a pseudo-instruction, MOV32, to construct
the instruction sequence for you. You can also use the LDR pseudo-instruction to load
immediate values into a register

Examples Meaning
----------------------------------------------------------------------
CMP R0, #22 ;Compare Register content R0 with 22
----------------------------------------------------------------------
ADD R1, R2, #18 ;Add the content of R2 and 18 then store
;the result in R1
----------------------------------------------------------------------
MOV R1, #30 ;copy the data 30 into register R1
----------------------------------------------------------------------
MOV R1, #0Xff ;copy the data ff in hexadecimal into R1
----------------------------------------------------------------------
MOV R2, #0xFF0000FF
----------------------------------------------------------------------
AND R0, R1, #0xFF000000
----------------------------------------------------------------------
CMN R0, #6400 ; update the N, Z, C and V flags
----------------------------------------------------------------------
CMPGT SP, R7, LSL #2 ; update the N, Z, C and V flags
----------------------------------------------------------------------

 MOV can load any 8-bit immediate value, giving a range of 0x0-0xFF (0-255). It can
also rotate these values by any even number. These values are also available as
immediate operands in many data processing operations, without being loaded in a
separate instruction.
 MVN can load the bitwise complements of these values. The numerical values are -
(n+1), where n is the value available in MOV.
 A MOVT instruction that can load any value in the range 0x0000 to 0xFFFF into the
most significant half of a register, without altering the contents of the least significant
half.
 The LDR Rd,=const pseudo-instruction generates the most efficient single instruction
to load any 32-bit number

Introduction to Register Indirect Addressing : Register indirect addressing means that


the location of an operand is held in a register. It is also called indexed addressing or base
addressing.
61 | P a g e
ES LAB MANUAL Appendix B

Register indirect addressing mode requires three read operations to access an operand. It
is very important because the content of the register containing the pointer to the operand
can be modified at runtime. Therefore, the address is a vaiable that allows the access to
the data structure like arrays.

 Read the instruction to find the pointer register


 Read the pointer register to find the oprand address
 Read memory at the operand address to find the operand

Some examples of using register indirect addressing mode:

LDR R2, [R0] ; Load R2 with the word pointed by R0


----------------------------------------------------------------------
STR R2, [R3] ; Store the word in R2 in the location
; pointed by R3
----------------------------------------------------------------------
LDR Rd,=label can load any 32-bit numeric value into a register. It also accepts PC-
relative expressions such as labels, and labels with offsets

Register Indirect Addressing with an Offset

ARM supports a memory-addressing mode where the effective address of an operand is


computed by adding the content of a register and a literal offset coded into load/store
instruction. For example,

Instruction Effective Address


---------------------------------------------------------------------
LDR R0, [R1, #20] R1 + 20 ; loads R0 with the word
; pointed at by R1+20
---------------------------------------------------------------------

62 | P a g e
ES LAB MANUAL Appendix B

ARM's Autoindexing Pre-indexed Addressing Mode

This is used to facilitate the reading of sequential data in structures such as arrays, tables,
and vectors. A pointer register is used to hold the base address. An offset can be added to
achieve the effective address. For example,

Instruction Effective Address


----------------------------------------------------------------------
LDR R0, [R1, #4]! R1 + 4 ; loads R0 with the word
;pointed at by R1+4 then
;update the pointer
;by adding 4 to R1
----------------------------------------------------------------------

ARM's Autoindexing Post-indexing Addressing Mode

This is similar to the above, but it first accesses the operand at the location pointed by the
base register, then increments the base register. For example,

Instruction Effective Address


----------------------------------------------------------------------
LDR R0, [R1], #4 R1 ;loads R0 with the word
;pointed at by R1 then
;update the pointed by
;adding 4 to R1
----------------------------------------------------------------------

Program Counter Relative (PC Relative) Addressing Mode

Register R15 is the program counter. If you use R15 as a pointer register to access
operand, the resulting addressing mode is called PC relative addressing. The operand is
specified with respect to the current code location. Please look at this example,

Instruction Effective Address


----------------------------------------------------------------------
LDR R0, [R15, #24] R15 + 24 ;loads R0 with the word
;pointed at by R1+24
----------------------------------------------------------------------

63 | P a g e
ES LAB MANUAL

APPENDIX C
GPIO extension connectors:

There are four 10 pin FRC type male connectors, they extends the controllers
general purpose port lines for the use of user requirements. Details on each connector is
given below:

CNA –10 pin male box type FRC connector. Port lines P0.4 to P0.11 from controller are
terminated in this connector. They can be extended to interface few on board or external
peripherals. The pins mentioned in the above table are configured to work as a GPIO's at
power on. Other alternate functions on those pins needs to be selected using
respective PINSEL registers.

CNB – 10 pin male box type FRC connector. Port lines fromP1.23 to P1.26 and P2.10
to

P2.13 are terminated in this connector.

64 | P a g e
ES LAB MANUAL

Description of the connector CNB:

CNC – 10 pin male box type FRC connector. Port lines fromP0.15 to P0.22 and P2.13
are terminated in this connector.

65 | P a g e
ES LAB MANUAL

CND – 10 pin male box type FRC connector. Port lines fromP0.23 to P0.28 and P2.0 to
P2.1 are terminated in this connector.

66 | P a g e

You might also like