100% found this document useful (1 vote)
471 views

21EC52 - ARM Microcontrollers LAB - Programs

The document describes a laboratory manual for a Computer Organization and ARM Microcontrollers course. It contains details about the course, teaching methodology, assessment criteria, and a list of experiments to be conducted using ARM assembly language programs. The experiments include tasks like multiplying numbers, adding numbers, finding sums, factorials, and interfacing with hardware.

Uploaded by

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

21EC52 - ARM Microcontrollers LAB - Programs

The document describes a laboratory manual for a Computer Organization and ARM Microcontrollers course. It contains details about the course, teaching methodology, assessment criteria, and a list of experiments to be conducted using ARM assembly language programs. The experiments include tasks like multiplying numbers, adding numbers, finding sums, factorials, and interfacing with hardware.

Uploaded by

shanavi2004
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/ 30

Visvesvaraya Technological University

Belagavi, Karnataka-590 018

Computer Organization & ARM Microcontrollers


Laboratory Manual
(21EC52)
for
V Semester
Bachelor of Engineering

Department of Electronics and Communication Engineering


SDM Institute of Technology, Ujire-574240
Computer Organization & ARM Microcontrollers LAB
B.E: Electronics & Communication Engineering / B.E: Electronics & Telecommunication
Engineering
NEP, Outcome Based Education (OBE) and Choice Based Credit System (CBCS)
(Effective from the academic year 2021 – 22)
V Semester
Course Code 21EC52 CIE Marks 50
Teaching Hours/Week (3:0:2:0) SEE Marks 50
(L: T: P: S)
Total Hours of Pedagogy 40 hours Theory + 13 Lab slots Total Marks 100
Credits 4 Exam Hours 03

PRACTICAL COMPONENT OF IPCC


Conduct the following experiments by writing Assembly Language Program (ALP) using
ARM Cortex M3 Registers using an evaluation board/simulator and the required software
tool.

Sl. No. Experiments


1 Write an ALP to i) multiply two 16-bit binary numbers. ii) add two 64-bit numbers.
2 Write an ALP to find the sum of first 10 integer numbers.
3 Write an ALP to find factorial of a number.
Write an ALP to add an array of 16-bit numbers and store the 32-bit result in internal
4
RAM.
5 Write an ALP to find the square of a number (1 to 10) using look-up table.
6 Write an ALP to find the largest/smallest number in an array of 32 numbers.
7 Write an ALP to arrange a series of 32-bit numbers in ascending/descending order.
i) Write an ALP to count the number of ones and zeros in two consecutive memory
8 locations.
ii)Write an ALP to Scan a series of 32-bit numbers to find how many are negative

Demonstration Experiments (For CIE only not for SEE)


Conduct the following experiments on an ARM CORTEX M3 evaluation board using
evaluation version of Embedded 'C' & Keil μvision-4 tool/compiler.

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


10 Interface a DAC and generate Triangular and Square waveforms.
Display the Hex digits 0 to F on a 7-segment LED interface, with a suitable delay in
11
between.
12 Interface a simple Switch and display its status through Relay, Buzzer and LED.
Teaching-Learning Process (General Instructions)
These are sample Strategies, which teacher can use to accelerate the attainment of the various
course outcomes.
• Lecture method (L) does not mean only traditional lecture method, but different type of
teaching methods may be adopted to develop the outcomes.
• Encourage collaborative (Group) Learning in the class.
• Ask at least three HOTS (Higher order Thinking) questions in the class, which promotes
critical thinking.
• Adopt Problem Based Learning (PBL), which fosters students‟ Analytical skills, develop
thinking skills such as the ability to evaluate, generalize, and analyze information rather than
simply recall it.
• Show the different ways to solve the same problem and encourage the students to come up
with their own creative ways to solve them.
• Discuss how every concept can be applied to the real world - and when that's possible, it
helps improve the students' understanding.
• Give Programming Assignments.

Assessment Details (both CIE and SEE)


