Professional Documents
Culture Documents
APPLICATIONS
LABORATORY MANUAL
SEMESTER: VI
11 Mini Project
12 Appendix I
13 Appendix II
14 Appendix III
15 Appendix IV
Experiment Plan & Course Outcomes
Course Outcomes:
No. Outcome
No.
Term Work:
1. Term work assessment must be based on the overall performance of the student with
every experiment graded from time to time. The grades will be converted to marks as per
‘credit and grading’ System manual and should be added and averaged. Based on the
above scheme grading and term work assessment should be done
2. The final certification and acceptance of term work ensures satisfactory performance of
laboratory work and minimum passing marks in term work
Oral:
1. Practical and Oral exam will be based on the entire syllabus
Microcontrollers and Applications
Experiment No: 1
3. Theory
Features:
8051 Architecture:
From the following diagram Fig 1.1, the system bus connects all the support devices to the
CPU. The system bus consists of an 8-bit data bus, a 16-bit address bus and bus control
signals. All other devices like program memory, ports, data memory, serial interface,
interrupt control, timers, and the CPU are all interfaced together through the system bus.
Fig 1.1: Architecture of 8051
1. ALU
▪ 8-bit
▪ Performs all arithmetic and logical operations
▪ Updates status flags(PSW)
2. Memory
▪ Separate On-chip Data and Code memory
▪ Code Memory-Programs instructions (ROM-4KB)
▪ Data memory-various Data (RAM-128B)
▪ Few RAM locations used to program control
▪ various on-chip peripherals and features-SFRs
3. Peripherals
▪ 2, 16 bit Timers T0, T1
▪ SFRs- TCON, TMOD, T0, T1
▪ PINs-T0, T1
▪ 4, I/O ports P0, P1, P2, P3
▪ SFRs-P0, P1, P2, P3
▪ PINs-P0.0-P0.7, P1.0-P1.7, P2.0-P2.7, P3.0-P3.7
4. Serial Port
▪ SFRs-SCON, SBUF, PCON (1-bit)
▪ PINs-Rxd, Txd
5. Interrupts
▪ SFRs-IP, IE
▪ PINs-INT0, INT1 (H/W)
6. Timing and Control Unit
▪ Generate time and Control signal
▪ Necessary for Execution
▪ Synchronizes all activities with clock
7. Oscillator
▪ On-chip oscillator circuit – generates clock pulses.
▪ External resonant circuit connected (complete oscillator)
▪ Crystal Frequency=12Mhz
Pin Description:
Port 0(p0.0 to p0.7): It is 8-bit bi-directional I/O port. It is bit/ byte addressable. During
external memory access, it functions as multiplexed data and low-order address bus AD0-
AD7.
Port 1 (p1.0 to p1.7): It is 8-bit bi-directional I/O port. It is bit/ byte addressable. When logic
'1' is written into port latch then it works as input mode. It functions as simply I/O port and it
does not have any alternative function.
Port 2 (p2.0 to p2.7): It is 8-bit bi-directional I/O port. It is bit/ byte addressable. During
external memory access it functions as higher order address bus (A8-A15).
Port 3(p3.0 to port 3.7): It is 8-bit I/O port. In an alternating function each pins can be used as
a special function I/O pin.
P3.0-RxD: It is an Input signal. Through this I/P signal microcontroller receives serial data of
serial communication circuit.
P3.1-TxD: It is O/P signal of serial port. Through this signal data is transmitted.
P3.2- (INT0): It is external hardware interrupt I/P signal. Through this user, programmer or
peripheral interrupts to microcontroller.
P3.3-(INT1): It is external hardware interrupt I/P signal. Through this user, programmer or
peripheral interrupts to microcontroller.
P3.4- T0: It is I/P signal to internal timer-0 circuit. External clock pulses can connect to
timer-0 through this I/P signal.
P3.5-T1: It is I/P signal to internal timer-1 circuit. External clock pulses can connect to timer-
1 through this I/P signal.
P3.6-WR#: It is active low write O/P control signal. During External RAM (Data memory)
access it is generated by microcontroller. When [WR (bar)] =0, then performs write
operation.
P3.7-RD#: It is active low read O/P control signal. During External RAM (Data memory)
access it is generated by microcontroller. When [RD (bar)] =0, then performs read operation
from external RAM.
XTAL1 and XTAL2: These are two I/P line for on-chip oscillator and clock generator circuit.
A resonant network as quartz crystal is connected between these two pin. 8051
microcontrollers also drive from external clock, then XTAL2 is used to drive 8051 from
external clock and XTAL1 should be grounded.
EA#/VPP: It is and active low I/P to 8051 microcontrollers. When (EA)= 0, then 8051
microcontroller access from external program memory (ROM) only. When (EA) = 1, then it
accesses internal and external program memories (ROMS).
PSEN#: It is active low O/P signal. It is used to enable external program memory (ROM).
When PSEN#= 0, then external program memory becomes enabled and microcontroller read
content of external memory location. Therefore, it is connected to (OE) of external ROM. It
is activated twice every external ROM memory cycle.
ALE: Address latch enable: It is active high O/P signal. When it goes high, external address
latch becomes enabling and lower address of external memory (RAM or ROM) latched into
it. Thus it separates A0-A7 address from AD0-AD7. It provides properly timed signal to
latch lower byte address. The ALE is activated twice in every machine cycle. If external
RAM & ROM is not accessed, then ALE is activated at constant rate of 1/6 oscillator
frequency, which can be used as a clock pulses for driving external devices.
RESET: It is active high I/P signal. It should be maintained high for at least two machine
cycle while oscillator is running then 8051 microcontroller resets.
NOTE: # stands for active low signal
4. Conclusion
Salient features, architecture and pin diagram of 8051 microcontrollers were studied in
detail
6. References:
3. Apparatus Required
4. Theory
Instructions used to implement Addition and Subtraction program using Immediate, Direct
and Indirect addressing mode are:
i. MOV A,8-bit data: The MOV instruction moves data bytes between the two
specified operands. The byte specified by the second operand is copied to the
location specified by the first operand. The source data byte is not affected.
ii. MOV DPTR, 16-BIT ADDRESS: Move the 16-bit address of external memory
location to data pointer register. Data pointer registers can be initialized by
immediate data, thus 16-bit address to be used is loaded in DPTR.
iii. MOV A, @DPTR: Move content of memory location pointed by data pointer
having 16-bit direct address to A register.
iv. MOV @DPTR, A: Move content of A register to memory location pointed by data
pointer having 16-bit direct address.
v. ADD A, B: The ADD instruction adds a byte value to the accumulator and stores
the results back in the accumulator. The destination operand is always in register A
while the source operand can be a register, immediate data, or in memory. The
instruction could change any of the AF, CF, or P bits of flag register.
vi. SUBB A, B: In subtraction with borrow, the 8051 use the 2’s complement method.
There are two case for SUBB instruction; (1) with CY = 0, and (2) With CY = 1.
The SUBB instruction subtracts the specified byte variable and the carry flag from
the accumulator. The result is stored in the accumulator. This instruction sets the
carry flag if borrow is required for bit 7 of the result. If no borrow is required, the
carry flag is cleared.
vii. INC DPTR: The INC instruction increments the specified operand by 1. An original
value of FFh or FFFFh overflows to 00h or 0000h. No flags are affected by this
instruction. When this instruction is used to modify an output port, the value used as
the port data is read from the output data latch, not the input pins of the port.
5. Algorithm
Immediate AM
Start Start
Store the result in A Store result in A & transfer to memory location 32H
Stop Stop
Fig 2.1: Flow chart for Immediate and Direct Addressing Mode
Start
Stop
8. Observation Table
For Addition
INPUT B 9000H
Before execution
A 9001H
OUTPUT
After execution A 9002H
For Subtraction
INPUT B 9000H
Before execution
A 9001H
OUTPUT
After execution A 9002H
• if the results generate carry from addition or require borrow from subtraction it will
set carry flag
• if the result is out of range, OF will set to 1
• if result contains even no of 1s, PF sets to 1
10. Precautions
12. References:
3. Apparatus Required
4. Theory
Instructions used to implement Multiplication and Division program using Register, Direct
and Indirect addressing mode (repeated instructions in the previous Experiment are not
explained):
i. MUL AB: The MUL instruction multiplies the unsigned 8-bit integer in the
accumulator and the unsigned 8-bit integer in the B register producing a 16-bit
product. The low-order byte of the product is returned in the accumulator. The high-
order byte of the product is returned in the B register. The OV flag is set if the
product is greater than 255 (0FFh), otherwise it is cleared. The carry flag is always
cleared.
ii. DIV AB: The DIV instruction divides the unsigned 8-bit integer in the accumulator
by the unsigned 8-bit integer in register B. After the division, the quotient is stored in
the accumulator and the remainder is stored in the B register. The carry and OV flags
are cleared. If the B register begins with a value of 00h the division operation is
undefined, the values of the accumulator and B register are undefined after the
division, and the OV flag will be set indicating a division-by-zero error.
5. Algorithm
Immediate AM
Step1: Load register B and A with contents from 30H and 31H
Step2: Multiply/Divide the two numbers
Step3: Multiplication result lower 8 bits are stored in register A and higher 8 bits are
stored in register B/ Division result quotient in register A and remainder in register B
Step4: Move the result from A register to the memory location 32H and result from B
register to the memory location 33H
Step5: Stop
Indirect AM
Start Start
Store the lower byte in A and upper byte in B Store the lower byte in A and upper byte in B
of the product /Quotient in A and Remainder of the product /Quotient in A and Remainder
in B to the destination in B to the destination
Stop Stop
Multiply A and B /
Divide A by B
Stop
8. Observation Table
For Multiplication
INPUT B 9000H
Before execution
A 9001H
OUTPUT A 9002H
After execution
B 9003H
For Division
INPUT B 9000H
Before execution
A 9001H
OUTPUT A 9002H
After execution
B 9003H
• The multiplication of two 8-bit numbers will give 16-bit result, so the lower 8-bit are
stored in register A and higher 8-bit are stored in register B
• The division of two 8-bit numbers will give 16-bit result, so the lower 8-bit are stored
in register A and higher 8-bit are stored in register B
• if the results generate carry from multiplication/ division it will set carry flag
• if the result is out of range, OF will set to 1
• if result contains even no of 1s, PF sets to 1
10. Precautions
12. References:
3. Apparatus Required
4. Theory
Instructions used to arrange n-numbers in ascending order using different addressing modes
are:
i. LJMP: LJMP is an unconditional long jump. It is 3-byte instruction in which first
byte is opcode, and the second and third bytes represent the 16- bit address of the
target location. The LJMP instruction transfers program execution to the specified 16-
bit address. The PC is loaded with the high-order and low-order bytes of the address
from the second and third bytes of this instruction respectively. No flags are affected
by this instruction. The range of destination addresses is within whole memory
(64KB).
ii. AJMP: AJMP is an unconditional absolute jump. It is 2-byte instruction, the new
value for the Program Counter is calculated by replacing the least-significant-byte of
the Program Counter with the second byte of the AJMP instruction, and replacing bits
0-2 of the most-significant-byte of the Program Counter with 3 bits that indicate the
page of the byte following the AJMP instruction. Bits 3-7 of the most-significant-byte
of the Program Counter remain unchanged. Since only 11 bits of the Program Counter
are affected by AJMP, jumps may only be made to code located within the same 2k
block as the first byte that follows AJMP.
iii. SJMP: SJMP is an unconditional short jump. It is 2-byte instruction in which first
byte is opcode, and the second byte represent the 8- bit relative address. The address
is calculated by adding the signed relative offset in the second byte of the instruction
to the address of the following instruction. The range of destination addresses is from
128 before the next instruction to 127 bytes after the next instruction.
iv. CJNE: CJNE compares the value of operand1 and operand2 and branches to the
indicated relative address if operand1 and operand2 are not equal. If the two operands
are equal program flow continues with the instruction following the CJNE instruction.
v. JNC: JNC will branch to the address indicated by relative address if the Carry Bit is
not set. If the Carry Bit is set program execution continues with the instruction
following the JNC instruction. No flags are affected by this instruction
vi. JC: JC will branch to the address indicated by relative address if the Carry Bit is set.
If the Carry Bit is not set program execution continues with the instruction following
the JC instruction. No flags are affected by this instruction
vii. DJNZ: DJNZ decrements the value of register by 1. If the initial value of register is 0,
decrementing the value will cause it to reset to 255 (0xFF Hex). If the new value of
register is not 0 the program will branch to the address indicated by relative address.
If the new value of register is 0 program flow continues with the instruction following
the DJNZ instruction. When this instruction is used to modify an output port, the
value used as the port data is read from the output data latch, not the input pins of the
port.
5. Algorithm
Y
Is
A =B?
N
N
Is
CY=1?
N
Is
R1=0?
R1=1? Y
N
Is
R0=0?
R0R0=
Y
1?
STOP
8. Observation Table
9002H
9003H
9004H
9005H
9006H
9007H
9008H
9009H
INPUT 9000H
Before execution
9001H
9002H
9003H
9004H
9005H
9006H
9007H
9008H
9009H
9. Result and Discussion
Arrangement of ten random numbers in ascending order was done by using CJNE, JNC,
SJMP instructions and result is overwritten at the same location from where the input
data was taken.
• For ascending and descending order arrangement two counter are initialized.
• One counter is used for inner iterations and another is used for outer iterations.
• For ascending order arrangement JNC instruction will be used
• For descending order arrangement JC instruction will be used
10. Precautions
a. Explain JNC.
b. What is word length of 8086?
c. Which signal is used to separate address & data bus?
d. How many multiplexed lines are there in 8086?
e. What is maximum memory addressing capability of 8086?
f. What is maximum I/O addressing capability of 8086?
g. What are equivalent instructions to JZ & JNZ?
h. What is the jump range in 8051?
i. What are the different industrial applications of micro controllers?
12. References:
3. Apparatus Required
4. Theory
In the "timer" function mode, the counter is incremented in every machine cycle. Thus,
one can think of it as counting machine cycles. Hence the clock rate is (1/12) th of the
oscillator frequency. The operation of the timers/counters is controlled by two special
function registers, TMOD and TCON respectively.
TF1: Timer1 overflow flag. It is set when timer rolls from all 1s to 0s. It is cleared when
processor vectors to execute ISR located at address 001BH.
TR1: Timer1 run control bit. Set to1tostartthe timer / counter.
TF0: Timer0overflowflag. (SimilartoTF1)
TR0: Timer0 run control bit.
IE1: Interrupt1 edge flag. Set by hardware when an external interrupt edge is detected. It
is interrupt is processed
IE0: Interrupt0edgeflag.(SimilartoIE1)
IT1: Interrupt1 type control bit. Set/ cleared by software to specify falling edge / low
level triggered external interrupt.
IT0: Interrupt0 type control bit. (Similar to IT1)
Example: Given Time delay t = 10ms => ton = 500µs, toff = 500µs
= 65535 – 461 + 1
= (65075)10
S/W delay is generated using a single or a pair of register. For the delay to be
generated count is loaded in the register and decremented till it becomes zero. The
calculation of count depends on number of instructions in delay program. If count is
given delay generated can be calculated and if delay is given count required can be
calculated
Step1: Set the TMOD register value according to the timer required and which
timer mode is to be used (Example: Set TMOD register value to 01H, Timer 0
Mode 1)
Step2: Move count lower byte to TL0 and Higher byte to THO
Step3: Start Timer by setting TR0 bit in TCON
Step4: Check TF flag for overflow
Step5: When the flag is raised stop the timer
Step6: Clear TR and TF bit
Step7: Complement the Port bit and call delay routine again
Step8: Loop back to step 2
6. Flowchart
Draw the flowchart for square wave generation using both hardware and software delay
generation (use algorithm to draw flowchart)
7. Procedure
Follow the procedure as given in Appendix I for MumLab-51 Kit and Appendix II for
MCU 8051 IDE
9. Precautions
• Properly connect 8051 trainer kit with power supply terminals and with DSO
• Do not keep the kit and DSO on for longer time
• Switch off the Kit and DSO after implementing the program
• Shut down MCU 8051 IDE properly
• Handle the trainer kit carefully
11. References:
3. Apparatus Required
4. Theory
LED is a semiconductor device used in many electronic devices, mostly used for signal
transmission /power indication purposes. It is very cheaply and easily available in a
variety of shape, color, and size. The LEDs are also used for design message display
boards and traffic control signal lights etc.
There are two ways which we can interface LED to the Microcontroller 8051. But the
connections and programming techniques will be different. Both methods are given in
figure.
Observe carefully the interfacing with LED 2 (Right Side) is in forward biased because
the input voltage of 5V connected to the positive terminal of the LED, so here the
microcontroller pin should be at LOW level. And vice versa with the interfacing with
LED 1 (Left Side) connections.
The resistor is important in LED interfacing to limit the flowing current and avoid
damaging the LED and/or MCU.
Interface 1 will glow LED, only if the PIN value of the microcontroller is HIGH as
current flows towards the ground.
Interface 2 will glow LED, only if the PIN value of the microcontroller is LOW as
current flows towards PIN due to its lower potential.
There are two configurations which we can interface multiple LEDs to the
Microcontroller 8051. The configurations are- common cathode and common anode
configurations. All the LEDs are driven through resistors for limiting current. The
common cathode configurations for interfacing LEDs with 8051 is shown in following
figure.
Fig 5.3: Common cathode configurations to interface LED with 8051
In common cathode configurations, the anode terminal of LEDs is interfaced with 8051
with resistors and cathode terminal is grounded for all LEDs. For this configuration to
glow the LEDs from microcontroller pin should be at HIGH level.
In common anode configurations, the cathode terminal of LEDs is interfaced with 8051
and anode terminal is connected to 5V with resistors. For this configuration to glow the
LEDs from microcontroller pin should be at LOW level.
5. Algorithm
Draw the flowchart for LEDs interfacing with 8051 (use algorithm to draw flowchart)
7. Procedure
Follow the procedure as given in Appendix I for MumLab-51 Kit and Appendix II for
MCU 8051 IDE
Light Emitting Diodes or LEDs are the mostly commonly used output components in
many applications. They are made of semiconducting material. The LEDs are interfaced
with 8051 successfully to glow the desired pattern on LED and to get the output the port
programming is used.
9. Precautions
3. Apparatus Required
4. Theory
A seven segment display module is an electronic device used to display digital numbers
and it is made up of seven LED segments. Because of the small size of the LEDs, it is
really easy for a number of them to be connected together to make a unit like seven
segment display. In the seven segment display module, seven LED s are arranged in a
rectangle. Sometimes, an additional LED is seen in a seven segment display unit which is
meant for displaying a decimal point.
Each LED segment has one of its pins brought out of the rectangular package. Other pins
are connected together to a common terminal. Seven segment displays can only display 0
to 9 numbers. These seven LEDs indicate seven segments of the numbers and a dot point.
Seven segment displays are seen associated with a great number of devices such as
clocks, digital home appliances, signal boards on roads etc.
Fig 5.4: Seven Segment Display
Seven segment displays come up with two different configurations. They are the common
anode and a common cathode. One pin each from each segment is connected to a
common terminal. According to the pins which are connected to the common terminal,
the seven segment display is categorized as a common anode and common cathode.
As the name indicates, its cathode is connected to a common terminal. Below is the
schematic diagram to indicate its common cathode structure. It should be connected to
the ground while operating the display. If a high voltage is given to the anode, then it will
turn on the corresponding segment.
Common Anode 7-segment display
In this type, the anode is common. It should be connected to a high voltage (to the supply
through a resistor to limit current). In order to turn on a particular segment, a ground level
voltage is given to the corresponding pin. Since logic circuits can sink more current than
they can source, common anode connection is used most widely.
Display codes:
Display codes are the voltages to be applied to the segments to display a number. It is in
the order of segments ABCDEFG(DP), total 8 bits. Below is a table with display codes of
all the digits with decimal point OFF.
If number 0 has to be displayed, then the segments A through F are turned on. In order to
turn on the segments, in common cathode mode, the anode terminals are subjected to a
high voltage while in common anode mode, the cathode terminals are given a low
voltage.
SSD interfacing with 8051:
There are two configurations which we can interface SSD to the Microcontroller 8051.
The configurations are- common cathode and common anode configurations. The
common cathode configurations for interfacing SSD with 8051 is shown in following
figure.
In common cathode configurations to glow the SSD from microcontroller, pin should be
at HIGH level and in common anode configurations to glow the SSD from
microcontroller, pin should be at LOW level. The common terminals of SSD are
connected to 5V or GND according to the configurations.
5. Algorithm
Draw the flowchart for SSD interfacing with 8051 (use algorithm to draw flowchart)
7. Procedure
Follow the procedure as given in Appendix I for MumLab-51 Kit and Appendix II for
MCU 8051 IDE
A seven segment display module is an electronic device used to display digital numbers
(BCD numbers) and it is made up of eight LED segments. The SSD is interfaced with
8051 successfully to display the BCD numbers continuously and to get the output the port
programming is used.
9. Precautions
Experiment No: 6
3. Theory
Features:
▪ 32-bit Processor
▪ 40Mhz-60Mhz
▪ Modified RISC (code density, reduce complexity, low consumption) technology
▪ Enhanced Power Saving Design
▪ Core surrounded by Caches, Memory and peripherals
▪ Pipelining
▪ Large Register set
▪ Simple Addressing modes
▪ auto increment and decrement addressing mode
▪ Load-Store Architecture /Register to register
▪ Incorporates some CISC ideas (variable cycle execution)
▪ Add Barrel Shifter (expand capability)
▪ Conditionally executing instruction
▪ Thumb Instruction –16 bit
▪ DSP Instruction
▪ OS Manages Application task
When an instruction is decoded inside the ARM core and how a particular instruction is
executed by interacting with the internal registers file and then send result out of the registers
1. It is Von Neuman architecture, hence data coming through bus is either instruction or data
(same memory).
2. The Sign extend hardware converts signed 8-bit & 16-bit numbers to 32-bit values as they
are read from memory & placed in a register (for signed values), fill zeros if unsigned.
3. Source operands (Rn & Rm) are read from the register file using the internal buses A & B
respectively & result Rd is written back.
4. The PC value is in the address register which is fed in to the incremented, then the
incremented value is copied back in to r15.
5. It is also written in to address register to be used as the address for the next instruction
fetch.
6. ALU (The Arithmetic & logic Unit) or MAC (multiply & accumulate Unit) takes the
register values Rn & Rm from A & B buses & computers a result).
7. Data processing instructions write the result in Rd directly to the register file.
8. Load & Store instruction use the ALU to generate on Address to be to be held in the
address register & broadcast on the address bus.
9. Barrel shifter: One important feature of the is that register Rm alternatively can be
preprocessed in barrel in barrel shifter before it enters the ALU [left shift, right shift, rotated
etc.]. Depending on the instruction Barrel Shifter may be used or it could be short circuit.
10. Barrel shifter & ALU can calculate together a wide range of expression & address in the
same cycle.
The ARM register set contains 16 directly-accessible registers in user mode (non-privileged
mode), r0 to r15. An additional register, the Current Program Status Register (CPSR),
contains condition code flags, and the current mode bits. Registers r0 to r13 are general-
purpose registers used to hold either data or address values.
In privileged modes, another register, the Saved Program Status Register (SPSR), is
accessible. This contains the condition code flags, and the mode bits saved as a result of the
exception that caused entry to the current mode.
ARM core uses CPSR to monitor & control internal operations. The unused part reserved for
future expansion. CPSR fields is divided in to four fields, each 8-bits wide: flags, status,
extension, and control.
F- Fast interrupt request Disable If set fast interrupt request channel is disabled
T-Thumb instruction set If set processor will execute Thumb Instruction set
4. Conclusion
Salient features, data flow model and register set of ARM7 microcontrollers were studied
in detail
6. References:
3. Apparatus Required
4. Theory
ARM architecture incorporate a number of features inherits from RISC design. It has
Load and Store Architecture. It has fixed length 32-bit instructions. Various Blocks are
used in the process of performing Arithmetic or logical operation.
i. MOV: This instruction is used to move the content from one address to another
E.g. MOV r0, r1 // which will load content of r1 to r0
ii. LDR: This instruction is used to load the content from memory to register
E.g. LDR r0, [ r1] // which will load content from r1 address to r0
iii. STR: This instruction is used to store the content from register to memory
E.g. STR r0, [r1] // which will store content of r0 to r1 address
iv. ADD: It adds the content of two operands and result will be stored in destination
register
E.g. ADD r1, r2, r3 // r1=r2+r3
v. ADDS: It adds the content of two operands and result will be stored in destination
register and status is updated
E.g. ADD r1, r2, r3 // r1=r2+r3, result status is updated in CPSR
vi. ADC: This instruction is asked to add contents of two registers with carry bit, in
order to add number greater than 32-bit
E.g. ADC r1, r2, r3 // it adds upper 32 bits and carry of LSB addition.
vii. SUB: It subtracts the content of two operands and result will be stored in
destination register
E.g. SUB r1, r2, r3 // r1=r2-r3
viii. SUBS: It subtracts the content of two operands and result will be stored in
destination register and status is updated
E.g. ADD r1, r2, r3 // r1=r2-r3, result status is updated in CPSR
ix. SBC: This instruction subtracts the two operands taking carry into account and save
result in destination register
E.g. SBC r1, r2, r3 // it subtracts r3 and 1 from r2 and store the result to r1
5. Algorithm
Addition
Start
Start
M
Sub R3 from R2 content
Add R2 and R3 contents
Stop
Stop
Fig 7.1: Flow chart for addition and subtraction operation in ARM7
7. Procedure
Follow the procedure as given in Appendix III Keil IDE
8. Observation Table
For Addition
OUTPUT R1 0x40000008
After execution
For Subtraction
OUTPUT R1 0x40000008
After execution
• if the results generate carry from addition or require borrow from subtraction it will
set carry flag
• if ADC instruction is called then the result will add operand 2 and carry bit to operand
1, then store the result to destination register
• if SBC instruction is called then the result will subtract operand 2, carry bit and 1
from operand 1, then store the result to destination register
10. Precautions
3. Apparatus Required
4. Theory
ARM architecture incorporate a number of features inherits from RISC design. It has
Load and Store Architecture. It has fixed length 32-bit instructions. Instructions used to
implement multiplication and division (repeated instructions in the previous Experiment
are not explained) are:
i. MUL: It multiply the content of two operands and result will be stored in
destination register
E.g. MUL r1, r2, r3 // r1=r2 x r3
ii. UMULL: It multiply the content of two operands and result will be stored in two
destination register, one register will store lower 32-bit result and another register is
will store higher 32-bit result
E.g. UMULL r0, r1, r2, r3 // r2 x r3 = r0 (lower 32-bit) & r1 (higher 32-bit)
iii. MLA: It multiply the content of two operands and result is added with the another
operand and places the least significant 32 bits of the result at destination register
E.g. MLA r0, r1, r2, r3 // r0 = (r1 x r2) + r3
iv. LSR: Logical Shift Right instruction is a preferred synonym for MOV instructions
with shifted register operands. It provides the unsigned value of a register divided
by a variable power of two, inserting zeros into the vacated bit positions. (As there
is no separate instruction for division operation in ARM7)
E.g. MOV r1, r0, LSR#2 // r1 = r0 / (2^2)
5. Algorithm
Multiplication
Start Start
Stop Stop
Fig 7.1: Flow chart for Multiplication and Multiply and Accumulate operation in ARM7
Start
Stop
8. Observation Table
For Multiplication
OUTPUT R0 0x40000008
After execution
R1 0x4000000C
R3 0x40000008
OUTPUT R0 0x4000000C
After execution
For Division
OUTPUT R1 0x40000004
After execution
9. Result and Discussion
Multiplication and Division of two 32-bit numbers was done using UMULL/MLA and LSR
instruction respectively and the result was stored in the destination register and then shifted
to memory location. Following conclusion were made by multiplying and dividing various
numbers:
• for long multiplication we have UMULL instruction i.e. unsigned long multiplication
and result is of 64-bits, if we multiply two 32-bit numbers then we get 64-bit result so
by using UMULL instruction we get lower 32-bit result in one register and higher 32-
bit result in other register
• for multiplication and addition, we have MLA instruction and it first multiplies the
values from the registers, adds the value from another register, and places the least
significant 32 bits of the result in destination register
• for division there is no separate instruction in ARM7 so we use logical shift right
instruction with shifted register operands. It provides the unsigned value of a register
divided by a variable power of two and result in destination register
10. Precautions
12. References:
Experiment No: 8
3. Apparatus Required
4. Theory
Instructions used to find the largest number from n-numbers from memory locations are:
i. CMP: Comparison instruction subtracts the value of Operand2 from the value in Rn.
This is the same as a SUBS instruction, except that the result is discarded, this
instruction update the N, Z, C and V flags according to the result
E.g. CMP r1, r2 // (r1 - r2) = only status flag updated
ii. B: Branch instruction cause the program counter to point to a new address which is
specified after B, thus the program continues at the instruction thus pointed to.
Branch instruction is equivalent to the JMP instruction and this instruction does not
change the flags
E.g. B loop1 // PC is loaded with address of loop1
iii. BHI: This is a conditional branch instruction. This instruction performs unsigned
comparison and gave higher number. If status of carry flag is set and zero flag is
clear, then the condition for branch satisfies and it causes PC to point to a new
address which is specified after BHI
E.g. BHI loop1 // PC is loaded with address of loop1 if C=1 and Z=0
iv. BNE: This is a conditional branch instruction. This instruction performs comparison
of two operands and result is not equal or non-zero result. If status of zero flag is
clear, then the condition for branch satisfies and it causes PC to point to a new
address which is specified after BNE
E.g. BNE loop1 // PC is loaded with address of loop1 if Z=0
5. Algorithm
Y
Is
CY=1?
N
Is
R5=0?
R1=1? Y
N
Store the content of register R3 into memory location
pointed by register R2
STOP
Fig 8.1: Flow chart for finding largest number from n-numbers
7. Procedure
Follow the procedure as given in Appendix III Keil IDE
8. Observation Table
INPUT 0x40000000
0x40000004
0x40000008
0x4000000C
0x4000000F
0x40000010
0x40000014
0x4000001C
0x4000001F
0x40000020
OUTPUT 0x40000030
12. References:
Experiment No: 9
3. Apparatus Required
4. Theory
Instructions used to separate even & odd numbers from n-numbers which are stored at
memory locations (repeated instructions in the previous Experiment are not explained) are:
i. ROR: It provides the value of the contents of a register rotated by a value. The bits
that are rotated off the right end are inserted into the vacated bit positions on the
left. ROR can only be used with a register-controlled shift.
E.g. MOV R1, R0, ROR #1 // Rotate R0 to right by 1 bit and store result at R1
ii. BCS: This conditional instruction performs comparison between two operands and
update the result of status flags in CPSR. If status of carry flag is set means
arithmetic operation gave carry out, then the condition for branch satisfies and it
causes PC to point to a new address which is specified after BCS
E.g. BCS loop1 // PC is loaded with address of loop1 if C=1
5. Algorithm
6. Flow Chart
START
Get data from memory into register R0 & increment the pointer
Rotate the data of R0 to the right by 1 bit and store the result in R1
Y
Is
CY=1?
8. Observation Table
0x40000008 0x40000038
0x4000000C 0x4000003C
0x4000000F 0x40000040
0x40000010
OUTPUT 0x40000050
0x40000014 (EVEN NO.)
0x40000054
0x4000001C
0x40000058
0x4000001F
0x4000005C
0x40000020
0x40000060
10. Precautions
12. References:
3. Apparatus Required
4. Theory
LPC2148:
General Purpose Input Output (GPIO) pins of a microcontroller are the first thing we
need to learn before starting its embedded programming as input/output pins are the only
way to interface with the microcontroller. GPIO pins can be used for driving loads,
reading digital and analog signal, controlling external components, generating triggers for
external devices etc.
LPC2148 has two IO ports namely PORT0 (P0) and PORT1 (P1). These two IO ports are
of 32-bit wide and are provided by the 64 pins of the microcontroller. The naming
convention of the I/O pins on the LPC2148 Microcontroller is Pa.bc where ‘a’ is the
number of the port i.e. 0 or 1 (as LPC2148 has only two ports) and ‘bc’ is the number of
the pin in the port a. For example, P0.1 indicates pin number 1 of PORT0 and P1.10
indicates pin number 10 of PORT1.
(A) PORT0 is a 32-bit wide input/output port with dedicated direction control bits for
each physical pin. Out of the 32 pins, 28 pins can be used as general purpose bidirectional
I/O pins. Pin P0.31 is an output only pin. Pins P0.24, P0.26 and P0.27 of PORT0 are not
available.
(B) PORT1 is also a 32-bit wide input/output port. In PORT1, pins P1.0 to P1.15 are not
available and pins P1.16 to P1.31 are the available general purpose input/output pins.
Most of the pins in both the I/O ports of the LPC2148 have more than one function i.e.
they are multiplexed with different functions. The default function of all the Pins is
GPIO. At any point of operation, each pin can have a single function and the function can
be selected with the help of three Configuration Registers which control the multiplexers
to allow connection between the external pin and the on-chip peripheral.
GPIO function is the most frequently used functionality of the microcontroller. The GPIO
function in both the Ports are controlled by a set of 4 registers: IOPIN, IODIR, IOSET
and IOCLR.
(A) IOPIN: It is a GPIO Port Pin Value register and can be used to read or write values
directly to the pin. The status of the Pins that are configured as GPIO can always be read
from this register irrespective of the direction set on the pin (Input or Output).
The syntax for this register is IOxPIN, where ‘x’ is the port number i.e. IO0PIN for
PORT0 and IO1PIN for PORT1.
(B) IODIR: It is a GPIO Port Direction Control register and is used to set the direction
i.e. either input or output of individual pins. When a bit in this register is set to ‘0’, the
corresponding pin in the microcontroller is configured as Input. Similarly, when a bit is
set as ‘1’, the corresponding pin is configured as Output.
The syntax for this register is IOxDIR, where ‘x’ is the port number i.e. IO0DIR for
PORT0 and IO1DIR for PORT1.
(C) IOSET: It is a GPIO Port Output Set Register and can be used to set the value of a
GPIO pin that is configured as output to High (Logic 1). When a bit in the IOSET register
is set to ‘1’, the corresponding pin is set to Logic 1. Setting a bit ‘0’ in this register has no
effect on the pin.
The syntax for this register is IOxSET, where ‘x’ is the port number i.e. IO0SET for
PORT0 and IO1SET for PORT1.
(D) IOCLR: It is a GPIO Port Output Clear Register and can be used to set the value of a
GPIO pin that is configured as output to Low (Logic 0). When a bit in the IOCLR register
is set to ‘1’, the corresponding pin in the respective Port is set to Logic 0 and at the same
time clears the corresponding bit in the IOSET register. Setting ‘0’ in the IOCLR has no
effect on the pin.
The syntax for this register is IOxCLR, where ‘x’ is the port number i.e. IO0CLR for
PORT0 and IO1CLR for PORT1.
LED is a semiconductor device used in many electronic devices, mostly used for signal
transmission /power indication purposes. It is very cheaply and easily available in a
variety of shape, color, and size. The LEDs are also used for design message display
boards and traffic control signal lights etc. It has two terminals positive and negative as
shown in the figure.
Figure 10.2 shows the LED interfacing with LPC 2148. When P0.21 is at High (+5v)
status, then LED will glow and when P0.21 is at Low (0v) status, then LED will not
glow.
6. Flow Chart
Draw the flowchart for LED interfacing with LPC2148 (use algorithm to draw flowchart)
7. Procedure
Follow the procedure as given in Appendix IV for VSOFT LPC2148 Kit and Appendix
III for Keil IDE and Appendix V for Flash Magic
Light Emitting Diodes or LEDs are the mostly commonly used output components in
many applications. They are made of semiconducting material. The LEDs are interfaced
with LPC2148 successfully to blink LED and to get the output the GPIO programming is
used.
9. Precautions
11. References:
3. Apparatus Required
4. Theory
Buzzer:
Buzzer is an electrical device, which is similar to a bell that makes a buzzing noise and is
used for signaling. Typical uses of buzzers and beepers include alarm devices, timers and
confirmation of user input such as a mouse click or keystroke. A piezoelectric element
may be driven by an oscillating electronic circuit or other audio signal source, driven
with a piezoelectric audio amplifier. Sounds commonly used to indicate that a button has
been pressed are a click, a ring or a beep.
Figure 10.4 shows the Buzzer interfacing with LPC 2148. When P0.16 is at High (+5v)
status, then buzzer will make a buzzing noise and when P0.16 is at Low (0v) status, then
buzzer will not make a buzzing noise. When the input port pin from microcontroller is
changed, the sound wave is changed in Buzzer.
6. Flow Chart
Draw the flowchart for LED interfacing with LPC2148 (use algorithm to draw flowchart)
7. Procedure
Follow the procedure as given in Appendix IV for VSOFT LPC2148 Kit and Appendix
III for Keil IDE and Appendix V for Flash Magic
9. Precautions
11. References:
Commands:
1. A:
-Assemble? (Press enter key)
-Starting Address ------ (Enter starting address location and press enter key)
-Write down the assembly language program at starting address location
-After last line of program, press esc key to come out of editor
2. S:
-Substitute? (Press enter key)
-Internal RAM? / External RAM? (Press enter key to select the option / Press any key
except enter key to deselect the option)
-Enter Address ------ (Enter memory address location to store the data and press enter
key)
-Enter the data at memory address locations (Press upward arrow key)
-After last data stored, press esc key to come out of substitute
3. E:
-Execute? (Press enter key)
-Full swing? / Step by step? (Press enter key to select the option / Press any key except
enter key to deselect the option)
-Enter Address ------ (Enter starting address location of code and press enter key)
4. R:
-Register? (Press enter key)
-Bank0? / SFRs? (Press enter key to select the option / Press any key except enter key to
deselect the option)
-After choosing the option, read the contents of Bank0 / SFRs (Press enter key)
-After reading the contents of Bank0 / SFRs, press esc key to come out of register
5. S:
-Substitute? (Press enter key)
-Internal RAM? / External RAM? (Press enter key to select the option / Press any key
except enter key to deselect the option)
-Enter Address ------ (Enter memory address location to read the data and press enter
key)
-Read the data from memory locations (Press upward arrow key)
-After reading last data, press esc key to come out of substitute
6. D:
-Disassemble? (Press enter key)
-Enter Address ------ (Enter starting address location of code and press enter key)
-Getting machine code line by line (Press enter key)
-After getting all machine code, press esc key to come out of disassemble
Appendix II
1. Open KEIL software by double clicking an Icon which appears on your desktop PC.
2. Now click on Project in menu bar and select new project.
3. Now choose the destination where you want to store the project. Create a new folder and
use this folder as a destination folder for your new project.
4. Double click on the folder and give the name for your project file as *.uv3 (extension it
will take by default.). Click on Save.
5. It asks for target device name.
6. Select Philips ->LPC2148. And click OK.
7. It asks that “copy standard start up code” click yes. It will show target folder on left.
8. Now click to file menu and new file, and type your code here in the Text window.
9. After writing your code save this source file with proper extension, i.e. if you are writing
the code in the “C “language then save file as “*.c” or if in assembly then save as “*. S”.
10. Now click on the flash in menu bar and options for configure flash tools
11. After clicking on this window, you will get many options, after that click on “output”
option.
12. After clicking on output option you will get window, here selects the option that “create
hex file” and click ok.
13. After that click on the “build” icon very near to compile icon. After that click on Rebuild
icon this is near to build icon.
14. Now your *.hex file is created in your project folder.
15. For downloading this file in the target board (VSOFT-ARM7) use the “Flash Magic
Software.
Appendix IV
1. Open a VSET-ARM7DK box and ensure that all above mentioned parts or default
settings are in place.
2. Connect power adapter to mains supply (230V AC, 50Hz) and other end of adapter to
ARM7 Demo Kit (VSET-ARM7DK) PS_CON connector.
3. Remove jumper J31.
4. Switch on Demo/Trainer kit using SW_PWR Switch and press reset key (SW_RST).
5. The following message appears on LCD display module “VSOFT Technology”
6. Press Reset Switch (SW_RST) in case message does not appear on LCD Display Module.
7. Connect VSET-ARM7DK Demo kit to PC using USB cable.
8. Open KEIL tool by double clicking a ‘KEIL uvision 5’ icon.
9. Create a new project.
10. Compile that file and create a hex file for it.
11. Download hex file into Target board using flash magic software
12. Remove jumper J31.
13. Press Reset switch (SW_RST) to start execution program.
14. LED will blink.
Appendix V
1. Right click on ‘My computer’ icon available on Desktop of your PC. Go to Manage-
Device Manager-Ports. Now check and note down the assigned Port to ProlificUSB-to-
SerialCOMPort (COMxx).
2. Now go to Start menu of your computer and launch Flash Magic software.