ARM - Lab - Manual

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 35

lOMoAR cPSD| 30134443

Vision and Mission of the Institute

Vision of the Institute


To develop technologically competent, humane and socially responsible engineers
and managers to meet the ever growing challenges of the Global Environment.

Mission of the Institute


• To provide quality technical and management education by applying best
practices in teaching, learning and with the state-of-the-art infrastructural
facilities.
• To mould engineers and managers with appropriate pedagogy to develop
leadership qualities and skills by imbibing professional ethics to make them
industry ready.
• To develop student-centric institution which evolves and fosters the talents of
budding engineers, managers and entrepreneurs and prepare them to make a
positive contribution to the society.
• To promote Research and Consultancy through collaboration with industries and
Government Organizations.

1
lOMoAR cPSD| 30134443

Vision, Mission, PEOs & PSOs of the Department

Vision of the Department


To excel in creating technically competent and socially responsible Electronics &
Communication Engineers capable of contributing to the emerging technology.

Mission of the Department


M1: Imparting effective technical education to excel in Electronics &
Communication Engineering.
M2: Adapting appropriate pedagogy to imbibe professionalism in students.
M3: Inculcating Research culture and there by bridging the gap between Academia
and Industry.

Program Educational Objectives


PEO1: To deliver Engineering Skills and Knowledge by integrating basic
engineering concepts with core Electronics and Communication Engineering
to solve the problems of the society.
PEO2: To exhibit technical competency by developing solutions in diverse areas of
Electronics and Communication Engineering.
PEO3: To be receptive to emerging technologies and attain professional competency
through pursuing Research and life-long learning.

Program Specific Outcomes


PSO1: PSO1: Design, analyse and develop Analog and Digital Systems using
advanced hardware and software tools and technologies.
PSO2: Implement distinct models of Embedded systems, VLSI, Signal Processing
and Networking by various applications.

2
lOMoAR cPSD| 30134443

Program Outcomes

Graduates of Electronics & Communication Engineering by the time of graduation


will demonstrate:

PO1: Engineering knowledge: Apply the knowledge of mathematics, science,


engineering fundamentals, and an engineering specialization to the solution of
complex engineering problems.

PO2: Problem analysis: Identify, formulate, research literature, and analyze


complex engineering problems reaching substantiated conclusions using first
principles of mathematics, natural sciences, and engineering sciences.

PO3: 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.

PO4: 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.

PO5: Modern tool usage: Create, select, and apply appropriate techniques,
resources, and modern engineering and IT tools including prediction and modelling
to complex engineering activities with an understanding of the limitations.

PO6: 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.

PO7: 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.

PO8: Ethics: Apply ethical principles and commit to professional ethics and
responsibilities and norms of the engineering practice.
3
lOMoAR cPSD| 30134443

PO9: Individual and team work: Function effectively as an individual, and as a


member or leader in diverse teams, and in multidisciplinary settings.

PO10: 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.

PO11: 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.

PO12: 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.

4
lOMoAR cPSD| 30134443

5
lOMoAR cPSD| 30134443

6
lOMoAR cPSD| 30134443

7
lOMoAR cPSD| 30134443

8
lOMoAR cPSD| 30134443

Course objectives:
1. Explain the basic organization of a computer system.
2. Demonstrate functioning of different sub systems, such as processor, Input/output, and memory.
3. Describe the architectural features and instructions of 32-bit microcontroller ARM Cortex M3.
4. Apply the knowledge gained for Programming ARM Cortex M3 for different applications.
5. Understand the basic hardware components and their selection method based on the
characteristics and attributes of an embedded system.

Course outcomes:
After studying this course, student will be able to
CO’S STATEMENTS

C302.1 Explain the basic organization of a computer system.


Demonstrate functioning of different sub systems, such as processor, Input/output,
C302.2
and memory.
Describe the architectural features and instructions of 32-bit microcontroller ARM
C302.3
Cortex M3.
Apply the knowledge gained for Programming ARM Cortex M3 for different
C302.4
applications.

CO-PO mapping
Course Program Specific
Program Outcomes
Outcomes Outcomes
CO’S PO-1 PO-2 PO-3 PO-4 PO-5 PO-6 PO-7 PO-8 PO-9 PO-10 PO-11 PO-12 PSO-1 PSO-2