The weightage of Continuous Internal Evaluation (CIE) is 50% and for Semester End Exam
(SEE) is 50%. The minimum passing mark for the CIE is 40% of the maximum marks (20
marks). A student shall be deemed to have satisfied the academic requirements and earned
the credits allotted to each subject/course if the student secures not less than 35% (18 Marks
out of 50) in the semester-end examination (SEE), and a minimum of 40% (40 marks out of
100) in the sum total of the CIE (Continuous Internal Evaluation) and SEE (Semester End
Examination) taken together
CIE for the theory component of IPCC
Two Tests each of 20 Marks (duration 01 hour)
• First test at the end of 5th week of the semester
• Second test at the end of the 10th week of the semester
Two assignments each of 10 Marks
• First assignment at the end of 4th week of the semester
• Second assignment at the end of 9th week of the semester
Scaled-down marks of two tests and two assignments added will be CIE marks for the theory
component of IPCC for 30 marks.
CIE for the practical component of IPCC
• On completion of every experiment/program in the laboratory, the students shall be
evaluated and marks shall be awarded on the same day. The 15 marks are for conducting the
experiment and preparation of the laboratory record, the other 05 marks shall be for the test
conducted at the end of the semester.
• The CIE marks awarded in the case of the Practical component shall be based on the
continuous evaluation of the laboratory report. Each experiment report can be evaluated for
10 marks. Marks of all experiments‟ write-ups are added and scaled down to 15 marks.
• The laboratory test (duration 03 hours) at the end of the 15th week of the semester /after
completion of all the experiments (whichever is early) shall be conducted for 50 marks and
scaled down to 05 marks.
Scaled-down marks of write-up evaluations and tests added will be CIE marks for the
laboratory component of IPCC for 20 marks.

SEE for IPCC


Theory SEE will be conducted by University as per the scheduled timetable, with common
question papers for the course (duration 03 hours)
• The question paper will have ten questions. Each question is set for 20 marks.
• There will be 2 questions from each module. Each of the two questions under a module
(with a maximum of 3 sub-questions), should have a mix of topics under that module.
• The students have to answer 5 full questions, selecting one full question from each module.
The theory portion of the IPCC shall be for both CIE and SEE, whereas the practical
portion will have a CIE component only. Questions mentioned in the SEE paper shall
include questions from the practical component.
• The minimum marks to be secured in CIE to appear for SEE shall be the 12 (40% of
maximum marks-30) in the theory component and 08 (40% of maximum marks -20) in the
practical component. The laboratory component of the IPCC shall be for CIE only. However,
in SEE, the questions from the laboratory component shall be included. The maximum of
04/05 questions to be set from the practical component of IPCC, the total marks of all
questions should not be more than the 20 marks.
SEE will be conducted for 100 marks and students shall secure 35% of the maximum marks
to qualify in the SEE. Marks secured will be scaled down to 50.
PRACTICAL COMPONENT OF IPCC
Conduct the following experiments by writing Assembly Language Program (ALP) using
ARM Cortex M3 Registers using an evaluation board/simulator and the required software
tool.
1. a) Write an ALP to multiply two 16-bit binary numbers.

;/* VALUE1: 1900H (6400) (IN R1) */


;/* VALUE2: 0C80H(3200) (IN R2) */
;/* RESULT: 1388000H(20480000)(IN R3)*/

AREA multiply, CODE, READONLY


ENTRY ; Mark first instruction to execute
EXPORT __START
__START
MOV R1,#6400 ; STORE FIRST NUMBER IN R0
MOV R2,#3200 ; STORE SECOND NUMBER IN R1
MUL R3,R1,R2 ; MULTIPLICATION
NOP
NOP
END ; Mark end of file
1. b) Write an ALP to add two 64-bit numbers.

;/* VALUE1 0X1234E640 0X43210010 (R0,R1)*/


;/* VALUE2 0X12348900 0X43212102 (R2,R3)*/
;/* RESULT 0X24696F40 0X86422112 (R5,R4)*/

AREA ADDITION , CODE, READONLY


ENTRY ;Mark first instruction to execute
EXPORT __START
__START
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
END ;Mark end of file
2. ALP to find the sum of first 10 integer numbers.

AREA SUM, CODE, READONLY


ENTRY ; Mark 1st Instruction to execute
EXPORT __START
__START
MOV R2, #0 ; Initialize R2 with 0
MOV R3, #10 ; Initialize R3 with 10
MOV R0, #0 ; Initialize R0 with 0
MOV R1, #1 ; Initialize R1 with 1
LOOP ADD R0, R0, R1 ; Add R0 with R1 and store sum in R0
ADD R1, R1, #1 ; Increment the number by 1
CMP R1, R3 ; Compare incremented value with 10 in R3
BNE LOOP ; If it’s not equal then loop
LDR R4, =SUM1; If yes, get address of SUM1 pointed by R4
STR R0, [R4] : Store sum in Location SUM1
STOP B STOP

