Professional Documents
Culture Documents
ARM - Lab - Manual
ARM - Lab - Manual
ARM - Lab - Manual
1
lOMoAR cPSD| 30134443
2
lOMoAR cPSD| 30134443
Program Outcomes
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.
PO8: Ethics: Apply ethical principles and commit to professional ethics and
responsibilities and norms of the engineering practice.
3
lOMoAR cPSD| 30134443
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
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
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.
10
ARM Microcontroller
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
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.
14
ARM Microcontroller
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
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
END
RESULT:
INPUT:
R1 = 0X0000000A
R2 = 0X00000000
OUTPUT:
R2 = 0X00000037
16
ARM Microcontroller
EXPORT __main
__main
MOV r0, #7 ; STORE FACTORIAL NUMBER IN R0
MOV r1,r0 ; MOVE THE SAME NUMBER IN R1
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
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
18
ARM Microcontroller
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
19
ARM Microcontroller
NOP
NOP
NOP
VALUE1
DCD 0X44444444 ;
DCD 0X22222222 ;
DCD 0X11111111 ;
DCD 0X33333333 ;
DCD 0XAAAAAAAA ;
DCD 0X88888888 ;
DCD 0X99999999 ;
20
ARM Microcontroller
RESULT:
OUTPUT:
Largest number is stored in the internal RAM locations
RESULT[0X10000004] = 0XAA
RESULT[0X10000005] = 0XAA
RESULT[0X10000006] = 0XAA
RESULT[0X10000007] = 0XAA
OUTPUT:
Smallest number is stored in the internal RAM locations
RESULT[0X10000004] = 0X11
RESULT[0X10000005] = 0X11
RESULT[0X10000006] = 0X11
RESULT[0X10000007] = 0X11
21
ARM Microcontroller
22
ARM Microcontroller
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:
b) Descending Order:
23
ARM Microcontroller
8. (i) Write an ALP to count the number of ones and zeros in two consecutive memory
locations.
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)
NOP
NOP
NOP
HERE B HERE
24
ARM Microcontroller
RESULT:
OUTPUT:
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 */
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 ;
26
ARM Microcontroller
RESULT:
VALUE
DCD 0X12345678
DCD 0X8D489867
DCD 0X11111111
DCD 0X33333333
DCD 0XE605546C
DCD 0XAAAAAAAA
DCD 0X99999999
OUTPUT:
27
ARM Microcontroller
PART-B
28
ARM Microcontroller
#include <LPC17xx.H>
void clock_wise(void);
void anti_clock_wise(void);
int main(void)
while(1)
{
for(j=0;j<50;j++) //50 times in Clock wise Rotation
clock_wise();
anti_clock_wise();
}
//End of while(1)
}
//End of main
void clock_wise(void)
29
ARM Microcontroller
LPC_GPIO2->FIOCLR = 0X0000000F;
LPC_GPIO2->FIOSET = var1;
void anti_clock_wise(void)
LPC_GPIO2->FIOCLR = 0X0000000F;
LPC_GPIO2->FIOSET = var1;
30
ARM Microcontroller
Square Wave:
#include <LPC17xx.H>
void delay(void);
int main ()
LPC_GPIO0->FIODIR |= 0x00000FF0 ;
LPC_GPIO0->FIOMASK = 0XFFFFF00F;
while(1)
LPC_GPIO0->FIOPIN = 0x00000FF0 ;
delay();
LPC_GPIO0->FIOCLR = 0x00000FF0 ;
delay();
void delay(void)
for(i=0;i<=9500;i++);
31
ARM Microcontroller
Triangular Wave:
#include <LPC17xx.H>
int main ()
LPC_GPIO0->FIODIR |= 0x00000FF0 ;
LPC_GPIO0->FIOMASK = 0XFFFFF00F;
while(1)
for(i=0;i!=0xFF;i++)
temp=i;
LPC_GPIO0->FIOPIN = temp;
for(i=0xFF; i!=0;i--)
temp=i;
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>
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
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)
else
}
//end
35