C302.1 3 2 2 - - - - - - - - - - 1

C302.2 3 3 2 - - - - - - - - - - 1

C302.3 3 3 3 2 3 - - - 2 2 2 3 - 2

C302.4 3 3 2 2 3 - - - 2 2 2 3 - 2

Sum 12 11 9 4 6 - - - 4 4 4 4 - 8
Average 3 2.75 2.25 2 3 - - - 2 2 2 3 - 1.5

9
ARM Microcontroller

INTRODUCTION TO ARM CORTEX M3 PROCESSOR

The ARM Cortex-M3 is a general purpose 32-bit microprocessor, which offers high
performance and very low power consumption. The Cortex-M3 offers many new features,
including a Thumb- 2 instruction set, low interrupt latency, hardware divide,
interruptible / continuable multiple load and store instructions, automatic state save and restore for
interrupts, tightly integrated interrupt controller with Wake-up Interrupt Controller and multiple
core buses capable of simultaneous accesses. The processor has a Harvard architecture, which
means that it has a separate instruction bus and data bus. This allows instructions and data accesses
to take place at the same time, and as a result of this, the performance of the processor increases
because data accesses do not affect the instruction pipeline. This feature results in multiple bus
interfaces on Cortex-M3, each with optimized usage and the ability to be used simultaneously.
However, the instruction and data buses share the same memory space (a unified memory system).
In other words, you cannot get 8 GB of memory space just because you have separate bus
interfaces.

Figure 1: A Simplified View of the Cortex-M3

10
ARM Microcontroller

INTRODUCTION TO MICRO CONTROLLER LPC1768

The LPC1768FBD100 is an ARM Cortex-M3 based micro controller for embedded


applications requiring a high level of integration and low power dissipation. The ARM Cortex-M3
is a next generation core that offers system enhancements such as modernized debug features and a
higher level of support block integration. LPC1768 operate up to 100 MHz CPU frequency. The
peripheral complement of the LPC1768 includes up to 512 kilo bytes of flash memory, up to 64KB
of data memory, Ethernet MAC, a USB interface that can be configured as either Host, Device, or
OTG, 8 channel general purpose DMA controller, 4 UARTs, 2 CAN channels, 2 SSP controllers,
SPI interface, 3 I2C interfaces, 2-input plus 2- output I2S interface, 8 channel 12-bit ADC, 10-bit
DAC, motor control PWM, Quadrature Encoder interface, 4 general purpose timers, 6-output
general purpose PWM, ultra-low power RTC with separate battery supply, and up to 70 general
purpose I/O pins. The LPC1768 use a multi-layer AHB(Advanced High Performance Bus) matrix
to connect the ARM Cortex-M3 buses and other bus masters to peripherals in a flexible manner that
optimizes performance by allowing peripherals that are on different slaves ports of the matrix to be
accessed simultaneously by different bus masters.
On-chip flash memory system: The LPC1768 contains up to 512 KB of on-chip flash memory. A
flash memory accelerator maximizes performance for use with the two fast AHB Lite buses. This
memory may be used for both code and data storage. Programming of the flash memory may be
accomplished in several ways. It may be programmed In System via the serial port. The application
program may also erase and/or program the flash while the application is running, allowing a great
degree of flexibility for data storage field firmware upgrades, etc.
On-chip Static RAM: The LPC1768 contains up to 64 KB of on-chip static RAM memory. Up to
32 KB of SRAM, accessible by the CPU and all three DMA controllers are on a higher-speed bus.
Devices containing more than 32 KB SRAM have two additional 16 KB SRAM blocks, each
situated on separate slave ports on the AHB multilayer matrix. This architecture allows the
possibility for CPU and DMA accesses to be separated in such a way that there are few or no delays
for the bus masters.

SPECIFICATIONS OF ALS-SDA-ARMCTXM3-06

11
ARM Microcontroller