AREA DATA1, DATA, READWRITE


SUM1 DCD 0X0
END
3. Write an ALP to find factorial of a number.

AREA FACT1, CODE, READONLY


EXPORT __START
__START
MOV R0, #7 ; Copy 7 into register R0 (number for
;finding factorial)
MOV R1, #1 ; Initialize 1 in register R1
LOOP MUL R2, R1, R0 ; Multiply R0 with R1 and store
;result in R2
MOV R1, R2 ; Copy R2 into R1
SUBS R0, R0, #1 ; Decrement number in R0 by 1
BNE LOOP ; Is number==0? If no goto label loop
LDR R3, =FACT ; Get the address of FACT in register R3
STR R2, [R3] ; Store the factorial of number from R2 to
;FACT memory location
STOP B STOP

AREA DATA1, DATA, READWRITE


FACT DCD 0x0
END
4. Write an ALP to add an array of 16-bit numbers and store the 32-bit
result in internal RAM.

;/*ARRAY OF 6 NUMBERS 0X1111, 0X2222, 0X3333, 0XAAAA, 0XBBBB,


0XCCCC*/

;/* THE SUM IS 29997H THE RESULT CAN BE VIEWED IN LOCATION


0X10000000 & ALSO IN R0 */

AREA ADDITION, CODE, READONLY


ENTRY ;Mark first instruction to execute
EXPORT __START
__START
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
NOP
NOP
NOP
STOP B STOP
MASK DCD 0X0000FFFF ; MASK MSB
VALUE1 DCW 0X1111, 0X2222, 0X3333, 0XAAAA, 0XBBBB, 0XCCCC
; ARRAY OF 16 BIT NUMBERS(N=6)
AREA DATA2,DATA,READWRITE ; TO STORE RESULT IN GIVEN
;ADDRESS
RESULT DCD 0X0
END ; Mark end of file
5. Write an ALP to find the square of a number (1 to 10) using look-up
table.

AREA SQUARE, CODE, READONLY


ENTRY ; Mark 1st Instruction to execute
EXPORT __START
__START
LDR R0,LOOKUP ; Get the data LOOKUP(address) in reg R0
LDR R2, RESULT ; Get the data RESULT(address) in reg R2
LDRB R1,[R0]; Load the data byte(8-bit) to reg R1
ADD R0,R0,R1; Add R0, R1 reg contents and store in R0
LDRB R3,[R0]; Get the content of R0 in register R3
STRB R3,[R2]; Store DATA(SQ of no.) in Location RESULT
STOP B STOP
LOOKUP DCD 0X10000000
RESULT DCD 0X10000010
END
6. Write an ALP to find the largest/smallest number in an array of 32
numbers.
;/*ARRAY OF 7 NUMBERS 0X44444444 ,0X22222222, 0X11111111,
0X33333333, 0XAAAAAAAA, 0X88888888 ,0X99999999 */
/* RESULT CAN BE VIEWED IN LOCATION 0X10000000 & ALSO IN R2 */

AREA LARGEST, CODE, READONLY


ENTRY ;Mark first instruction to execute
EXPORT __START
__START
MOV R5,#6 ; INTIALISE COUNTER TO 6(i.e. N=7)
LDR R1,=VALUE ; LOADS THE ADDRESS OF FIRST VALUE
LDR R2,[R1],#4 ; WORD ALIGN T0 ARRAY ELEMENT
LOOP LDR R4,[R1],#4 ; WORD ALIGN T0 ARRAY ELEMENT
CMP R2,R4 ; COMPARE NUMBERS
BHI LOOP1 ; IF THE FIRST NUMBER IS > THEN GOTO LOOP1
MOV R2,R4 ; IF THE FIRST NUMBER IS < THEN MOV CONTENT R4
;TO R2
LOOP1 SUBS R5,R5,#1 ; DECREMENT COUNTER
CMP R5,#0 ; COMPARE COUNTER TO 0
BNE LOOP ; LOOP BACK TILL ARRAY ENDS
LDR R4,=RESULT ; LOADS THE ADDRESS OF RESULT
STR R2,[R4] ; STORES THE RESULT
NOP
NOP
NOP
;ARRAY OF 32 BIT NUMBERS(N=7)
VALUE DCD 0X44444444, 0X22222222, 0X11111111, 0X33333333,
0XAAAAAAAA, 0X88888888, 0X99999999

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


