ARM MANUAL(REV-24-25)
ARM MANUAL(REV-24-25)
An Autonomous Institution
Affiliated to VTU Belagavi, Recognised by AICTE New Delhi, Accredited by NAAC with A+ Grade
22ECE53
22ECE53
VISION
MISSION
Bloom’s Target
CO No. Course Outcomes (COs) Taxonomy Attainment
Level Level
1
Performance Indicators
4.3.3 Represent data (in tabular and/or graphical forms) so as to facilitate analysis
and explanation of the data, and drawing of conclusion
5.3.2 Verify the credibility of results from tool use with reference to the accuracy
and limitations, and the assumptions inherent in their use.
9.3.1 Present results as a team, with smooth integration of contributions from all
individual efforts
2
Lab Syllabus
● Part A
○ Data Transfer Programs
■ Block Move & Exchange
■ Sorting
■ Finding Largest element in an Array
○ Arithmetic operations
■ Addition & Subtraction
■ Multiplication & Division
○ Generating Delay for given duration
○ Counters
● Part B - Interface with TIVA C Kit
○ LED blink
○ Stepper Motor and DC Motor
○ Switch, Relay and Buzzer
○ DAC
Assessment
● Regular Lab (20) (Weekly)
○ Regular experiment (10)
○ Project Discussion (5)
○ Additional Experiment (5)
● Lab Test (20) (last week of semester)
○ Write up 5 marks
○ Conduction - 10 marks
○ Viva - 5 marks
● Lab record (10) (Weekly)
○ Rubrics
3
Mini Project List
Students need to select any one topic to execute (can use C or ASM or hybrid). Each Team will have
max of three members
Team Members
Sl.No USN Name
4
Software Procedure
Procedure For Developing Microcontroller ASM Program Using Keil µvision 5 IDE
Open Keil µvision 5. The screen will be opened as shown in figure. The screen has three major windows.
5
Project Window: It shows the source files and groups, register window, functions window and book
window.
Workspace or Editor Window: It shows all the opened source files, disassembly window and
performance information. Source codes are edited in this window.
Output Window: It shows the program- build progress information (assembling, linking or compiling,
errors and warnings.) It also shows the command, memory, call stack and local variable windows.
6
In this window, browse to the folder where you want to store all the project files, or create a new
folder. Type a desired project name in the File name box and Save it. µVision 5 automatically
assigns the extension. uvprojc to the project. It is advisable to use a separate folder for each
project.
7
8
1. Selecting a device (Microcontroller)
Whenever a new project is created, it is necessary to select a microcontroller (referred as target
device) for which the project is developed. The Select Device dialog box shows the µVision device
database. Select Texas Instruments -> TM4C123GH6PM
Change to
9
If you need startup Script, check the startup box as shown below
New Project file with startup files are created as shown below
Add a new file to the project for execution. To do that Right click on Source Group1 -> Add new item
to group ‘source Group 1’
10
Select the desired file type. Make sure to give filename and click add button
11
Type the below code in the text editor
Code Example:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Assembly language Syntax ;;;;;;;;;;
; label opcode operand ;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
AREA MYCODE,CODE, READONLY
ENTRY
EXPORT __main
__main
; MOV example (Note ';' is used to comment )
MOV R2,#0x123
MOV R4,#'A'
MOV R7, R3
; Addition example
ADD R1, #0x06
ADD R4,R2
ADD R6,R5,R3
ADDS R6,R5,R3
END
12
When using only simulation we need to disable the clock configuration. To do that, On Project window,
select system_TM4C123.C file, On the right hand side bottom you will have two tabs, Select the
Configuration Wizard and uncheck the Clock Configuration. Now save the file before Building the
target.
13
Build the Project:
No Error
14
Set the Target for Simulation: From Project menu select options for target “Target 1”
Select the Debug tab and make sure “use Simulator” button is selected
Click Ok
15
Debug:
From Debug menu select Start/Stop Debug Session
There are three windows. On the left you have registers, right you have code and disassembly code. On
bottom you have Command and Memory windows.
Since we have to access memory location from 0x40000000 to 0x400FFFFF for all our code, we need to
set the memory map for the simulator.
Select Debug -> Memory Map
16
.
Enter 0x40000000,0x400FFFFF as shown in figure below left. Make sure Read and Write boxes are
checked. Click Map range. You must see the Memory is mapped as highlighted below right figure
17
Now click on
18
Exit Debug:
Debug-> Start/Stop Debug Session
This completes the Basic setup and execution of ASM program. Similar procedure for C program also.
19
PART -A
EXPERIMENT 1
DATA TRANSFER: BLOCK MOVE, EXCHANGE, SORTING, FINDING
LARGEST ELEMENT OF AN ARRAY
Date: _ _ / _ _ / _ _
Write an ALP program to copy a block of data (array) from one location to another
Location.
Algorithm:
1. Initialise the Data Memory
2. Load the memory location to R1
3. Load the number of data to R2
4. Load the destination location to R3
5. Load the data from address of R1 to R4
6. Increment the R1 by 4 location
7. Store the Data of R4 to location pointed by R3
8. Increment R3 by 4
9. Check R2 is equal to zero, if so exit else go to step 5
20
Program:
Source SPACE 20
Destination SPACE 20
__main
LDR r1,=Source
LDR r2,[r1]
mov r6,#0x0
LDR r3,=Destination
Loop
add r6,#0x1
add r1,#0x4
LDR r5,[r1]
STR r5,[r3]
ADD r3,#0x4
CMP r2,r6
BGE Loop
Stop B Stop
ALIGN
END
21
Observation
Before Execution:
After Execution:
22
Additional Analysis:
23
Date: _ _ /__/__
Write an ALP program to exchange a block of data.
Algorithm:
1. Initialise the Data Memory
2. Load the memory location to R1
3. Load the number of data to R2
4. Load the destination location to R3
5. Load the data from address of R1 to R4
6. Load the data from location pointed by R3 to R5
7. Store the Data of R4 to location pointed by R3
8. Store the data of R5 to location pointed by R1
9. Increment the R1 by 4 location
10. Increment R3 by 4 location
11. Check R2 is equal to zero, if so exit else go to step 5
Program:
Label Instructions Comments
Source SPACE 25
Destination SPACE 4
__main
LDR r1,=Source
LDR r3,=Destination
LDR r2,[r1]
MOV r6,#0x1
Loop
ADD r1,#0x4
24
LDR r5,[r1]
LDR r7,[r3]
STR r5,[r3]
STR r7,[r1]
ADD r3,#0x4
ADD r6,#0x1
CMP r2,r6
BGE Loop
B Stop
Stop
Observation
Before Execution
After Execution
25
Additional Analysis
1. Rewrite the exchange of data programs such that the values from Data 2 locations are placed in
reverse order in data 1 location. While in data 2 location the exchange data are placed in order
with data 1 locations.
Example:
10 0A 0C 10
20 0B 0B 20
30 0C 0A 30
26
Date: _ _ / _ _ / _ _
27
swapdata
MOV R7,R5
MOV R5,R6
MOV R6,R7
B nextCycle
stop
B stop
ALIGN
END
Observation
Before Execution:
After Execution:
28
Additional Analysis
1. In the above program we stored the data in read only memory location. Try to change the code
such that the data are stored in RAM with Read and write permission. Note down the address of
count and array. Check the results for the same value and varying in count also.
29
Date: _ _ / _ _ / _ _
Program:
// Bubble sort program in C language
int main ()
{
int data[10] = {0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x80,0x01,0x02};
unsigned int i,j =0;
unsigned int temp = 0;
for(i = 0; i< 9; i++)
for (j=0;j<9;j++)
{
if(data[j]< data[j+1])
{
// Swap the data
temp = data[j];
data[j] = data[j+1];
data[j+1] = temp;
temp = 0;
}
}
30
Observation :
Kindly Note: Students need to identify the data stored in RAM at bottom right window “call Stack +
locals”
Before Execution:
After Execution:
31
Additional Analysis:
1. Write the assembly code for Bubble sort and verify with the same data provided in C code
32
EXPERIMENT 2
ARITHMETIC OPERATIONS ON TWO 32 BIT NUMBERS
Date: _ _ / _ _ / _ _
Program:
AREA MYCODE,CODE, READONLY
ENTRY
EXPORT __main
__main
MOV R2,#0x02
MOV R4,#0x05
ADD R6,R2,R4
SUB R7,R4,R2
SUB R8,R2,R4 ; Check the results
MUL R9,R2,R4 ; Multiply two numbers and stores only lower 32 bit values
33
Before Execution:
After Execution:
34
Additional Analysis:
1. Write the assembly code to check the overflow and negative flag changes using addition and
subtraction opcode only. . At Least need to take three cases to verify the result.
35
36
EXPERIMENT 3
DELAY AND COUNTERS
Date: _ _ / _ _ / _ _
Write an ALP to generate delay .
Algorithm:
1. Clear the Register R4,R5
2. Set R4 to 0x00
3. Load the delay Count value to R5
4. Decrement R5 till reaches zero
5. Set R4 to 0xFFFFFFFF
6. Load the delay Count value to R5
7. Decrement R5 till reaches zero
8. Go to Step 2
Program:
AREA |.data|, DATA, READONLY
37
dloop
SUBS R5,R5,#1
BNE dloop
ENDP ; End of Procedure
ALIGN
END
Observation:
Before Execution:
After Execution:
38
Date: _ _ / _ _ / _ _
Write an ALP to counter.
Algorithm:
1. Load the Count value to R5
2. Clear R4
3. Increment R4 till value reaches R5
4. Stop the program
Program:
AREA |.data|, DATA, READONLY
counts DCD 8
ALIGN
AREA MYCODE,CODE, READONLY
ENTRY
EXPORT __main
__main
LDR R6,=counts
LDR R5,[R6]
MOV R4,#0x00
iloop
ADD R4,#1
CMP R4,R5
BLT iloop
ALIGN
END
39
Observation:
Before Execution:
After Execution:
40
Additional Analysis:
1. Write the assembly program such that the Counter values stored in R4 should increment by 1 for
every delay of 10 cycles.
41
PART-B
EXPERIMENT 4
LED BLINK
Date: _ _ / _ _ / _ _
Program in ASM:
THUMB
AREA Constdata, DATA, READONLY
42
LDR R1,=GPIO_PORTF_DEN_R
LDR R0,[R1]
ORR R0,R0,#GPIO_PORTF_PIN3
STR R0,[R1]
LDR R1,=GPIO_PORTF_DATA_R
LED_FLASH
LDR R0,[R1]
EOR R0,R0,#GPIO_PORTF_PIN3
STR R0,[R1]
; DELAY
LDR R5,=DELAY_VALUE
DELAY
SUBS R5,#1
BNE DELAY
B LED_FLASH
ALIGN
END
Program in C:
#define SYSCTL_RCGC2_R *((volatile unsigned long *)0x400FE108)
#define SYSCTL_RCGC2_GPIOF 0x020
#define GPIO_PORTF_DATA_R *((volatile unsigned long *)0x400253FC) // 0x40025020
#define GPIO_PORTF_DIR_R *((volatile unsigned long *)0x40025400)
#define GPIO_PORTF_DEN_R *((volatile unsigned long *)0x4002551C)
43
unsigned int long j=0;
int main()
{
SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOF;
GPIO_PORTF_DEN_R |= GPIO_PORTF_PIN3;
GPIO_PORTF_DIR_R |= GPIO_PORTF_PIN3;
while(1)
{
GPIO_PORTF_DATA_R ^= GPIO_PORTF_PIN3;
for(j=0;j< DELAY_VALUE; j++);
}
}
Inference :
44
EXPERIMENT 5
STEPPER MOTOR
Date: _ _ / _ _ / _ _
Program:
/*During simulation ensure Read and write permission is provided for GPIO location
GPIO is located at 0x40000000,0x400FFFFF
*/
#include "TM4C123.h"
#define portdSelect 0x08
#define pins 0x0F
#define clockFreq 16000000
#define DelayValue clockFreq/80
unsigned int j =0;
void delay(){
for(j=0;j<DelayValue;j++);
// delay function
}
void setupInit(){
// set the Port D as GPIO enable
SYSCTL->RCGC2 |= portdSelect;
GPIOD->DEN |= 0x0F; // enable pin PD0,1,2,3
GPIOD->DIR |= 0x0F; // set all the pins as output pins, (0 -> i/p, 1->o/p)
}
int main()
{
setupInit();
while(1)
{ delay();
GPIOD->DATA = 0x04;
delay();
45
GPIOD->DATA = 0x08;
delay();
GPIOD->DATA = 0x01;
delay();
GPIOD->DATA = 0x02;
}
}
Inference:
46
EXPERIMENT 6
SWITCH, LED & BUZZER
Date: _ _ / _ _ / _ _
Program:
#include "TM4C123.h"
/*During simulation ensure Read and write permission is provided for GPIO location
GPIO is located at 0x40000000,0x400FFFFF*/
/*The PF1 Red LED will blink upon press of switch connected to PF0
PF1 -> Output; DEN->1; DIR -> 1
PF0 -> Input; DEN->1; DIR -> 0*/
unsigned int j = 0;
void delay()
{
for(j=0;j<delayValue;j++);
}
void GPIOsetup()
{
SYSCTL->RCGC2 |= 0x20; // set for port f
GPIOF->DEN |= 0x03;
GPIOF->DIR |= 0x02;
GPIOF->LOCK = 0x4C4F434B; // unlockGPIOCR register
GPIOF->CR = 0x01; // Enable GPIO PUR register enable to commit
GPIOF->PUR |= 0x01; // Enable Pull Up resistor PF0
}
47
int main()
{
uint8_t sw = 0; // 8 bit storage
GPIOsetup();
delay(); // delay
while(1)
{
// Logic goes here
sw = GPIOF->DATA & 0x01; // Check the value at pin0
if(sw)
{
GPIOF->DATA ^= 0x02;
delay();
}
else
{
GPIOF->DATA &= 0xFFFFFFFE;
}
}
}
Inference :
48
Mini Project Discussion and Implementation Week Wise plan
Week No To Complete
3 Working on block
4 Testing of blocks
49
Week 1
Discussion Topic Discussion
Faculty Observation
50
Week 2
Discussion Topic Discussion
Faculty Observation
51
Week 3
Discussion Topic Discussion
Faculty Observation
52
Week 4
Discussion Topic Discussion
Faculty Observation
53
Week 5
Discussion Topic Discussion
Faculty Observation
54
Week 6
Discussion Topic Discussion
Faculty Observation
55
Week 7
Discussion Topic Discussion
Faculty Observation
56
Week 8
Discussion Topic Discussion
Faculty Observation
57
Week 9
Discussion Topic Discussion
Faculty Observation
58
Week 10
Discussion Topic Discussion
Faculty Observation
59
Annexure A
Description of Kit
60
Pinout Details
61
Port Details
62
63