• LPC1768 is ARM Cortex M3 based microcontroller with 512KB flash memory and 64KB
SRAM In-System Programming (ISP) and InApplication Programming (IAP) capabilities.
• Single 3.3 V power supply (2.4 V to 3.6 V).
• 70 General Purpose I/O (GPIO) pins with configurable pull-up/down resistors, open drain
mode, and repeater mode.
• 12-bit Analog-to-Digital Converter (ADC) and up to 8 analog channels. 10-bit Digital-to-
Analog Converter (DAC) with dedicated conversion timer.
• Four general purpose timers/counters, with a total of eight capture inputs and ten
compare outputs.
• Four UART's with fractional baud rate generation, internal FIFO, IrDA.
• SPI controller with synchronous, serial, full duplex communication.
• Three enhanced I2C-bus interfaces
• Four reduced power modes: Sleep, Deep-sleep, Power-down, and Deep power down.
• Real-Time Clock (RTC) with a separate power domain.
• Standard JTAG test/debug interface as well as Serial Wire Debug.
• Four external interrupt inputs configurable as edge/level sensitive.
• 12MHz Crystal allows easy communication setup
• One on board voltage regulator for generating 3.3V. Input to this will be from
External +5V DC Power supply through a 9-pin DSUB connector
• Piggy Back module containing LPC1768 controller
• Standard JTAG connector with ARM 2×10 pin layout for programming /debugging with
ARM-JTAG
• Reset push-button for resetting the controller
• One RS232 interface circuit with 9 pin DSUB connector: this is used by the Boot
loader program, to program LPC1768 Flash memory without external Programmer
• DC motor interface with direction and speed control
• Stepper motor interface with direction and speed control
• 16×2 alphanumeric LCD Display
• On chip ADC interface circuit using AD0.5(P1.31)
• 8-bit DAC interface
• 4x4 Key-Matrix connected to the port lines of the controller
12
ARM Microcontroller

• One External interrupt circuit with LED indication


• Two-digit multiplexed 7-segment display interface
• Interface circuit for on board Buzzer, Relay and Led indication controlled through
push button.
• SPI Interface: 2 channel ADC IC with POT and Temperature sensor I2C Interface: NVROM
IC
• Standard 26-pin FRC connectors to connect to on-board interface or some of ALS
standard External Interfaces.
• A number of software examples in ‘C-language’ to illustrate the functioning of the
interfaces. The software examples are compiled using an evaluation version of KEIL4 ‘C’
compiler for ARM.
• Compact elegant plastic enclosure
• Optional USB to Serial interface (RS232) cable.

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.
Go to “Project” then to “New Project” and save it with a name in the Respective Project
folder, already you created.
• Select the device as “NXP (founded by Philips)” In that “LPC1768” then Press OK and then
press “YES” button to add “system_LPC17xx.s” file.
• Go to “File” In that “New” to open an editor window. Create your source file and use the
header file “LPC17xx.h” in the source file and save the file. Colour 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 Existing Files to Group
'Source Group 1' “add the file
–C: Keil4\ARM\startup\NXP\LPC17xx\system_LPC17xx.c

13
ARM Microcontroller

• Any changes made to this file at current project will directly change the source
system_LPC17xx.c file. So that other project settings may get altered. So it is
recommended to copy the file
• C: Keil(4)\ARM\startup\NXP\LPC17xx\system_LPC17xx.c to the project folder and add to
the source group. Important: This file should be added at each project creation.
• Then go to “Project” in that “Translate” to compile the File (s).
Go to “Project” in that “Build Target” for building all source files such as
“.C”,”.ASM”, “.h”, files, etc…This will create the hex file if no warnings & no errors.

Settings to be done in KEILUV4 for Executing C programs:


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

14
ARM Microcontroller

1. Write an ALP to multiply two 16 bit binary numbers.

AREA multiply, CODE, READONLY

ENTRY ;Mark first instruction to execute

EXPORT __main

__main
MOV r1,#6400 ; STORE FIRST NUMBER IN R0
MOV r2,#3200 ; STORE SECOND NUMBER IN R1
MUL r3,r1,r2 ; MULTIPLICATION

NOP
NOP
here: B here
END ;Mark end of file

RESULT:

INPUT:
R1 = 0X00001900
R2 = 0X00000C80

OUTPUT:
R3 = 0X01388000

15
ARM Microcontroller

2. Write an ALP to find the sum of first 10 integer numbers.

AREA sumten, CODE, READONLY