;ADDRESS
RESULT DCD 0X0
END ; Mark end of file
Note: In place of BHI use BLS to find smallest number in an array
7. Write an ALP to arrange a series of 32-bit numbers in
ascending/descending order.

;/*ARRAY OF 4 NUMBERS 0X44444444 , 0X11111111, 0X33333333,


0X22222222 */
;/* RESULT CAN BE VIEWED AT LOCATION 0X10000000 */

AREA ASCENDING , CODE, READONLY


ENTRY ;Mark first instruction to execute
EXPORT __START
__START
MOV R8,#4 ; INTIALISE COUNTER TO 4(i.e. N=4)
LDR R2,=CVALUE ; ADDRESS OF CODE REGION
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
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
NOP
; ARRAY OF 32 BIT NUMBERS(N=4) IN CODE REGION
CVALUE DCD 0X44444444, 0X11111111, 0X33333333,0X22222222

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

Note: In place of BLT use BGT to sort in descending order


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

;/*TAKE TWO NUMBERS i.e. 0X11111111,0XAA55AA55 (R0) */


;/*CHECK THE RESULT IN R2 FOR ONES & R3 FOR ZEROS */

AREA ONEZERO , CODE, READONLY


ENTRY ;Mark first instruction to execute
EXPORT __START
__START
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
VALUE DCD 0X11111111, 0XAA55AA55; TWO VALUES IN AN ARRAY
END ; Mark end of file
8. b) 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 NEGATIVE , CODE, READONLY


ENTRY ;Mark first instruction to execute
EXPORT __START
__START
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
NOP
;ARRAY OF 32 BIT NUMBERS(N=7)
VALUE DCD 0X12345678, 0X8D489867, 0X11111111, 0X33333333,
0XE605546C, 0XAAAAAAAA, 0X99999999 ;
END ; Mark end of file
Demonstration Experiments (For CIE only not for SEE)
Conduct the following experiments on an ARM CORTEX M3 evaluation board using
evaluation version of Embedded 'C' & Keil μvision-4 tool/compiler.

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


direction.
Aim: to Interface a Stepper motor and rotate it in clockwise and anti-clockwise direction with
an ARM CORTEX M3 evaluation board using evaluation version of Embedded 'C' & Keil
uVision- tool.

Stepper motor:
A stepper motor or step motor or stepping motor is a brushless DC electric motor that divides
a full rotation into a number of equal steps. The motor's position can then be commanded to
move and hold at one of these steps without any position sensor for feedback (an open-loop
controller), as long as the motor is carefully sized to the application in respect to torque and
speed.

Unlike a brushless DC motor which rotates continuously when a fixed DC voltage is applied
to it, a step motor rotates in discrete step angles. The Stepper Motors therefore are
manufactured with steps per revolution of 12, 24, 72, 144, 180, and 200, resulting in stepping
angles of 30, 15, 5, 2.5, 2, and 1.8 degrees per step. The stepper motor can be controlled with
or without feedback.
How a stepper motor works?
Stepper motors work on the principle of electromagnetism. There is a soft iron or magnetic
rotor shaft surrounded by the electromagnetic stators. The rotor and stator have poles which
may be teethed or not depending upon the type of stepper. When the stators are energized the
rotor moves to align itself along with the stator (in case of a permanent magnet type stepper)
or moves to have a minimum gap with the stator (in case of a variable reluctance stepper).
This way the stators are energized in a sequence to rotate the stepper motor. Get more
information about working of stepper motors through interesting images at the stepper motor
Insight.
Stepper motors consist of a permanent magnetic rotating shaft, called the rotor, and
electromagnets on the stationary portion that surrounds the motor, called the stator. Figure 1
illustrates one complete rotation of a stepper motor. At position 1, we can see that the rotor is
beginning at the upper electromagnet, which is currently active (has voltage applied to it). To
move the rotor clockwise (CW), the upper electromagnet is deactivated and the right
electromagnet is activated, causing the rotor to move 90 degrees CW, aligning itself with the
active magnet. This process is repeated in the same manner at the south and west
electromagnets until we once again reach the starting position.