ENTRY ;Mark first instruction to execute

EXPORT __main

__main
MOV R1,#10 ; load 10 to regester
MOV R2,#0 ; empty the register to store result
loop
ADD R2,R2,R1 ; add the content of R1 with result at R2
;10+9+8+7+6+5+4+3+2+1+0
SUBS R1,#0x00 ; Decreament R1 by 1
BNE loop ; repeat till r1 goes 0

here: B here ; stop the program execution

END

RESULT:

INPUT:
R1 = 0X0000000A
R2 = 0X00000000

OUTPUT:
R2 = 0X00000037

16
ARM Microcontroller

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

AREA fact, CODE, READONLY

ENTRY ;Mark first instruction to execute

EXPORT __main

__main
MOV r0, #7 ; STORE FACTORIAL NUMBER IN R0
MOV r1,r0 ; MOVE THE SAME NUMBER IN R1

FACT SUBS r1, r1, #1 ; SUBTRACTION


CMP r1, #1 ; COMPARISON
BEQ STOP
MUL r3,r0,r1; ; MULTIPLICATION
MOV r0,r3 ; Result
BNE FACT ; BRANCH TO THE LOOP IF NOT EQUAL
STOP
NOP
NOP
NOP
HERE B HERE
END ;Mark end of file

RESULT:

INPUT:
R0 = 0X00000007
R1 = 0X00000000

OUTPUT:
R0 or R3 = 0X000013B0

17
ARM Microcontroller

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
ENTRY ;Mark first instruction to execute
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
NOP
NOP
NOP
here B here

MASK DCD 0X0000FFFF ; MASK MSB


VALUE1 DCW 0X1111,0X2222,0X3333,0XAAAA,0XBBBB,0XCCCC
; ARRAY OF16 BIT NUMBERS(N=6)

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


RESULT DCD 0X0
END ; Mark end of file

RESULT:
INPUT: Array of 16-bit number
VALUE1 => 0X1111, 0X2222, 0X3333, 0XAAAA, 0XBBBB, 0XCCCC
OUTPUT:
Internal RAM location
RESULT[0X10000004] = 0X97
RESULT[0X10000005] = 0X99
RESULT[0X10000006] = 0X02
RESULT[0X10000007] = 0X00

Note: Observe the output in R0 = 0x00029997

18
ARM Microcontroller

5. Write an ALP to add two 64 bit numbers.

AREA ADDITION64, CODE, READONLY


ENTRY ;Mark first instruction to execute
EXPORT __main
__main
LDR R0,=0X1234E640 ;LOAD THE FIRST VALUE IN R0,R1
LDR R1,=0X43210010
LDR R2,=0X12348900 ;LOAD THE SECOND VALUE IN R2,R3
LDR R3,=0X43212102
ADDS R4,R1,R3 ;RESULT IS STORED IN R4,R5
ADC R5,R0,R2

NOP
NOP
NOP
here B here
END ;Mark end of file

RESULT:

INPUT:
R0 = 0X1234E640
R1 = 0X43210010
R2 = 0X12348900
R3 = 0X43212102

OUTPUT:
R4 = 0X86422112
R5 = 0X24696F40

0X43210010 0X1234E640 NUM1

+ 0X43212102 0X12348900 NUM2

0X86422112 0X24696F40 SUM

19
ARM Microcontroller

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

AREA LARGEST, CODE, READONLY


ENTRY ;Mark first instruction to execute
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 ; USE BLS LOOP1 FOR SMALLEST NUMBER

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

NOP
NOP
NOP

;ARRAY OF 32 BIT NUMBERS(N=7)

VALUE1
DCD 0X44444444 ;
DCD 0X22222222 ;
DCD 0X11111111 ;
DCD 0X33333333 ;
DCD 0XAAAAAAAA ;
DCD 0X88888888 ;
DCD 0X99999999 ;

AREA DATA2,DATA,READWRITE ; TO STORE RESULT IN GIVENADDRESS


RESULT DCD 0X0

END ; Mark end of file

20
ARM Microcontroller

RESULT:

(a) Largest Number

INPUT: (Data stored in the memory specified by VALUE1)