Figure 1
In the above example, we used a motor with a resolution of 90 degrees for demonstration
purposes. In reality, this would not be a very practical motor for most applications. The
average stepper motor's resolution (the amount of degrees rotated per pulse) is much higher
than this. For example, a motor with a resolution of 1.8 degrees would move its rotor 1.8
degrees per step, thereby requiring 200 pulses (steps) to complete a full 360 degree rotation.
Here we are using 200 pole stepper motor hence it gives 360degree/200 pole=1.8 degree per
step.
So for example if we need 120 degree rotation then we have to apply approximately 67
pulses to complete 120 degree rotation.
120/1.8=66.66==67 steps approximately.
So if we need 90 degree rotation then 90/1.8=50 steps. Here one cycle means 4 steps. So
50/4=12.5 =~ 13. So we need 13 cycles to rotate 90 degree. If we want to run 180 degree then
180/1.8=100. So 100/4=25 cycles would make a stepper motor to rotate 180 degree.

Stepper Motor Interface


Program:

#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 Clockwise Rotation


clock_wise();

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

for(j=0;j<50;j++) //50 times in Anti Clockwise 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
{
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 = 0x00000008; //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
}

Result: A Stepper motor was interfaced with an ARM CORTEX M3 evaluation board and was
rotated in clockwise and anti-clockwise direction.

Viva Questions:

1. Explain the working of Stepper Motor.


2. How do you configure the PINSEL Address?
3. How many PINSEL does AMR CORTEX M3 has?
4. How many PORT‟s does AMR CORTEX M3 has?
5. How to calculate the step size for Stepper Motor.
10.Interface a DAC and generate Triangular and Square waveforms.
Aim: to Interface a DAC and generate Triangular and Square waveforms with an ARM
CORTEX M3 evaluation board using evaluation version of Embedded 'C' & Keil uVision-4
tool.

DAC0800:
DAC0800 is used to convert the digital data into analog signals. Digital data from specified port
lines is given to DAC input. Amplitude of output waveform can be varied by varying POT3 (5K)
that is by varying the reference voltage of DAC0800. JP11 (1,2) closed output is uni-polar and
JP11(1,2) open output is bi-polar. Port lines used for DAC are P0.4 – P0.11. Connect FRC cable
from CN7 to CN8 to use this block.

DAC Interface

Program: (Triangular Wave)