VALUE1
DCD 0X44444444
DCD 0X22222222
DCD 0X11111111
DCD 0X33333333
DCD 0XAAAAAAAA
DCD 0X88888888
DCD 0X99999999

OUTPUT:
Largest number is stored in the internal RAM locations
RESULT[0X10000004] = 0XAA
RESULT[0X10000005] = 0XAA
RESULT[0X10000006] = 0XAA
RESULT[0X10000007] = 0XAA

Note: Observe the output in R2 = 0xAAAAAAAA

(b) Largest Number

INPUT: (Data stored in the memory specified by VALUE1)


VALUE1
DCD 0X44444444
DCD 0X22222222
DCD 0X11111111
DCD 0X33333333
DCD 0XAAAAAAAA
DCD 0X88888888
DCD 0X99999999

OUTPUT:
Smallest number is stored in the internal RAM locations
RESULT[0X10000004] = 0X11
RESULT[0X10000005] = 0X11
RESULT[0X10000006] = 0X11
RESULT[0X10000007] = 0X11

Note: Observe the output in R2 = 0x11111111

21
ARM Microcontroller

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

AREA LARGEST, CODE, READONLY


ENTRY ;Mark first instruction to execute
EXPORT __main
__main
MOV R8,#4 ;
;INTIALISE COUNTER TO 4(i.e. N=4)
LDR R2,=CVALUE ;
LDR R3,=DVALUE ; ADDRESS OF DATA REGION

LOOP0 LDR R1,[R2],#4; LOADING VALUES FROM CODE

REGION STR R1,[R3],#4 ; STORING VALUES TO DATA REGION

SUBS R8,R8,#1 ; DECREMENT COUNTER


CMP R8,#0 ; COMPARE COUNTER TO 0
BNE LOOP0 ; LOOP BACK TILL ARRAY ENDS

START1 MOV R5,#3 ; INTIALISE COUNTER TO 3(i.e. N=4)


MOV R7,#0 ; FLAG TO DENOTE EXCHANGE HAS OCCURED
LDR R1,=DVALUE ; LOADS THE ADDRESS OF FIRST VALUE

LOOP LDR R2,[R1],#4 ; WORD ALIGN T0 ARRAY ELEMENT


LDR R3,[R1] ; LOAD SECOND NUMBER
CMP R2,R3 ; COMPARE NUMBERS
;BGT LOOP2 ; FOR DESCENDING ORDER
BLT LOOP2 ; IF THE FIRST NUMBER IS < THEN GOTO LOOP2
STR R2,[R1],#-4 ; INTERCHANGE NUMBER R2 & R3
STR R3,[R1] ; INTERCHANGE NUMBER R2 & R3
MOV R7,#1 ; FLAG DENOTING EXCHANGE HAS TAKEN PLACE
ADD R1,#4 ; RESTORE THE PTR
LOOP2
SUBS R5,R5,#1 ; DECREMENT COUNTER
CMP R5,#0 ; COMPARE COUNTER TO 0
BNE LOOP ; LOOP BACK TILL ARRAY ENDS
CMP R7,#0 ; COMPARING FLAG
BNE START1 ; IF FLAG IS NOT ZERO THEN GO TO START1 LOOP
NOP
NOP
HERE B HERE

22
ARM Microcontroller

; ARRAY OF 32 BIT NUMBERS(N=4) IN CODE REGION

CVALUE
DCD 0X44444444 ;
DCD 0X11111111 ;
DCD 0X33333333 ;
DCD 0X22222222 ;

AREA DATA1,DATA,READWRITE ;
; ARRAY OF 32 BIT NUMBERS IN DATA REGION
DVALUE DCD 0X00000000 ;
END ; Mark end of file

RESULT:
a) Ascending Order:

INPUT: (Data stored in the memory specified by CVALUE)


CVALUE
DCD 0X44444444
DCD 0X11111111
DCD 0X33333333
DCD 0X22222222
OUTPUT:
DVALUE [0X10000004] = 0X11111111
DVALUE [0X10000005] = 0X22222222
DVALUE [0X10000006] = 0X33333333
DVALUE [0X10000007] = 0X44444444

b) Descending Order:

INPUT: (Data stored in the memory specified by CVALUE)