Description: This example explains about how Triangular Wave is generated. P0.4 to
P0.11 are used to get the Digital values.
#include <LPC17xx.H>
int main ()
{
unsigned long int temp=0x00000000;
unsigned int i=0;

LPC_PINCON->PINSEL0 = 0x00000000; /* Configure P0.4 to


P0.11 as GPIO */
LPC_GPIO0->FIODIR = 0x00000FF0;
// LPC_GPIO0->FIOMASK = 0xFFFFF00F;

while(1)
{
for(i=0;i!=0xFF;i++) //output 0 to FE

{
temp=i;
temp = temp << 4;
LPC_GPIO0->FIOPIN = temp;
}

for(i=0xFF; i!=0;i--) // output FF to 1

{
temp=i;
temp = temp << 4;
LPC_GPIO0->FIOPIN = temp;
}
}

Program: (Square Wave)


Description: This example explains about how Square Wave is generated. P0.4 to P0.11
are used to get the Digital values.
#include <LPC17xx.H>
void delay(void);
int main ()
{
LPC_PINCON->PINSEL0 = 0x00000000; /* Configure P0.4 to
P0.11 as GPIO */
LPC_GPIO0->FIODIR = 0x00000FF0;
while(1)
{
LPC_GPIO0->FIOSET = 0x00000FF0;
delay();
LPC_GPIO0->FIOCLR = 0x00000FF0;
delay();2
}
}

void delay(void)
{
unsigned int i=0;
for(i=0;i<=9500;i++);
}

Result: A DAC was interfaced with an ARM CORTEX M3 evaluation board; Triangular and
Square waveforms were generated using DAC0800.

Viva Questions:

1. Explain FIOSET Keyword


2. Explain FIOCLR keyword
3. Explain FIOMASK Keyword
4. How to calculate PINSEL for Square wave generation.
11.Display the Hex digits 0 to F on a 7-segment LED interface, with a
suitable delay in between.
Aim: To display the Hex digits 0 to F on a 7-segment LED interface, with an appropriate
delay in between. on an ARM CORTEX M3 evaluation board using evaluation version of
Embedded 'C' & Keil uVision-4 tool.
Seven Segment Display Symbol:

Block Diagram:

There are two multiplexed 7-segment display units (U8, U9) 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 enable of all the segments are pulled up. A two bits input through SW5 is used
for multiplexing operation. A high level on these lines enables the corresponding display.
Connection of these enable lines are shown below.

CN8 pin 17 → SW5 pin 1 → EN1 (U8)


CN8 pin 18 → SW5 pin 2 → EN2 (U9)
CN8 pin 13 → SEG A
CN8 pin 14 → SEG B
CN8 pin 11 → SEG C
CN8 pin 12 → SEG D
CN8 pin 9 → SEG E
CN8 pin 10 → SEG F
CN8 pin 7 → SEG G
CN8 pin 8 → Decimal points

The Common Cathode (CC) – In the common cathode display, all the cathode connections
of the LED segments are joined together to logic “0” or ground. The individual segments are
illuminated by application of a “HIGH”, or logic “1” signal via a current limiting resistor to
forward bias the individual Anode terminals (a-g).
The Common Anode (CA) – In the common anode display, all the anode connections of the
LED segments are joined together to logic “1”. The individual segments are illuminated by
applying a ground, logic “0” or “LOW” signal via a suitable current limiting resistor to the
Cathode of the particular segment (a-g).
Table: hexadecimal equivalent values for each digit to be displayed

Program:

/* Description: \\\\\\\\\\\\\\\DISPLAY ARE CONNECTED IN


COMMON CATHODE MODE\\\\\\\\\\\\\\\\\\\\\
Port0 Connected to data lines of all 7 segment displays
a
----
f| g |b
|----|
e| |c
---- . dot
d
a = P0.04
b = P0.05
c = P0.06
d = P0.07
e = P0.08
f = P0.09
g = P0.10
dot = P0.11 */
#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++); // 1s delay
Switchcount++;

if(Switchcount == 0x10) /* 0 to F has been


displayed ? go back to 0 */
{
Switchcount = 0;

LPC_GPIO0->FIOCLR = 0x00180ff0;

}
}
}
Result: The Hex digits „0‟ to „F‟ were displayed on a 7-segment LED interface, with an
appropriate delay in between, on an ARM CORTEX M3 evaluation board

Viva Questions:
1. Explain the fundamentals of Seven Segment Display.
2. How do you configure seven segment LED‟s to display hex numbers.
3. Explain the keywords ALLDISP and DATAPORT.
4. How do you configure PINSEL and GPIO?
12.Interface a simple Switch and display its status through Relay, Buzzer
and LED.
Aim: To interface a simple Switch and display its status through Relay, Buzzer and LED on
an ARM CORTEX M3 evaluation board using evaluation version of Embedded 'C' & Keil
uVision-4 tool.

Relay and Buzzer

Block Diagram
Program:
#include <LPC17xx.H>
unsigned int count=0;
int main(void)
{
unsigned int i;

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


LPC_GPIO0->FIODIR = 0x03000000; //P0.24, P0.25 OUTPUT

while(1)
{
if(!(LPC_GPIO2->FIOPIN & 0x00000800))//FIOPIN-P2.12
{
for(i=0;i<10;i++)

{
LPC_GPIO0->FIOSET = 0x03000000; //relay on
for(i=0;i<10000;i++);
}
}
else

{
LPC_GPIO0->FIOCLR = 0x03000000; //relay off
for(i=0;i<100000;i++);
}
}
} //end int main(void)

Result: A simple Switch was interfaced with an ARM CORTEX M3 evaluation board and its
status was displayed through Relay, Buzzer and LED.

VIVA Questions:

1. What is the relay and how it works.


2. How does the Piezoelectric buzzer works.
3. How do you configure PINSEL and GPIO?
4. Mention the uses of Relay.

You might also like