CVALUE
DCD 0X44444444
DCD 0X11111111
DCD 0X33333333
DCD 0X22222222
OUTPUT:
DVALUE [0X10000004] = 0X44444444
DVALUE [0X10000005] = 0X33333333
DVALUE [0X10000006] = 0X22222222
DVALUE [0X10000007] = 0X11111111

23
ARM Microcontroller

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

AREA LARGEST, CODE, READONLY

ENTRY ;Mark first instruction to execute


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
BNE LOOP ; IF NOT EQUAL GOTO TO LOOP

NOP
NOP
NOP
HERE B HERE

VALUE DCD 0X11111111,0XAA55AA55; TWO VALUES IN AN ARRAY

END ; Mark end of file

24
ARM Microcontroller

RESULT:

INPUT: (Data stored in the memory specified by VALUE)

VALUE DCD 0X11111111, 0XAA55AA55

OUTPUT:

R2 = 0X00000018 (Number of ONES)


R3 = 0X00000028 (Number of ZEROS)

25
ARM Microcontroller

ii) Write an ALP to Scan a series of 32 bit numbers to find how many are negative.

;/*ARRAY OF 7 NUMBERS
0X12345678,0X8D489867,0X11111111,0X33333333,0XAAAAAAAA */
;/*0XE605546C ,0X99999999 */
;/* RESULT CAN BE VIEWED IN R2 */

AREA LARGEST, CODE, READONLY


ENTRY ;Mark first instruction to execute
EXPORT __main
__main
MOV R5,#7 ; INTIALISE COUNTER TO 7(i.e. N=7)
MOV R2,#0 ; COUNTER
LDR R4,=VALUE ; LOADS THE ADDRESS OF FIRST VALUE

LOOP LDR R1,[R4],#4 ; WORD ALIGN T0 ARRAY ELEMENT


ANDS R1,R1,#1<<31 ; TO CHECK NEGATIVE NUMBER
BHI FOUND ; IF THE GIVEN NUMBER IS NEGATIVE GOTO FOUND
B LOOP1; IF THE GIVEN NUMBER IS NOT NEGATIVE GOTO LOOP1

FOUND ADD R2,R2,#1 ; INCREMENT THE COUNTER


(NEGATIVE NUMBER)
B LOOP1 ; GOTO LOOP1

LOOP1
SUBS R5,R5,#1 ; DECREMENT COUNTER
CMP R5,#0 ; COMPARE COUNTER TO 0
BNE LOOP ; LOOP BACK TILL ARRAY ENDS

NOP
HERE B HERE
;ARRAY OF 32 BIT NUMBERS(N=7)

VALUE
DCD 0X12345678 ;
DCD 0X8D489867 ;
DCD 0X11111111 ;
DCD 0X33333333 ;
DCD 0XE605546C ;
DCD0XAAAAAAAA;
DCD 0X99999999 ;

END ; Mark end of file

26
ARM Microcontroller

RESULT:

INPUT: (Data stored in the memory specified by VALUE)

VALUE
DCD 0X12345678
DCD 0X8D489867
DCD 0X11111111
DCD 0X33333333
DCD 0XE605546C
DCD 0XAAAAAAAA
DCD 0X99999999

OUTPUT:

R2 = 0X00000004 (Number of NEGATIVES)

27
ARM Microcontroller

PART-B

28
ARM Microcontroller

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

#include <LPC17xx.H>

void clock_wise(void);

void anti_clock_wise(void);

unsigned long int var1,var2;

unsigned int i=0,j=0,k=0;

int main(void)

LPC_PINCON->PINSEL4 = 0x00000000; //P2.0 to P2.3 GPIO

LPC_GPIO2->FIODIR = 0x0000000F; //P2.0 to P2.3 output

while(1)

{
for(j=0;j<50;j++) //50 times in Clock wise Rotation

clock_wise();

for(k=0;k<65000;k++); //Delay to show anti_clock Rotation

for(j=0;j<50;j++) //50 times in Anti Clock wise Rotation

anti_clock_wise();

for(k=0;k<65000;k++); //Delay to show clock Rotation

}
//End of while(1)

}
//End of main

void clock_wise(void)

var1 = 0x00000001; //For Clockwise

for(i=0;i<=3;i++) //for A B C D Stepping

29
ARM Microcontroller

LPC_GPIO2->FIOCLR = 0X0000000F;

LPC_GPIO2->FIOSET = var1;

var1 = var1<<1; //For Clockwise

for(k=0;k<15000;k++); //for step speed variation

void anti_clock_wise(void)

var1 = 0x0000008; //For Anticlockwise

for(i=0;i<=3;i++) //for A B C D Stepping


{

LPC_GPIO2->FIOCLR = 0X0000000F;

LPC_GPIO2->FIOSET = var1;

var1 = var1>>1; //For


Anticlockwise

for(k=0;k<15000;k++); //for step speed variation

30
ARM Microcontroller

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

Square Wave:

#include <LPC17xx.H>

void delay(void);

int main ()

LPC_PINCON->PINSEL0 &= 0xFF0000FF ;


// Configure P0.4 to P0.11 as GPIO

LPC_GPIO0->FIODIR |= 0x00000FF0 ;

LPC_GPIO0->FIOMASK = 0XFFFFF00F;

while(1)

LPC_GPIO0->FIOPIN = 0x00000FF0 ;

delay();

LPC_GPIO0->FIOCLR = 0x00000FF0 ;

delay();

void delay(void)

unsigned int i=0;

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

31
ARM Microcontroller

Triangular Wave:

#include <LPC17xx.H>

int main ()

unsigned long int temp=0x00000000;

unsigned int i=0;

LPC_PINCON->PINSEL0 &= 0xFF0000FF ; Configure P0.4 to P0.11 as GPIO

LPC_GPIO0->FIODIR |= 0x00000FF0 ;

LPC_GPIO0->FIOMASK = 0XFFFFF00F;

while(1)

for(i=0;i!=0xFF;i++)

temp=i;

temp = temp << 4;

LPC_GPIO0->FIOPIN = temp;

for(i=0xFF; i!=0;i--)

temp=i;

temp = temp << 4;

LPC_GPIO0->FIOPIN = temp;

}//End of while(1)

}//End of main()

32
ARM Microcontroller

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

#include <LPC17xx.h>

unsigned int delay, count=0, Switchcount=0,j;

unsigned int Disp[16]={0x000003f0, 0x00000060, 0x000005b0, 0x000004f0,


0x00000660,0x000006d0, 0x000007d0, 0x00000070, 0x000007f0, 0x000006f0,
0x00000770,0x000007c0, 0x00000390, 0x000005e0, 0x00000790, 0x00000710 };

#define ALLDISP 0x00180000


//Select all display

#define DATAPORT 0x00000ff0


//P0.4 to P0.11 : Data lines connected to drive Seven Segments

int main (void)


{

LPC_PINCON->PINSEL0 = 0x00000000;

LPC_PINCON->PINSEL1 = 0x00000000;

LPC_GPIO0->FIODIR = 0x00180ff0;

while(1)

LPC_GPIO0->FIOSET |= ALLDISP;

LPC_GPIO0->FIOCLR = 0x00000ff0;
// clear the data lines to 7-segment displays

LPC_GPIO0->FIOSET = Disp[Switchcount]; // get the 7-segment display value


from the array

for(j=0;j<3;j++)

for(delay=0;delay<30000;delay++);
// delay

Switchcount++;

if(Switchcount == 0x10)
// 0 to F has been displayed ? go back to 0
33
ARM Microcontroller

Switchcount = 0;

LPC_GPIO0->FIOCLR = 0x00180ff0;

34
ARM Microcontroller

12. Interface a simple Switch and display its status through Relay, Buzzer and LED.

#include <LPC17xx.H>

int main(void)

LPC_PINCON->PINSEL1 = 0x00000000;
//P0.24,P0.25 GPIO

LPC_GPIO0->FIODIR = 0x03000000;
//P0.24 configured output for buzzer,P0.25 configured output for Relay/Led

while(1)

if(!(LPC_GPIO2->FIOPIN & 0x00000800)) //Is


GP_SW(SW4) is pressed??

LPC_GPIO0->FIOSET = 0x03000000; //relay on

else

LPC_GPIO0->FIOCLR = 0x03000000; //relay off

}
//end

35

You might also like