Microprocessor & Microcontroller (Book)
Microprocessor & Microcontroller (Book)
in
1
www.aktutor.in
QUANTUM SERIES
For
B.Tech Students of Third Year
of All Engineering Colleges Affiliated to
Dr. A.P.J. Abdul Kalam Technical University,
Uttar Pradesh, Lucknow
(Formerly Uttar Pradesh Technical University)
Ankit Tyagi
TM
,, %DVLF3URJUDPPLQJFRQFHSWV)ORZFKDUWV\PEROV'DWD7UDQVIHURSHUDWLRQV$ULWKPHWLF
RSHUDWLRQV /RJLF 2SHUDWLRQV %UDQFK RSHUDWLRQ :ULWLQJ DVVHPEO\ ODQJXDJH SURJUDPV
3URJUDPPLQJWHFKQLTXHVORRSLQJFRXQWLQJDQGLQGH[LQJ$GGLWLRQDOGDWDWUDQVIHUDQG
ELWDULWKPHWLFLQVWUXFWLRQ/RJLFRSHUDWLRQURWDWHFRPSDUHFRXQWHUDQGWLPHGHOD\V
,QWHUUXSWV
1 Introduction to
Microprocessor
CONTENTS
Part-1 : Introduction to Microprocessor : ............ 1–2B to 1–7B
Microprocessor Architecture
and its Operations
CONCEPT OUTLINE
• The operations performed by microprocessor can be classified
into three groups :
i. Internal operations
ii. Operation initiated by microprocessor
iii. Operation initiated by external devices.
Questions-Answers
Answer
A. Microprocessor :
Microprocessor is a multipurpose, programmable, clock driven, register
based electronic device that reads binary instructions from a storage
device called memory; accepts binary data as input, process data according
to instructions, and provides output as a result.
B. Difference between microprocessor and microcontroller :
Answer
A. 8085 microprocessor :
1. The 8085 CPU is the most popular CPU amongst all the 8-bit CPUs.
2. The 8085 CPU houses an on-chip clock generator and provides good
performance utilizing an optimum set of registers and reasonably
powerful ALU.
3. The major limitation of this 8-bit microprocessors are limited memory
addressing capacity, slow speed of execution, limited number of
scratchpad registers and non-availability of compiler instruction set
and addressing modes.
B. 8086 microprocessor :
1. The first 16-bit CPU from Intel was a result of the designer’s efforts to
produce more powerful and efficient computing machine.
2. The 8086 contains a set of 16-bit general purpose registers, supports a
16-bit ALU, a rich instruction set and provides segmented memory
addressing scheme.
3. The introduction of a set of segment registers for addressing the
segmented memory in 8086 was indeed a major step in the process of
evaluation.
4. The major limitation in 8086 was that it did not have the memory
management and protection capabilities.
Introduction to Microprocessor 1–4 B (EC-Sem-5)
www.aktutor.in
C. 80286 microprocessor :
1. 80286 was the first CPU to possess the ability of memory management,
privilege and protection.
2. However, the 80286 CPU had a limitation on the maximum segment
size supported by it.
3. Another limitation of 80286 was that, once it was switched to protected
mode, it was difficult to get it back to real mode.
4. The only way of reverting it to the real mode was to reset the system.
D. 80386 microprocessor :
1. 80386 was the first 32-bit CPU from Intel.
2. The memory management capability of 80386 was enhanced to support
virtual memory, paging and four levels of protection.
3. The maximum segment size in 80386 was enhanced and this could be
as large as 4 GB.
4. The 80386 along with its math coprocessor 80387, provided a high
speed environment.
E. 80486 microprocessor :
1. The 80486 was designed with an integrated math coprocessor.
2. After getting integrated, the speed of execution of mathematical
operations enhanced three folds.
3. Also for the first time, an 8 KB four-way set associative code and data
cache was introduced in 80486.
4. A five stage instruction pipeline was also introduced.
F. Pentium microprocessor :
1. It has a super scalar, super pipelined architecture.
2. It has two integer pipelines U and V, where each one is a 4-stage
pipeline.
3. It has an on-chip floating point unit, which has increased the floating
point performance.
4. Pentium-II is the next version of Pentium.
5. It incorporates all features of Pentium-Pro and it has a large cache.
6. Pentium-III has been developed on 0.25 microtechnology and includes
over 9.5 million transistors.
Answer
1. The process of program execution in a microprocessor can be described
in the following sequence: read, interpret and perform.
2. The instructions are stored sequentially in the memory. The
microprocessor fetches the first instruction from its memory, decodes it
and executes that instruction.
www.aktutor.in
Microprocessor & Microcontroller 1–5 B (EC-Sem-5)
Answer
A. Architecture :
1. Microprocessor architecture defines suitable placement of its various
functional blocks in the form of required circuitry for efficient flow of
data and result, from one block to another.
2. The most general purpose architecture of microprocessor is shown in
Fig. 1.4.1.
Register Instruction
Data decoder
bus Register ALU
General purpose
Register
Answer
The operations performed by microprocessor can be classified as follows :
i. Internal operations :
1. Store 8-bit data.
2. Perform arithmetic and logical operations.
3. Test for conditions.
4. Sequence the execution of instructions.
5. Store data temporarily into the stack.
ii. Operations initiated by microprocessor : To communicate with
external devices or with memory, microprocessor performs primarily
four operations :
1. Read data or instruction from the memory.
2. Write data into the memory.
3. Read data from input devices.
4. Write data into the output devices.
iii. Operations initiated by external devices : External devices can
initiate the operation by activating Reset, Interrupt, READY and HOLD
pins of the microprocessor. These operations are as follows :
1. After activation of Reset pin, suspend all internal operations and clear
program counter so that it can fetch the next instruction from the
predefined memory address.
www.aktutor.in
Microprocessor & Microcontroller 1–7 B (EC-Sem-5)
Answer
1. The four operations commonly performed by the microprocessor (MPU)
are as follows :
i. Memory read : Reads data (or instructions) from memory.
ii. Memory write : Writes data (or instructions) into memory.
iii. I/O read : Accepts data from input devices.
iv. I/O write : Sends data to output devices.
2. All these operations are part of the communication process between
the MPU and peripheral devices.
3. To communicate with a peripheral (or a memory location), the MPU
needs to perform the following steps :
i. Identify the peripheral or the memory location (with its address).
ii. Transfer binary information (data and instructions).
iii. Provide timing or synchronization signals.
PART-2
Memory, Input and Output Devices.
CONCEPT OUTLINE
• Memory is a medium that stores binary information. They are
classified into two groups :
1. Primary or main memory.
2. Secondary or storage memory
• Input and o utput de vices are the me ans by which
microprocessor communicates with the outside world.
Introduction to Microprocessor 1–8 B (EC-Sem-5)
www.aktutor.in
Questions-Answers
Answer
A. Memory : A memory unit is a device to which binary information is
transferred for storage and from which information is retrieved when
needed for processing.
B. Classification :
Classification of memory
5. ROM in its strictest sense can only be read from, but all ROMs allow
data to be written into them at least once, either during initial
manufacturing or during a step called “programming”.
6. There are three types of ROM :
a. PROM :
1. A programmable read-only memory (PROM) is a form of digital memory
where the setting of each bit is locked by a fuse or antifuse. Such
PROMs are used to store programs permanently.
2. A typical PROM comes with all bits reading as 1, burning fuse during
programming causes its bit to read as 0.
3. The memory can be programmed just once after manufacturing by
“blowing” the fuses, which is an irreversible process. Blowing a fuse
opens a connection while blowing an antifuse closes a connection (hence
the name).
b. EPROM :
1. An EPROM, or erasable programmable read-only memory, is a type of
computer memory chip that retains its data when its power supply is
switched OFF. In other words, it is non-volatile.
2. Once programmed, an EPROM can be erased only by exposing it to
strong ultraviolet light.
c. EEPROM :
1. An EEPROM (also called an E2PROM) or electrically erasable
programmable read-only memory is a non-volatile storage chip used in
computers and other devices to store small amounts of volatile
(configuration) data.
2. The main advantage of EEPROMs over EPROMs is that they are erased
electrically instead of by ultraviolet light; this is faster and can be done
in circuit.
Answer
1. A latch is a D flip-flop. Two types of D flip-flops are available, a transparent
latch and a positive-edge-triggered flip-flop.
Introduction to Microprocessor 1–10 B (EC-Sem-5)
www.aktutor.in
D0 – D7 Output
device
(Latch)
Data bus
Clock To output device (display)
Fig. 1.8.1.
2. In a transparent latch, when the clock signal is high, the output Q
changes according to the input D.
3. When the clock signal goes low, the output Q will latch (hold) the last
value of the input D.
4. Latch is the simplest form of output port.
5. The output device is connected to microprocessor through latch.
6. When microprocessor wants to send data to the output device it puts the
data on data bus and activates the clock signal of latch, latching the data
from the data bus to output of latch.
7. It is then available at output of latch for the output device.
8. A latch is used for an output port because latch is necessary to hold the
output data for display; however the input data byte is obtained by
enabling a tri-state buffer and placed in the accumulator.
Answer
1. The memory chip has 1024 registers therefore 10 address line (A9 – A0)
are required to identify the registers. The remaining six address lines
(A15 – A10) of the microprocessor are used for the chip select CS signal.
2. In Fig. 1.9.1, the memory chip is enabled when the address lines
A15 – A10 are at logic 0. The address lines A9 – A0 can assume any address
of the 1024 registers, starting from all 0’s to all 1’s.
A15 A14 A13 A12 A11 A10 A9 A8 A 7 A6 A5 A4 A3 A2 A1 A0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 = 0000 H
Chip select logic 1 1 1 1 1 1 1 1 1 1 = 03FF H
3. The memory addresses range from 0000 H to 03FF H.
www.aktutor.in
Microprocessor & Microcontroller 1–11 B (EC-Sem-5)
A15
A14
A13
A12 MEMR
A11 MEMW
A10
A9
A8 CS RD WR
Internal decoder
A7
A6 1024
A5
A4 Registers
A3
A2
A1
A0
I/O
Lines
Fig. 1.9.1. Memory address range 1024 bytes of memory.
Answer
1. Fig. 1.10.1 shows a memory chip of 4 KB. The memory size of chip is
expressed as,
4 KB = 4 × 1024 bits = 212
2. As we know, 8085 microprocessor has 16 address lines. So, for addressing
the memory size we shall need 12 address lines only. Now remaining
lines (16 – 12 = 4), will be used for chip select.
Introduction to Microprocessor 1–12 B (EC-Sem-5)
www.aktutor.in
A15 MEMRD
A14
A13 MEMWR
A12 A11 CS RD WR
A10
A9
A8
Internal Decoder
A7
A6
A5 4 KB
A4 Memory
A3
A2
A1
A0
I/O line
Fig. 1.10.1. Memory map : 4 KB of memory.
A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0
6. The location of memory address have been shifted from 0000 H – 0FFF H
to 8000 H – 8FFF H and the hardware of the chip select will also change.
A15
A14 MEMRD
A13 MEMWR
A 12
CS
Memory
Fig. 1.10.2.
www.aktutor.in
Microprocessor & Microcontroller 1–13 B (EC-Sem-5)
Answer
Address lines to address 8 K byte of memory are
8 K = 23 × 1024 = 23 × 210 = 213
So, 13 address lines are necessary to address 8 K byte of memory.
Answer
1. Input/Output devices are the devices by which microprocessor
communicates with the outside world.
2. The microprocessor accepts data in form of binary digits as a input from
the devices such as keyboard, and A/D converters and it sends data to
the output devices such as LEDs or printers.
3. There are two types of input/output devices :
A. I/O with 8-bit addresses (peripheral-mapped I/O) :
1. In this type of input/output devices, 8 address lines are used to identify
an input or output device, this is known as peripheral mapped I/O (also
known as I/O mapped I/O).
2. This is an 8-bit numbering system for I/O used in conjunction with
input and output instruction. This is also known as I/O space which is
16-bit numbering system.
3. The 8 address lines can have 256 addresses. Thus, microprocessor can
identify 256 input and 256 output devices with an address ranging
from 00H to FFH.
4. The microprocessor uses I/O read control signals for the input devices
and I/O write control signal for output devices.
B. I/O with 16-bit addressing (memory-mapped I/O) :
1. In this type of I/O, 16 addressing lines are used by the microprocessor
to identify an I/O device.
2. An I/O device is connected as if it is a memory register. This is known
as memory-mapped I/O. The microprocessor uses same control signal
and instructions as those of memory.
3. In some microprocessor, all I/Os have 16-bit addresses : I/O and memory
share same memory map.
4. The entire range of memory-mapped I/O address is from 0000 H to
FFFF H.
Introduction to Microprocessor 1–14 B (EC-Sem-5)
www.aktutor.in
PART-3
The 8085 MPU-Architecture, Pins and Signals, Timing Diagrams,
Logic Devices for Interfacing, Memory Interfacing.
Questions-Answers
Que 1.13. Explain the pin configuration of 8085 MPU with neat
diagram.
Answer
Pins of 8085 : The signals of 8085 can be classified into seven groups
according to their functions.
Serial +5V GND
X1 1 40 VCC
I/O
X2 2 39 HOLD Ports 1 2 40 20
SID 5 X1 X2Vcc Vss
RESET OUT 3 38 HLDA
Externally initiated signals
SOD 4 28
SOD 4 37 CLK(OUT) A15 High-order
TRAP 6
SID 5 36 RESET IN A8 address bus
RST7.5 7 21
TRAP 6 35 READY
RST 6.5 8 19
RST 7.5 7 34 IO/M AD0
RST 5.5 9
RST 6.5 8 33 S1 Multiplexed
INTR 10 address/data
RST 5.5 9 32 RD READY 35 bus
AD7
INTR 10 31 WR HOLD 39 12
INTR 11 30 ALE RESET IN 36
AD0 12 29 S0
acknowledgement
External signal
AD1 13 28 A15 30
INTA11 ALE
AD2 A14 29 Control
14 27 S0
HLDA 36 33 and
AD3 15 26 A13 S1
34
IO/M status
AD4 16 25 A12 32 signals
32 RD
AD5 17 24 A11 WR
AD6 18 23 A10
AD7 19 22 A9
3 37
VSS 20 21 A8
RESET OUT CLK OUT
b. RD and WR :
i. These signals are basically used to control the direction of the data flow
between processor and memory or I/O device/port.
ii. A low on RD indicates that the data must be read from the selected
memory location or I/O port via data bus.
iii. A low on WR indicates that the data must be written into the selected
memory location or I/O port via data bus.
Answer
A. Pins of 8085 : Refer Q. 1.13, Page 1–14B, Unit-1.
B. Internal architecture or functional block diagram : The 8085 is
an 8-bit, general-purpose microprocessor that is ideally suited to many
applications. Fig. 1.14.1 shows the architecture of 8085.
Microprocessor & Microcontroller
www.aktutor.in 1–17 B (EC-Sem-5)
Answer
Flag register : It is 8-bit register in which five bits carry significant
information in form of flags as shown in Fig. 1.15.1.
D7 D6 D5 D4 D3 D2 D1 D0
S Z × AC × P × CY
Fig. 1.15.1. Flag register.
1. S (Sign flag) :
i. After the arithmetic or logical operations, if bit D7 of the result is 1, the
sign flag is set.
ii. In a given byte if D7 is 1, the number will be viewed as negative number.
iii. If D7 is 0, the number will be considered as positive.
Introduction to Microprocessor 1–20 B (EC-Sem-5)
www.aktutor.in
Example 1 :
85 H = 10000101
1E H = 00011110
A3 H = 10100011
Since, 8th bit of the result is 1, so the number is negative.
2. Z (Zero flag) :
i. The zero flag sets, if the result of operation in ALU is zero and flag reset
if the result is non-zero.
ii. The zero flag is also set if a certain register content becomes zero
following an increment and decrement operation of that register.
Example 2 : XRA A ;
It set the zero flag because this operation reset the content of A.
3. AC (Auxiliary carry flag) :
i. This flag is set if there is overflow out of bit 3, i.e., carry from lower
nibble to higher nibble (D3 to D4 bit).
ii. This flag register is used for BCD operations and not available for
programmer.
In Example 1, the carry is generated at 4th bit of the result, hence
AC = 1.
4. P (Parity flag) :
i. Parity is defined by the number of 1’s present in the accumulator.
ii. After arithmetic or logic operation if the result has an even number of
1’s, i.e., even parity, the flag is set.
iii. If the parity is odd, flag is reset.
Example 3 :
38 H = 00111000
Since, the number of 1’s is odd, hence the parity flag is zero, i.e., P = 0.
5. CY (Carry flag) :
i. The flag is set if there is an overflow out of bit 7.
ii. The carry flag also serves as a borrow flag for subtraction.
iii. In both the examples shown below carry flag is set.
ADDITION SUBTRACTION
9B H 89 H
+ 75 H – AB H
Carry 1 10 H Borrow 1 DE H
Answer
i. Instruction cycle and machine cycle :
1. Instruction cycle consists of opcode fetch followed by an execute cycle.
2. The execute cycle itself consists of zero or more fetch cycles which may
be required to fetch the operand.
3. All these operations are performed in different time slots known as
machine cycles.
4. An instruction cycle may consist of more than one machine cycles.
5. The first of these is always the opcode fetch cycle. Some instruction,
which require register to register transfer inside the microprocessor,
may be executed in one machine cycle, where as some which require
data transfer between microprocessor and memory or input/output device
may used more than one machine cycle.
6. Fig. 1.16.1 exhibits instruction cycle and machine cycle within it. It
shows two machine cycles M1 and M2.
7. M1 in which opcode is fetched and decoded consist of four state.
8. M2 consists of three states, the data contained in the next byte of
instruction is fetched and instruction executed.
Time
Fig. 1.16.1. A typical instruction cycle.
Instruction cycle
T-state T-state Tf
Tr
1 Clock cycle
(a) Ideal ( b) Practical
Fig. 1.16.3. Clock signal representation.
8. A typical timing diagram showing ALE activation and its period (T-state)
is shown in Fig. 1.16.4.
T1 T2 T3 T4 T1 T2 T3
ALE
Answer
A. Importance of ALE :
1. ALE is used to indicate the beginning of any operation.
Microprocessor & Microcontroller
www.aktutor.in 1–23 B (EC-Sem-5)
Answer
74LS32
IO/M MEMR
RD
WR MEMW
IOR
8085 p 74LS04
IOW
Fig. 1.18.1. Generation of Read/Write control signals for memory and I/O.
3. Fig. 1.18.1 shows that four different control signals are generated by
combining the signals RD , WR and IO/ M .
Introduction to Microprocessor 1–24 B (EC-Sem-5)
www.aktutor.in
4. The signal IO/ M goes low for the memory operation. This signal is
ANDed with RD and WR signals by using the 74LS32 quadruple two-
input OR gates, as shown in Fig. 1.18.1.
5. The OR gates are functionally connected as negative NAND gates. When
both input signals go low, the outputs of the gates go low and generate
MEMR (memory read) and MEMW (memory write) control signals.
signals to generate IOR (I/O read) and IOW (I/O write) control signals.
Answer
A. Tri-state devices :
1. These are the devices which have three logic states, i.e., logic 0, logic 1
and high input impedance.
2. These devices have enable line, when activated they work like ordinary
logic devices, but when the enable line is disabled then the logic devices
switch into high impedance state and behave as they are disconnected
from the system.
Enable Enable
Active high Active low
Fig. 1.19.1. Tri-state inverter with active high and active low.
B. Buffer :
1. It is a logic circuit that amplifies the current or power. It has one input
and one output line.
2. It provides the same logic level at the output that is applied at the input.
3. Generally, it is used to increase the driving capability of the logic circuit
hence known as driver.
www.aktutor.in
Microprocessor & Microcontroller 1–25 B (EC-Sem-5)
Enable
Active low
(a) (b )
Fig. 1.19.2. A buffer.
C. Decoder :
1. Decoder is a logic circuit that identifies combination of signals that are
applied at the input.
2. In decoder if there are n input lines then at the output there are 2n
output lines.
3. Suppose there is 3 × 8 decoder, i.e., there are 3 input lines then there are
23, i.e., 8 possible combination which are identified by 0 to 7 output lines.
4. If 111 is applied at the input then the output at 7 will be 1 and all others
will remain at logic zero.
0
1
A2 2
3 Input A1 3 2 3 Output
4
A0 5
6
7
Que 1.20. What are the timing diagrams for memory read and
memory write cycle ?
Answer
1. The main function of interfacing is that microprocessor should be able
to read from and write into the given register or a memory chip.
2. To perform these operations microprocessor should be able to do
following functions :
i. Select the chip.
ii. Identify the register.
iii. Enable the appropriate buffer.
3. To understand the interfacing concept, consider the timing diagram of
memory read operation of microprocessor 8085.
i. Microprocessor places a 16-bits address on the address bus and with this
address only one register is to be selected. From Fig. 1.20.1, it is clear
that only 11 address lines are required to identify 2048 registers.
ii. Therefore, lower order address lines A10 – A0 of microprocessor address
bus is connected with memory chip. The internal decoder of the memory
chip will identify and select the register for the EPROM.
EPROM
A11
Internal Decoder
4096 × 8
A0
CS
Output Buffer
RD
Output
Data
Fig. 1.20.1.
iii. The remaining address lines (A15 – A11) of 8085 should be decoded to
generate a (chip select) signal which is unique to that combination of
address logic.
Microprocessor & Microcontroller
www.aktutor.in 1–27 B (EC-Sem-5)
iv. The two signals IO / M and RD are provided by 8085 to indicate memory
IO/M M
RD
MEMR
T1 T2 T3
CLK
IO/M M
WR
MEMW
Answer
Answer
1. Fig. 1.22.1 shows the desired memory system using IC 2764 (8K) EPROM
and 6264 (8K) SRAM memory requires 13 address lines (A0 – A12) since
213 = 8K.
Microprocessor & Microcontroller
www.aktutor.in 1–29 B (EC-Sem-5)
+5 V
D0 Q0 D1 Q1
CLK CLK
+5 V
Q0 Q1
R V Ready A
CC 15
Reset A8
C AD 7 L
SW A A0
AD0
CLK T A15
ALE C
H
D0
8085 D7
+5 V
CLKOUT G1
D
E MEMW
RD A C MEMR
O
WR B D IOR
E
m/IO C G RG IOW
X1 X2 1 2
D0 – D7 OE A0 – A12 D0 – D7 OE WR A0 – A12
EPROM (8K) RAM(8K)
CS CS
15 pF
+5 V
V CC G1
Y0
D
A13 E
A C Y1
A14
B O
A15 D
C
E
G1 R
G 2 GND
Fig. 1.22.1.
2. The remaining address lines (A13 – A15) are decoded to generate chip
select (CS) signals. IC 74LS138 is used as decoder.
3. When (A15 – A13) address lines are zero, the Y0 output of decoder goes
low and selects the EPROM.
4. This means that A15 – A13 address lines must be zero to read data from
EPROM. The address lines A0 – A12 select the particular memory location
in the EPROM when A15 – A13 lines are zero.
5. Similarly when address lines A15 – A13 are 001, the Y1 output of decoder
goes low and selects the RAM.
Introduction to Microprocessor 1–30 B (EC-Sem-5)
www.aktutor.in
Table 1.22.1. Memory map.
Memory ICs A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0 Address
Starting 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0000H
address of
EPROM
End 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1FFFH
address
of EPROM
Starting 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 2000H
address of
SRAM
End 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3FFFH
address
of SRAM
Answer
Input/output read and input/output write cycle :
1. The I/O read and I/O write machine cycles are similar to the memory
read and memory write machine cycles, respectively, except that the
IO/ M signal is high for I/O read and I/O write machine cycles.
I/O Read
T1 T2 T3
CLK
ALE
A15 – A8 I/O Addr
2. Here high IO/ M signal indicate that it is an I/O operation. Fig. 1.23.1
and Fig. 1.23.2 show the timing diagrams for I/O read and I/O write
cycles respectively.
www.aktutor.in
Microprocessor & Microcontroller 1–31 B (EC-Sem-5)
I/O Write
T1 T2 T3
CLK
WR
Answer
i. ADD B :
OPCODE FETCH
T1 T2 T3 T4
CLK
PCH PC = PC + 1
High-order Unspe-
A15 – A8 cified
memory address
PC L
Low-order
AD7 – AD 0 memory Opcode
address
ALE
IO / M
IO / M = 0, S 0 = 1, S 1 = 1
S0 – S1
RD
Fig. 1.24.1.
ii.
OPCODE FETCH MEMORY READ MEMORY READ MEMORY WRITE MEMORY WRITE
T1 T2 T3 T4 T5 T6 T1 T2 T3 T1 T2 T3 T1 T2 T3 T1 T2 T3
PC = PC + 1
PCH PC = PC + 1 PCH PC = PC + 1 PCH SP = SP – 1 SPH SP = SP – 1 SPH
High-order High-order High-order High-order High-order
(20H) Unspecified (20H) (20H) (20H) (20H)
CALL 2050H :
ALE
Fig. 1.24.2.
IO/M
IO/M = 0, S0 = 1, S1 = 1 IO/M = 0, S0 = 0, S1 = 1 IO/M = 0, S0 = 0, S1 = 1 IO/M = 0, S0 = 1, S1 = 0 IO/M = 0, S0 = 1, S1 = 0
www.aktutor.in
S0 – S1
RD
WR
1–32 B (EC-Sem-5)
www.aktutor.in
Microprocessor & Microcontroller 1–33 B (EC-Sem-5)
Answer
Instruction : STA 3500 H
Timing diagram :
Opcode fetch Memory read I/O read
T1 T2 T3 T4 T5 T6 T7 T8 T9 T10
CLK
ALE
RD
WR
Fig. 1.25.1.
PART-4
Interfacing Output Displays, Interfacing Input Devices,
Memory Mapped I/O.
Questions-Answers
E C
D DP
Fig. 1.26.1. Seven-segment LED : LED segments.
7. Consider a seven segment LED that is connected using 3:8 decoder. The
circuit diagram is shown in Fig. 1.26.2.
8. Now if we want to display digit 7 on the LED then in common anode
seven segment LED, logic 0 is required to be turn ON the segment. The
binary code should be equal to 78H.
Data lines D7 D6 D5 D4 D3 D2 D1 D0
Bits × 1 1 1 1 0 0 0 = 78 H
Segments NC G F E D C B A
+5V
20 10 GND
D7 3 2 5
NC 330 NC
D6 4 5 10
Latch
D5 7 6 9
A6 D4 8 9 1 3/8
A5 A7 D3 13 12 2 +5V
A4 D2 14 15 4
A3 16 6
A3 D1 17
D0 18 19 7
MSB E E E LE OE
A2 1 2 3
O5
A1 3-to-8 11 Current Common anode
A0 Decoder limiting seven-segment
IOSEL
resistors LED
IO/M IOW
WR
Fig. 1.26.2. Interfacing seven-segment LED using 3:8 decoder.
Microprocessor & Microcontroller
www.aktutor.in 1–35 B (EC-Sem-5)
Answer
1. Interfacing of input device is similar to that of output device except that
there is difference in bus signals and circuit components.
2. Consider an eight DIP switches interfaced using 3:8 decoder. The circuit
used for interfacing eight DIP switches is shown in Fig. 1.27.1.
3. The 3 : 8 decoder is used to decode low order bus and tri-state buffer is
used to interface the switches with data bus. The port can be accessed
with address 84 H however it has multiple address.
4. The device has two groups of four buffers each and they are controlled
by active low signals OE .
5. When OE is low the input data shown up on the output lines and when
OE signal is high, the output lines assumes high impedance state.
+5V
1 S7
D7
Octal 1 S6
A6 A7
buffer 1 S5
A5 1 S4
Data S3
Bus 1
E E E
A2 MSB A 1 2 3 0 S2
2 0 S1
A1 IOADR
A1 3 : 8 D0 0 S0
Decoder O4
A0 A0 OE
LSB
IOSEL
IO/M
IOR
RD
Fig. 1.27.1. Interfacing DIP switches.
Introduction to Microprocessor 1–36 B (EC-Sem-5)
www.aktutor.in
6. The low order address bus, except the lines A4 and A3, is connected to
the decoder. The address lines A3 and A4 are left in don’t care state.
7. The output line O4 of the decoder goes low when the address bus has
following address
A7 A6 A5 A4 A3 A2 A0 A1
1 0 0 0 0 1 0 0 = 84 H
9. When the address is 84 H and control signal IOR is asserted, the I/O
select the pulse enable tri-state buffer and logic levels of the switches
are placed on data bus. The 8085 then begins to read switch position and
places the reading in accumulator.
Answer
1. In memory-mapped I/O, the input and output devices are assigned and
identified by 16-bit addresses. To transfer data between the MPU and
I/O devices, memory related instructions (such as LDA, STA, etc.) and
memory control signals ( MEMR and MEMW ) are used.
Memory Machine
address code Mnemonics Comments
2050 32 STA 8000H ; Store the content of accumulator
in memory location 8000H
2051 00
2052 80
5. The instruction LDA (Load accumulator direct) transfers the data from
a memory location to the accumulator. The instruction LDA is a 3-byte
instruction.
6. To use memory-related instructions for data transfer the control signals
Memory read ( MEMR ) and Memory write ( MEMW ) should be
connected to I/O devices instead of IOR and IOW signals and the 16-bit
address bus (A15 – A0) should be decoded.
IO/M
RD
WR
MEMW
Microprocessor & Microcontroller
www.aktutor.in 2–1 B (EC-Sem-5)
2 Basic Programming
Concepts
CONTENTS
Part-1 : Flow Chart Symbols, .................................. 2–2B to 2–9B
Data Transfer
Operations, Arithmetic
Operations, Logic Operations,
Branch Operation
CONCEPT OUTLINE
• A flow chart is a diagrammatic representation of the procedure
for solving the problem.
• The data transfer instructions copy data from a source into a
destination without modifying the contents of the source.
Questions-Answers
Answer
A. Flowchart :
1. A flowchart is a diagrammatic representation of the procedure for solving
the problem.
2. It is a pictorial representation that a programmer uses for planning the
procedure for solution of problems.
3. Once developed and thoroughly checked, the flowchart provides an
excellence guide for writing a program.
4. It indicates the direction of flow of a process, relevant operation and
computation, point of decision and other information which is part of
solution.
B. Steps to develop a flow chart :
1. Gather information of how the process flows by the use of :
a. Conservation
b. Experience
c. Product development codes
2. Trail process flow.
3. Allow other more familiar personnel to check for accuracy.
4. Make changes if necessary.
5. Compare final actual flow with best possible flow.
Microprocessor & Microcontroller
www.aktutor.in 2–3 B (EC-Sem-5)
(subroutine).
6. Circle with alphabet : It indicates continuation.
A : Any alphabet A
Answer
Start
End
Fig. 2.2.1.
Answer
A. Data transfer instructions : These are the instructions used to
copy the data from one memory location or register to another memory
location or register.
Basic Programming Concepts 2–4 B (EC-Sem-5)
www.aktutor.in
B. Intructions :
1. MOV (Move) : This instruction copies the content of source register to
the destination register. If one of the operand is a memory location, it
is specified by contents of HL register.
Format : MOV Source, Dest.
2. MVI (Move immediate data) : This instruction is used to move
immediate data into the specified register.
Format : MVI R, 8-bit data
3. LXI (Load register pair immediate) : This instruction load 16-bit
data in the register pair B-C, D-E and H-L with the data byte available
immediately.
Format : LXI RP, 16-bit address
4. LHLD (Load H and L register direct) : This instruction copies the
contents of memory location pointed by 16-bit address in register L and
copies the contents of next memory location in register H.
Format : LHLD 16-bit address
5. LDA (Load accumulator direct) : This instruction copies the data of
given memory location in accumulator.
Format : LDA 16-bit address
6. LDAX (Load accumulator indirect) : This instruction copies the
contents of memory location whose address is specified by register pair
into the accumulator. The register pair is used as a memory pointer.
Format : LDAX RP
7. SHLD (Store H and L register direct) : This instruction stores the
contents of L register in the memory location given within the
instruction and content of H register at address next to it.
Format : SHLD 16-bit address
8. STA (Store accumulator direct) : The contents of accumulator is
copied into memory location specified by operand.
Format : STA 16-bit address
9. SPHL (Copy HL registers to stack pointer) : This instruction loads
the contents of register H and L into stack pointer. The content of H
register provides the higher order address and content of L register
provides lower order address.
Format : SPHL
10. STAX (Store accumulator indirect) : The contents of accumulator
are copied into memory location specified by register pair.
Format : STAX RP
Que 2.4. What are the various instructions used for arithmetic
operation in the 8085 microprocessors.
Microprocessor & Microcontroller
www.aktutor.in 2–5 B (EC-Sem-5)
Answer
A. Arithmetic instruction : These are the instructions used for
arithmetic operation like addition, subtraction etc.
B. Instructions :
1. ADD (Add Register data to Accumulator) : This instruction add
the contents of register or memory with the content of accumulator
and result is stored in accumulator.
Format : ADD R/M
2. ACI (Add immediate data to accumulator with carry) : This
instruction add the 8-bit data and carry flag with the accumulator
contents and result is stored in accumulator.
Format : ACI 8-bit data
3. ADC (Add register data to accumulator with carry) : The contents
of register or memory and carry flag are added to contents of
accumulator and result is placed in the accumulator.
Format : ADC R/M
4. ADI (Add immediate data to accumulator) : The 8-bit data are
added to contents of accumulator and result is stored in accumulator.
Format : ADI 8-bit data
5. DAD (Add register pair to H and L register) : This instruction is
used to add the 16-bit contents of specified register with contents of
register pair HL and sum is saved in HL register.
Format : DAD Rp
6. SUB (Subtract register or memory from accumulator) : The
contents of register or memory location specified by operand are
subtracted from the contents of accumulator.
Format : SUB R/M
7. SUI (Subtract immediate data from accumulator) : The 8-bit data
are subtracted from contents of accumulator and result is stored in
accumulator.
Format : SUI 8-bit data
8. SBB (Subtract source and borrow from accumulator) : The
contents of register or memory and the borrow flag are subtracted
from contents of accumulator and result are placed in accumulator.
Format : SBB R/M
9. SBI (Subtract immediate with borrow) : The 8-bit data and borrow
are subtracted from the contents of accumulator.
Format : SBI 8-bit data
10. DAA (Decimal adjus t accumulator) : The conte nts of the
accumulator are change from the binary value to two 4-bits binary
Basic Programming Concepts 2–6 B (EC-Sem-5)
www.aktutor.in
coded decimal digit. This is the only instruction that uses auxiliary flag
to perform binary to BCD conversion.
Format : DAA
11. INR (Increment contents of register / memory by 1) : This
instruction increments the contents of register/memory by 1 and result
are stored in same place.
Format : INR R/M
12. INX (Increment register pair by 1) : This instruction increments the
contents of specified register pair by 1.
Format : INX RP
13. DCR (Decrement source by 1) : The contents of designated register/
memory is decremented by 1 and store the result in same place.
Format : DCR R/M
14. DCX (Decrement register pair by 1) : This instruction decrements
the contents of specified register pair by 1.
Format : DCX RP
Answer
Logical instruction : These are the instructions used to perform the
logical operation like AND, OR, XOR etc.
1. ANA (Logical AND with accumulator) : The contents of accumulator
are logically ANDed with the contents of register or memory location
and result is stored in the accumulator.
Format : ANA R/M
2. ANI (AND immediate with accumulator) : This instruction ANDed
the contents of accumulator with specified 8-bit data and result is placed
in accumulator.
Format : ANI 8-bit data
3. XRA (Exclusive OR with accumulator) : The contents of specified
register/memory location are Exclusive ORed with contents of the
accumulator and result is placed in accumulator.
Format : XRA R/M
4. XRI (Exclusive OR immediate with accumulator) : The 8-bit data
are exclusive ORed with contents of accumulator and result is placed in
the accumulator.
Format : XRI 8-bit data
5. ORA (Logically OR with accumulator) : This instruction logically
ORed the contents of accumulator with contents of register on memory
location.
Format : ORA R/M
Microprocessor & Microcontroller
www.aktutor.in 2–7 B (EC-Sem-5)
Answer
Branching instruction : This group of instruction alters the sequence
of program execution either conditionally or unconditionally.
i. JMP (Jump unconditionally) :
1. The jump instructions specify the memory location explicitly.
2. The program sequence is transferred to memory location specified by
the 16-bit address.
3. This is 3-byte instruction : First byte for operation code and the second
and third byte specific the address. The unconditionally jump
instruction enables the programmer to set up continuous loop.
Format : JMP 16-bit address
PART-2
Writing Assembly Language Programs, Programming
Techniques : Looping, Counting and Indexing.
CONCEPT OUTLINE
• Looping is a programming technique used to instruct
microprocessor to repeat task.
• Indexing means pointing or referencing objects with sequential
number.
Questions-Answers
Answer
1. A program is a set of instructions arranged in the specific sequence to do
the specific task.
2. It tells the microprocessor what it has to do.
3. The process of writing the set of instructions which tells the
microprocessor what to do is called programming.
Basic Programming Concepts 2–10 B (EC-Sem-5)
www.aktutor.in
Steps involved in programming :
i. Specifying the problem : The first step in the programming is to find
out which task is to be performed. This is called specifying the problem.
If the programmer does not understand what is to be done, the
programming process cannot begin.
ii. Designing the problem-solution : During this process, the exact
step by step process that is to be followed, is developed and written
down.
iii. Coding :
1. Once the program is specified and designed, it can be implemented.
Implementation begins with the process of coding the program. Coding
the program means to tell the processor the exact step by step process
in its language.
2. Each processor has a set of instructions. Programmer has to choose
appropriate instructions from the instruction set to build the program.
iv. Debugging : Once the program or a part of program is coded, the next
step is debugging the code. Debugging is the process of testing the code
to see if it does the given task. If program is not working properly,
debugging process helps in finding and correcting errors.
Que 2.8. What are the various types of instructions used in
assembly language programming ? Explain one of them in detail.
AKTU 2015-16, Marks 10
Answer
1. Data transfer instruction related to microprocessor register
and I/O : Refer Q. 2.3, Page 2–3B, Unit-2.
2. Logical instructions related to rotating the accumulator bits :
Refer Q. 2.5, Page 2–6B, Unit-2.
3. 16-bit arithmetic instructions :
a. ADD M (Add memory data to the accumulator) : This instruction
add the contents of memory location specified by the HL register pair
with accumulator and the result are stored in accumulator.
Format : ADD M
b. SUB M (Subtract memory content from accumulator) : This
instruction subtracts the contents of memory location specified by register
pair HL and stores the result into accumulator.
Format : SUB M
c. INR M (Increment contents of memory by 1) : This instruction
increment the contents of memory location by 1. The memory location
is specified by register pair HL. After execution of this instructions all
flags are affected except carry flag.
Format : INR M
Microprocessor & Microcontroller
www.aktutor.in 2–11 B (EC-Sem-5)
Answer
1. Looping is a programming technique used to instruct microprocessor
to repeat tasks.
2. A loop is set up by instructing the microprocessor to change the sequence
of execution and perform the task again.
3. This process is done using jump instruction. Loops are classified into
two groups :
i. Continuous loop : Unconditional jump instructions are used to set
up these loop. A program with this type of loop does not stop until the
system is reset.
Start
Perform task
Start
Is
No counter
=0
?
Yes
Stop
Fig. 2.9.2.
Basic Programming Concepts 2–12 B (EC-Sem-5)
www.aktutor.in
4. Counter : A counter is a application of conditions loop. If the
microprocessor has to perform a certain repeated task for fix number
of times then task is performed using counter and conditional loop.
Using conditional loop the task is performed repeatedly and by using
the counter number of times, the task is to be performed is counted.
5. Conditional loop using counting and indexing :
i. Indexing means pointing or referencing objects with sequential number.
ii. For example, in library, books are arranged according to numbers and
they are sorted according to numbers. This is known as indexing,
similarly data bytes are stored in memory location and these data bytes
are referred to by their memory location.
Answer
Let an 8-bit number is stored in memory at 2200 H.
LDA 2200 H ;
Get the number
MOV B, A ;
Move content of register A to register B
MVI A, FF H ;
Load register A with the data FF H
SUB B ;
Subtract content of register B from content of register A
(we obtained 1’s complement of the number stored in
register A)
ADI, 01 H ; Add 1 in the number
STA 2300 H ; Store the result
HLT ; Terminate program execution.
PART-3
Additional Data Transfer and 16-bit Arithmetic Instruction,
Logic Operation : Rotate, Compare.
Questions-Answers
Answer
A. 16-bit data transfer to register pair (LXI) :
1. LXI RP, 16-bit : This instruction loads 16-bit data in the register pair.
Register pair can be BC, DE and HL. It is a 3-byte instruction.
Example : LXI D, 2070 H
2. LXI SP, 16-bit : This instruction loads 16-bit data in the stack pointer
register.
Example : LXI SP, 0317 H
B. Data transfer from memory to the microprocessor :
1. MOV R, M : This instruction copies the data byte from memory location
into a register. It is a 1-byte instruction. R can be A, B, C, D, E, H and L
and M is specified by the content of HL register.
2. LDAX B/D : It is a 1-byte instruction which copies the data byte from
memory location into the accumulator. Memory location can be specified
by the content of registers BC or DE.
3. LDA 16-bit : It is a 3-byte instruction which copies the data of given
memory location into accumulator.
Example : LDA 3757 H
C. Data transfer from microprocessor to memory or directly into
memory :
1. MOV M, R : This is a 1-byte instruction that copies data from a register
R, into the memory location specified by the content of HL registers.
2. STAX B/D : The contents of accumulator are copied into memory
location specified by the register pairs. It is a 1-byte instruction.
3. STA 16-bit : It is a 3-byte instruction that copies data from accumulator
into the memory location specified by the 16-byte operand.
4. MVI M, 8-bit : It is a 2-byte instruction that copies 8-bit data into
memory location specified by HL register pair from the accumulator.
Answer
These are the instructions which perform arithmetic task related to
memory such as ADD M, INR M etc.
i. ADD M (Add memory data to the accumulator) : This instruction
add the contents of memory location specified by the HL register pair
with accumulator and the result are stored in accumulator.
Format : ADD M
ii. SUB M (Subtract memory content from accumulator) : This
instruction subtracts the contents of memory location specified by
register pair HL and stores the result into accumulator.
Format : SUB M
Basic Programming Concepts 2–14 B (EC-Sem-5)
www.aktutor.in
iii. INR M (Increment contents of memory by 1) : This instruction
increment the contents of memory location by 1. The memory location
is specified by register pair HL. After execution of this instructions all
flags are affected except carry flag.
Format : INR M
iv. DCR M (Decrement contents of memory by 1) : This instruction
decrease the contents of memory location specified by register pair HL
by 1.
Format : DCR M
v. INX RP : It is a 1-byte instruction. It treats the contents of two register
as one 16-bit number and increases the contents by 1.
RP can be BC, DE, HL and stack pointer.
Format : INX RP
vi. DCX RP : It is a 1-byte instruction. It decreases the 16-bit contents of a
register pair by 1. RP can be B, D, H and SP (stack pointer).
Format : DCX RP
Answer
Rotation instructions are primarily used in arithmetic, multiply and
divide operation. These operations include instructions such as RAR,
RRC, RAL and RLC.
i. RLC (Rotate accumulator left) : This instruction rotates the contents
of accumulator left by one position. Bit D7 is placed in the position of D0
as well as in the carry flag.
CY
0
D7 D6 D5 D4 D3 D2 D1 D0
A= 1 0 1 0 1 0 1 0 AA H
CY
0
D7 D6 D5 D4 D3 D2 D1 D0
A= 1 0 0 0 0 0 0 1 81 H
Answer
The microprocessor 8085 includes two instructions CMP and CPI.
These two instructions are used to compare data byte with contents of
accumulator by subtracting the data byte or content of memory from
accumulator and indicating the result by modifying the flags. However
contents are not modified.
i. CMP R/M (Compare with accumulator) : This instruction compares
the contents of specified register or memory location with the contents
of accumulator and both the contents are preserved and comparison is
shown by setting the flags.
If (A) < (Reg/Mem) : Carry flag is set and zero flag is reset.
If (A) = (Reg/Mem) : Zero flag is set and carry flag is reset.
If (A) > (Reg/Mem) : Carry and zero flags are reset.
Example : Register B contains data byte 62H and accumulator contains
data byte 57H. Compare the contents of register B with those of
accumulator.
Instruction: CMP B
Before instruction After instruction
A 57 ×× Z A 57 0 Z
B 62 ×× C B 62 1 C
Flag : S = 1, Z = 0, AC = 1, P = 1, CY = 1
Fig. 3.14.1.
Answer
LXI H, 2050 H ; Set up HL as a pointer for the source memory.
LXI D, 2070 H ; Set up DE as a pointer for the destination memory.
MVI B, 10 H ; Set up B as byte counter
NEXT : MOV A, M ; Get data byte from the source memory
STAX D ; Store the data byte in destination memory
INX H
INX D ; Get ready to transfer next byte
DCR B
JNZ NEXT ; Go back to get next byte if byte counter 0
HLT ; End of program
PART-4
Counters and Time Delays, 8085 Interrupts.
Questions-Answers
Que 2.16. Write a short note on counter and time delay operation
in microprocessor.
Answer
A. Counters :
1. Counters are mainly used to keep track of events.
2. It can be designed by loading an appropriate number into any one register
of microprocessor and then using INR or DCR instructions.
Basic Programming Concepts 2–18 B (EC-Sem-5)
www.aktutor.in
3. Whenever a loop is established using a register, end count is updated
then every time count is checked to determine whether it has reached
the required number and if not then loop is repeated again.
4. Fig. 2.16.1 shows the flow chart of counter operation.
Initialize
Display
Update counter
No Is this
final count
?
Yes
Fig. 2.16.1. Flow chart of a counter.
B. Time delay :
1. This is used to perform ‘NOP’ means no operation as real time
applications such as traffic light, digital clock etc., requires some delay
during their application.
2. Time delay can be generated using execution of instruction several
times.
3. The flowchart in Fig. 2.16.2 shows the generation of time delay.
Load delay register
Decrement register
Is
No
register = 0
?
Yes
Fig. 2.16.2. Time delay loop flow diagram.
Answer
A. Timer delay using one register :
1. A count is loaded in a register and loop is executed until the count
reaches zero.
2. The instruction is as follow :
Microprocessor & Microcontroller
www.aktutor.in 2–19 B (EC-Sem-5)
Number of T-states
MVI C, count ; Load count 7 T-states
BACK : DCR C ; Decrement count 4 T-states
JNZ BACK ; If count 0, repeat 10/7 T-states
3. The instructions DCR C and JNZ BACK execute number of times
equal to count stored in the C register.
4. The time taken by this program for execution can be calculated with
the help of T-states.
5. There are count – 1 passes through the loop where the condition is met
and control is transferred back to the first instruction in the loop
(DCR C).
Total T-states required to execute the given program
= 7 + (count – 1) × (4 + 10) + (4 + 7)
MVI C Loops Last Loop
For count = 5
Number of T-state = 7 + (5 – 1) × (14) + (11) = 7 + 56 + 11 = 74
Assuming operating frequency of 8085A is 2 MHz,
1
Time required for 1 T-state = = 0.5 sec.
2 MHz
6. Total time required to execute the program = 74 × 0.5 sec, = 37 sec
The maximum count that can be loaded in the 8-bit register is FF H (255)
so the maximum delay possible with 8-bit count, assuming operating
frequency 2 MHz.
= (7 + (255 – 1) × (14) + (11)) × 0.5 sec.
= 1787 sec.
B. Time delay using a register pair :
Number of T-states
LXI B, count ; Load 16 bit count 10 T-states
BACK : DCX B ; Decrement count 6 T-states
MOV A, C ; 4 T-states
ORA B ; Logically OR B and C 4 T-states
JNZ BACK ; If result is not 0, repeat 10 T-states
1. The instructions DCX B, MOV A, C; ORA B and JNZ BACK execute
number of times equal to count stored in BC register pair.
2. The instruction LXI B, count; is executed only once. It requires 10
T-states. The number of T-states requited for one loop
= 6 + 4 + 4 + 10 + = 24 T-states.
Basic Programming Concepts 2–20 B (EC-Sem-5)
www.aktutor.in
3. The number of T-states required for last loop = 6 + 4 + 4 + 7 = 21
T-states. So total T-states required for execution of given program are
= 10 + (count – 1) × 24 + 21
LXI B Loops Last Loop
For count = 03FF H (102310)
Number of T-state = 10 + (1022) × 24 + 21
= 24559
4. Assuming operating frequency of 8085A as 2 MHz, the time required for
one T-state = 0.5 sec.
Total time required to execute the given program
= 24559 × 0.5 sec = 12279.5 sec
= 12.2795 msec
C. Timer delay using nested loops :
1. In this, there is more than one loop. The outer loop sets the multiplying
count to the delays provided by the innermost loop.
Number of T-states
MVI B, Multiplier count ; Initialize multiplier 7 T-states
START : MVI C, Delay count ; Initialize delay count 7 T-states
BACK : DCR C ; Decrement delay count 4 T-states
JNZ BACK ; If not 0, repeat 10/7 T-states
DCR B ; Decrement multiplier count 4 T-states
JNZ START ; If not 0, repeat 10/7 T-states
2. T-states required for execution of inner loop
Tinner = 7 + (Delay count – 1) × 14 + 11
3. T-states required for execution of the given program
= (Multiplier count – 1) × (Tinner + 14) + 11
For delay count = 65 H (101) and multiplier count = 51 H (81)
Tinner = 7 + (101 – 1) × 14 + 11
= 1418
4. Total time required to execute the given program is (Operating frequency
is 2 MHz) = [(81 – 1) × (1418 + 14) + 11] × 0.5 sec.
= 57.2855 msec.
Answer
1. In 8085, the operating frequency is half of the crystal frequency.
2. Operating frequency = 6/2 = 3 MHz
1
3. Time for one T-state = = 0.33 sec
3 MHz
4. Number of T-states required
Required time 0.5 msec
= =
Time for one T- state 0.33 sec
= 1500
5. Delay routine :
LXI B, Count ; 16-bit count
BACK : DCX B ; Decrement count
MOV A, C
ORA B ; Logically OR B and C
JNZ BACK ; If result is not zero repeat.
6. Count calculation :
1500 = 10 + (count – 1) × 24 + 21
1500 31
Count = 1 (62)10
24
Count = 3E H
Answer
1. Clock frequency = 5 MHz = 5 × 106 Hz
1 1
2. Time, T = = 0.2 × 10 – 6 = 0.2 s
frequency 5 106
3. Time required to execute an instruction of 18 T-states = 0.2 × 18 = 3.6 s
Answer
The debugging techniques are used to check the errors in a counter program.
Various errors which may occur in the programs are :
1. Errors in counting T-states in a delay loop. Most of the times, first
instruction to load a delay register is included in loop by mistake.
2. Errors in calculating how many times a loop is repeated.
3. Failure to convert a delay count from a decimal number into its equivalent
hexadecimal number.
Basic Programming Concepts 2–22 B (EC-Sem-5)
www.aktutor.in
4. Error in converting a delay count from a decimal number to its
hexadecimal equivalent or vice-versa.
5. Specifying a wrong jump location.
6. Failure to set a flag, especially with 16-bit decrement / increment
instruction.
7. Failure to display either the first or last count.
8. Failure to provide a delay between the last and the last-but-one count.
Answer
1. In 8085, interrupt enabled flip-flop controls the interrupt process.
2. This flip-flop can be set or reset using software instruction. If the
flip-flop is enabled and the input to the interrupt signal (INTR) goes
high, the microprocessor is interrupted.
3. This is maskable interrupt and can be disabled using software
instruction.
4. There are eight necessary steps required to describe interrupt process
of microprocessor 8085.
i. Using interrupt Enable Instruction (EI), interrupt process can be used.
ii. During execution of program, microprocessor checks INTR line during
execution of each instruction.
iii. If the INTR line is high and interrupt is enabled, the microprocessor
completes the execution of current instruction and disable the interrupt
enable flip-flop and send interrupt acknowledge signal ( INTA ). Until
the interrupt flip-flop is enabled again, the processor cannot accept
any interrupt request.
iv. This INTA signal is used to insert a restart (RST) or a CALL instruction
through external hardware. This RST instruction transfers the program
control to a specific memory location on page 00 H and start the execution
at that memory location after executing step (v).
v. Whenever RST or CALL instruction is received by the microprocessor,
it saves the memory address of next instruction on the stack. Then,
the program is transferred to the CALL instruction.
vi. The task to be performed is written as a subroutine at the specified
location. The microprocessor performs the task. This subroutine is
called as service routine.
vii. The service subroutine should include EI to enable the interrupt again.
viii. At the end of subroutine, the RET instruction retrieve the memory
address, where the program was interrupted and continues the
execution.
Microprocessor & Microcontroller
www.aktutor.in 2–23 B (EC-Sem-5)
Answer
A. Interrupt : The process by which the normal working of 8085 processor
can be interrupted so as to provide service to I/O or perform another
job, is called as an interrupt.
B. Hardware Interrupts :
1. The 8085 has five hardware interrupts, among them four are maskable
(RST 7.5, RST 6.5, RST 5.5 and INTR) and one is non-maskable (TRAP).
2. When any of these pins, except INTR, is active, the internal control
circuit of the 8085 produces a CALL to a predetermined memory location.
i. TRAP : It is non-maskable interrupt. It can’t be disabled by instruction.
In order to service this interrupt the signal on TRAP pin must have
high level. The 8085 completes execution of current instruction, pushes
the program counter on the stack and branches to location 0024 H
(Interrupt address vector for TRAP).
ii. RST 7.5 : It is maskable interrupt. It can be enabled and disabled using
SIM (Set Interrupt Mask) instruction. 8085 respond to RST 7.5 interrupt
when signal on pin has leading edge. In order to service RST 7.5, 8085
complete current execution of instruction, pushes the program counter
on the stack and branches to 003C H.
iii. RST 6.5 : This can be enabled and disabled using SIM instruction.
RST 6.5 is high level sensitive, microprocessor 8085 execute current
instruction save the program counter on to the stack and branches to
location 0034 H.
iv. RST 5.5 : It is maskable interrupt and can be enabled and disabled by
SIM instruction. It is high level sensitive. In order to service this
interrupt, 8085 completes the execution of current instruction, save
the program counter into the stack and branches to location 002C H.
v. INTR :
1. It is a maskable interrupt. Whenever INTR signal is high then 8085
completes its current instruction and send active low interrupt
acknowledge signal INTA if interrupt is enabled.
Que 2.23. What is meant by the software interrupts and why they
are used ? List out all the software interrupts of 8085 and give their
vector addresses.
OR
Explain the role of interrupts in programming. Explain the interrupt
used in 8085. List out all the vectored interrupts of 8085 and give
their vector address. AKTU 2016-17, Marks 7.5
OR
Explain the interrupts used in 8085 briefly.
AKTU 2015-16, Marks 05
Answer
A. Interrupt : Refer Q. 2.21, Page 2–22B, Unit-2.
B. Role of interrupts : Refer Q. 2.21, Page 2–22B, Unit-2.
C. Interrupt in 8085 :
a. Hardware interrupts : Refer Q. 2.22, Page 2–23B, Unit-2.
b. Software interrupts :
1. Software interrupt includes RST 0 to RST 7. These are restart interrupts.
2. In software interrupts the cause of the interrupt is an execution of the
instruction. These are special instructions supporte d by the
microprocessor.
3. After execution of these instructions microprocessor completes the
execution of the instruction it is currently executing and transfers the
program control to the subroutine program.
4. Upon completion of the execution of the subroutine program, program
control returns to the main program.
5. The 8085 has eight software interrupts from RST 0 to RST 7. The vector
address can be calculated as :
Interrupt number × 8 = Vector address
Microprocessor & Microcontroller
www.aktutor.in 2–25 B (EC-Sem-5)
www.aktutor.in
Microprocessor & Microcontroller 3–1 B (EC-Sem-5)
3 16-bit Microprocessor
CONTENTS
Part-1 : 16-bit Microprocessors (8086) : .............. 3–2B to 3–13B
Architecture, Pin Description,
Physical Address, Segmentation,
Memory Organization,
Addressing Modes
PART-1
16-bit Microprocessors (8086) : Architecture, Pin Description,
Physical Address, Segmentation, Memory Organization,
Addressing Modes.
CONCEPT OUTLINE
• 8086 is a 16-bit microprocessor and most of its instructions are
designed to work with 16-bit binary words.
• It provides fourteen 16-bit register.
• It supports the pipelining.
Questions-Answers
Que 3.1. State the features of 8086. Also explain the difference
between microprocessor 8085 and 8086.
Answer
A. Features of 8086 :
1. The 8086 is a 16-bit microprocessor. The arithmetic logic unit, internal
registers and most of its instruction are designed to work with 16-bit
binary words.
2. The 8086 has a 16-bit data bus, so it can read data from memory or
write data to memory and ports either 16-bits or 8-bits at a time.
3. The 8086 has a 20-bit address bus, so it can directly access 220 memory
locations.
4. The 8086 has multiplexed address and data bus which reduces the
number of pins needed, but it slows down the transfer of data.
5. The 8086 requires one phase clock with a 33 % duty cycle to provide
optimized internal timing.
6. It is possible to perform bit, byte, word and block operations in 8086.
7. The 8086 is designed to operate in two modes namely the minimum
mode and the maximum mode.
8. 8086 supports multiprogramming and pipelining.
www.aktutor.in
Microprocessor & Microcontroller 3–3 B (EC-Sem-5)
Answer
The functional signal description of pin diagram of microprocessor 8086
is shown in Fig. 3.2.1.
GND 1 40 VCC
AD 14 2 39 AD15
AD 13 3 38 A16 /S3
AD 12 4 37 A17 /S4
AD 11 5 36 A18 /S5
AD 10 6 35 A19 /S6
AD 9 7 34 BHE/S7
AD 8 8 33 MN/MX
AD 7 9 32 RD
AD 6 10 31 RQ/GT0 (HOLD)
AD 5 11 30 RQ/GT1 (HLDA)
8086
AD 4 12 29 LOCK (WR)
AD 3 13 28 S2 (M/IO)
AD 2 14 27 S1 (DT/R)
AD 1 15 26 S0 (DEN)
AD 0 16 25 QS0 (ALE)
NMI 17 24 QS1 (INTA)
INTR 18 23 TEST
CLK 19 22 READY
GND 20 21 RESET
1. AD15 – AD0 : These are time multiplexed memory I/O address and data
lines which act as address but during first part of machine cycle and
data bus for remaining part of the machine cycle.
16-bit Microprocessor 3–4 B (EC-Sem-5)
www.aktutor.in
2. A19/S6 – A16/S3 : These are used to output upper 4-bits of address
during first part of machine cycle. During remaining part of the machine
cycle these are used to output status, which indicates the type of
operation to be performed.
3. BHE / S7 : (Bus High Enable)/Status : Low signal on this pin during
first part of machine cycle indicates that at least one of the current
transfer is to be made on higher order byte AD15 – AD8, otherwise
transfer is made on low order byte AD7 – AD0.
Status S7 is output during later part of machine cycle.
4. NMI : It is positive edge triggered non-maskable interrupt.
5. INTR : It is maskable level triggered input. It is sampled during the last
clock cycle of each instruction to determine if processor should enter
into interrupt service routine.
6. CLK : It provides basic timing for processor operation and bus control
activity clock frequency depends on version of 8086.
17. WR : This signal is low when 8086 is writing into the memory or I/O
device.
18. HOLD Input, HLDA Output : A high on HOLD pin indicates that
another master is requesting to take over the system bus. On receiving
HOLD signal, processor output HLDA signal high as acknowledgement.
At the same time processor tri-states the system bus. A low on HOLD
gives the system bus control back to the processor. Then output is low
signal on HLDA.
19. QS1, QS0 (Output) : These two output signals reflect the status of the
instruction queue.
QS 1 QS 0 Status
0 0 No operation (queue is idle)
0 1 First byte of an opcode
1 0 Queue is empty
1 1 Subsequent byte of an opcode
S2 S1 S0 Machine cycle
0 0 0 Interrupt acknowledge
0 0 1 I/O Read
0 1 0 I/O Write
0 1 1 Halt
1 0 0 Instruction fetch
1 0 1 Memory read
1 1 0 Memory write
1 1 1 Inactive-passive
16-bit Microprocessor 3–6 B (EC-Sem-5)
www.aktutor.in
21. LOCK : This signal indicates that an instruction with LOCK prefix
being executed and the bus is not to be used by another processor.
22. RQ / GT1 and RQ / GT 0 : In maximum mode, HOLD and HLDA pins
Que 3.3. Draw and explain in detail the architecture of 8086 (pin
Answer
A. Pin diagram : Refer Q. 3.2, Page 3–3B, Unit-3.
B. Architecture :
The internal block diagram of 8086 is shown in Fig. 3.3.1. It is internally
divided into two separate functional units as follows :
Memory Interface
C-Bus
BIU
6
Instruction
5
stream
B-bus 4
byte
ES 3 queue
2
CS
SS 1
DS
IP
Control
system
EU
Address bus
AX AH AL
BX BH BL
Arithmetic
CX CH CL
Logic unit
DX DH DL
SP
BP
SI Operands
DI Flags
Fig. 3.3.1.
1. Bus Interface Unit (BIU) : The bus interface unit is the 8086’s interface
to the outside world. It provides a full 16-bit bi-directional data bus and
www.aktutor.in
Microprocessor & Microcontroller 3–7 B (EC-Sem-5)
20-bit address bus. The bus interface unit is responsible for performing
all following external bus operations :
i. It sends address of the memory or I/O.
ii. It fetches instruction from memory.
iii. It reads data from port/memory.
iv. It writes data into port/memory.
v. It supports instruction queuing.
vi. It provides the address relocation facility.
To implement these functions, the BIU contains the instruction queue,
segment registers, instruction pointer, address summer and bus control
logic.
2. Execution Unit (EU) : The execution unit of 8086 tells the BIU from
where to fetch instructions or data, decodes instructions and executes
instructions. It contains :
i. Control circuitry
ii. Instruction decoder
iii. Arithmetic Logic Unit (ALU)
iv. Registers organization :
a. Flag registers
b. General purpose registers
c. Pointers and index register.
The control circuitry in the EU directs the internal operations. A decoder
in the EU translates the instructions fetched from memory into a series
of actions which the EU performs.
ALU is 16-bit. It can add, subtract, AND, OR, XOR, increment,
decrements, complement and shift binary numbers.
Answer
8086 has a powerful set of registers containing general purpose and
special purpose registers. All the registers of 8086 are 16-bit registers.
A. General data registers :
1. The registers AX, BX, CX and DX are the general purpose 16-bit
registers.
2. Each 16-bit register can be split into two 8-bit registers. Letter L and H
specify the lower and higher bytes.
16-bit Microprocessor 3–8 B (EC-Sem-5)
www.aktutor.in
3. These registers are either used for holding data, variables, and
intermediate results temporarily, or as counters.
SP
AX AH AL CS
P
BX BH BL SS Flags/PSW B
SI
CX CH CL DS
DI
DX DH DL ES
IP
General purpose registers Segment registers Pointer and index
Fig. 3.4.1. registers
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
× × × × O D I T S Z × AC × P × CY
www.aktutor.in
Microprocessor & Microcontroller 3–9 B (EC-Sem-5)
Answer
A. Memory segmentation :
1. In the segmented addressing, on the other hand, the available memory
space is divided into ‘‘chunks’’ called segments. Such a memory is known
as segmented memory.
2. In 8086 system the available memory space is 1 Mbytes. This memory is
divided into number of logical segments.
3. Each segment is 64 Kbytes in size and addressed by one of the segment
registers.
4. The 16-bit contents of the segment register gives the starting/base
address of a particular segment, as shown in Fig. 3.5.1.
16-bit Microprocessor 3–10 B (EC-Sem-5)
www.aktutor.in
Physical address
FFFFF H Highest address
7FFFF H
Top of extra segment
64 K
Answer
A. Advantages of memory segmentation : Refer Q. 3.5, Page 3–9B,
Unit-3.
B. Physical address formulation :
1. For generating a physical address, the content of a segment register
also called as segment address is shifted left bit-wise four times and to
this result, content of an offset register also called as offset address is
added, to produce a 20-bit physical address.
2. For example, if the segment address is 1005 H and the offset is 5555 H,
then the physical address is calculated as follows :
Segment address = 1005 H
Offset address = 5555 H
Segment address = 1005 = 0001 0000 0000 0101
Shifted by 4-bit positions = 0001 0000 0000 0101 0000
Offset address = + 0101 0101 0101 0101
—————————————
Physical address = 0001 0101 0101 1010 0101
Physical address = 155A5 H
So, 155A5 H is the physical address.
Generation of 20-bit address :
1. To access a specific memory location from any segment we need 20-bit
physical address.
2. The 8086 generates this address using the contents of segment register
and the offset register associated with it.
3. The CS register holds the base address of the code segment.
4. The 8086 provides an instruction pointer (IP) which holds the
16-bit address of the next code byte within the code segment.
5. The value contained in the IP is referred to as an offset.
6. This value must be offset from the segment base address in CS to
produce the required 20-bit physical address.
7. The contents of the CS register are multiplied by 16 (10 H), i.e., shifted
by 4 position to the left by inserting 4 zero bits and then the offset, i.e.,
the contents of IP register are added to the shifted contents of CS to
generate physical address.
8. The content of CS register are 348A H, therefore the shifted contents of
CS register are 348A0 H.
9. When the BIU adds the offset of 4214 H in the IP to this starting address,
we get 38AB4 H as a 20-bit physical address of memory.
16-bit Microprocessor 3–12 B (EC-Sem-5)
www.aktutor.in
Top of code CS 3 4 8 A 0 Implied zero
4 2 1 4 (nibble)
segment IP + 4 zero bits
4489F H Physical 3 8 A B 4
address
Code byte
IP = 4214 H 38AB4 H
CS = 348A H Start of code
(a) segment 348A0 H ( b)
Answer
Answer
Addressing modes : Addressing mode indicates a way of locating
data or operands. The addressing modes describe the types of operands
and the way they are accessed for executing an instruction.
The addressing modes for sequential control transfer instructions are
explained as follows :
www.aktutor.in
Microprocessor & Microcontroller 3–13 B (EC-Sem-5)
PART-2
Peripheral Devices : 8237 DMA Controller, 8255
Programmable Peripheral Interface.
16-bit Microprocessor 3–14 B (EC-Sem-5)
www.aktutor.in
Questions-Answers
Answer
1. Direct Memory Access is an I/O technique commonly used for high-
speed data transfer.
2. In status check I/O and interrupt I/O data transfer is relatively slow
because each instruction needs to be fetched and executed.
3. In DMA, the MPU releases the control of the buses to a device called a
DMA controller.
4. The controller manages data transfer between memory and a peripheral
under its control thus bypassing the MPU.
5. The two important signals in DMA controller are :
a. HOLD :
i. This is an active high input signal to the 8085 from another master,
requesting the use of the address and data buses. After receiving the
Hold request, the MPU relinquishes the buses in the following machine
cycle.
ii. All buses are tri-stated and the Hold acknowledge (HLDA) signal is sent
out. The MPU regains the control of the buses after HOLD goes low.
b. HLDA (Hold acknowledge) : This is an active high output signal
indicating that the MPU is relinquishing control of the buses.
6. A DMA controller uses these signals as if it were a peripheral, requesting
the MPU for the control of the buses. The MPU communicates with the
controller by using the chip select line buses and control signals. However
once the controller has gained control, it plays the role of a processor for
data transfer.
7. To perform this function the DMA controller should have :
i. A data bus.
ii. An address bus.
iii. Read/Write control signals.
iv. Control signals to disable its role as a peripheral and to enable its role as
a processor.
8. This process is called switching from the slave mode to the master mode.
www.aktutor.in
Microprocessor & Microcontroller 3–15 B (EC-Sem-5)
Answer
Pin diagram of 8237 DMA controller is shown in Fig. 3.10.1. The
functional signal description in brief as follows :
1. VCC : This is + 5 V supply pin required for operation of circuit.
2. GND : This is return line for the supply (ground pin of IC).
3. CLK : This is the internally required clock signal for deriving the internal
timings required for the circuit operation.
IOR 1 40 A7
IOW 2 39 A6
MEMR 3 38 A5
MEMW 4 37 A4
VCC 5 36 EOP
READY 6 35 A3
HLDA 7 34 A2
ADSTB 8 33 A1
AEN 9 32 A0
HRQ 10 8237 31 VCC (+ 5 V)
CS 11 30 DB0
CLK 12 29 DB1
RESET 13 28 DB2
DACK2 14 27 DB3
DACK3 15 26 DB4
DREQ3 16 25 DACK0
DREQ2 17 24 DACK1
DREQ1 18 23 DB5
DREQ0 19 22 DB6
GND 20 21 DB7
6. READY : This active high input is used to match the read or write speed
of 8237 with slow memories or input/output devices.
16-bit Microprocessor 3–16 B (EC-Sem-5)
www.aktutor.in
7. Address bus (A0 – A3 and A4 – A7) : The four least significant lines
A0 – A3 are bi-directional three state signal. In idle cycle, they are input
and used by CPU to address the control register to be read or written.
The four most significant address lines (A4 – A7) are activated only
during DMA services to generate the respective address bits.
8. HRQ (Hold request) : The HRQ is an output pin used to request the
control of the system bus from the CPU. If the corresponding mask bit
is not set, every valid DREQ to 8237 will issue HRQ signal to the CPU.
9. DB0 – DB7 (Data bus) : These are bi-directional lines used to transfer
data to/from memory or input/output.
10. IOR and IOW (I/O read and I/O write) : These are active low
bi-directional symbol. In idle cycle, these are input control signals used
by CPU to read/write the control registers. In the active cycle IOR
signal is used to access the data from a peripheral and IOW signal is
used to load data to the peripheral.
11. DACK0 – DACK3 (DMA acknowledge) : These are used to indicate
peripheral devices that the DMA request is granted.
12. AEN (Address enable) : This active-high output enables the 8-bit latch
that drives the upper 8-bit address bus. The AEN pin is used to disable
other bus drivers during DMA transfers.
13. ADSTB (Address strobe) : This output line is used to strobe the upper
address byte generated by 8237, in master mode into an external latch.
14. DREQ0 – DREQ3 : These are used to indicate peripheral devices that
the DMA request is granted.
15. MEMR : This active-low output is used to access data from the selected
memory location, during DMA read or a memory to memory transfer.
16. MEMW : This active low output signal is used to write data to the
selected memory location during DMA write or memory to memory
transfer.
Que 3.11. With the help of the block diagram, describe 8237 DMA
Answer
1. The internal block diagram is shown in Fig. 3.11.1.
2. The 8237 contains three basic block of its operational logic.
Microprocessor & Microcontroller
www.aktutor.in 3–17 B (EC-Sem-5)
3. The timing and control block generates the internal timings and
external control signals.
4. The programmed command control block decodes the various
commands given to the 8237 by the CPU before servicing a DMA
request. It also decodes the mode control word used to select the type
of DMA during services.
5. The priority encoder block resolves the priority between DMA channels
requesting the service simultaneously.
6. The timing and control block derives necessary timing from clock input.
7. Internal registers : The 8237A contains 344 bits internal memory in
the form of registers, such as base address registers, current address
registers, temporary address registers etc.
Decrementor Inc./Decrementor A0 – A3
EOP
Temp. Word count Temp. Addr.
RESET
reg. (16) reg. (16) I/O Buffer
CS
READY
CLK Timing and
AEN Control
Read Buffer Read/Write Buffer
ADSTB O/P Buffer
Base Base Current Current
MEMR add. word add. word A4 – A7
MEMW (16) count (16) (16) count (16)
IOR
IOW Command
A8 – A15
Control
Answer
A. Internal block diagram and organization : Refer Q. 3.11,
Page 3–16B, Unit-3.
B. Modes :
i. Single transfer mode :
1. In this mode, the device transfer one byte per request.
16-bit Microprocessor 3–18 B (EC-Sem-5)
www.aktutor.in
2. The word count is decremented and the address is decremented or
incremented after each transfer.
3. For each transfer the DREQ must be active until the DACK is activated,
in order to get recognized.
4. After terminal count (TC), the bus will be relinquished for the CPU.
5. For a new DREQ to 8237, it will again activate the HRQ signal to the
CPU and the HLDA signal from the CPU will push the 8237 again into
single transfer mode. This mode is also called as ‘cycle stealing’.
ii. Block transfer mode :
1. In this mode, 8237 is activated by DREQ to continue the transfer until a
TC is reached, i.e., a block of data is transferred.
2. The transfer cycle may be terminated due to EOP which forces TC.
3. The DREQ needs to be activated only till the DACK signal is activated by
DMA controller.
4. Auto initialization may be programmed in this mode.
iii. Demand transfer mode :
1. In this mode, the device continuously transfer until a TC is reached or
Answer
1. The 8255 is a widely used programmable parallel I/O device.
2. It can be programmed to transfer data under various conditions, from
simple I/O to interrupt I/O.
3. It is compatible with all Intel and most other microprocessors.
4. It is completely TTL compatible.
5. It has three 8-bit ports : Port A, Port B, and Port C, which are arranged
in two groups of 12 pins. Each port has a unique address, and can be
read from or written to a part.
6. The address is assigned to the control register into which control words
are written for programming the 8255 to operate in various modes.
7. The 8255 can operate in three I/O modes :
i. In Mode 0, Port A and Port B can be configured as simple 8-bit input or
output ports without handshaking. The two halves of Port C can be
programmed separately as 4-bit input or output ports.
ii. In Mode 1, two groups each of 12 pins are formed. Group A consists of
Port A and the upper half of Port C while Group B consists of Port B and
the lower half of Port C. Ports A and B can be programmed as 8-bit Input
or Output ports with three lines of Port C in each group used for
handshaking.
iii. In Mode 2, only Port A can be used as a bi-directional port. The
handshaking signals are provided on five lines of Port C (PC3 – PC7).
Port B can be used in Mode 0 or in Mode 1.
Que 3.14. Explain the architecture of 8255 PPI with neat diagram.
Answer
1. The 8255 is a Programmable Peripheral Interface (PPI) which is used
for parallel data transfer.
16-bit Microprocessor 3–20 B (EC-Sem-5)
www.aktutor.in
2. It is used as a general purpose device for interfacing parallel
input/output devices to the system data bus.
3. It has three 8-bit ports : Port A, Port B and Port C. The 8255 can be
programmed to operate in three modes : Mode 0, Mode 1 and Mode 2.
Data bus control buffer :
1. This tri-stated bi-directional buffer is used to interface the 8255 to the
system data bus. IN or OUT instructions executed by the CPU either
read data from, or write data into the buffer.
2. Output data from the CPU to the ports or control register, and input
data to the CPU from the ports or status register are all passed through
the buffer.
Read/Write control logic :
1. The control logic block accepts control bus signals as well as inputs
from the address bus, and issues commands to the individual group
control blocks.
2. It issues appropriate enabling signals to access the required data/control
words or status word. RD , WR , RESET, and CS are 4-control signals
generated by control section.
Group A and group B controls :
1. Each of the group A and group B control blocks receives control words
from the CPU through the data bus buffer and the internal data bus
accepts commands from the control logic block and issues appropriate
commands to the ports associated with it.
PA7 – PA0
Group A Group A I/O
Control Port A
CS
Fig. 3.14.1. 8255 block diagram.
www.aktutor.in
Microprocessor & Microcontroller 3–21 B (EC-Sem-5)
2. The group A control block controls Port A and PC7 – PC4, while the
group B control block controls Port B and PC3 – PC0.
i. Port A : This has an 8-bit latched and buffered output and 8-bit input
latch.
ii. Port B : This has an 8-bit input/output latch/buffer and an 8-bit data
input buffer.
iii. Port C : This has one 8-bit unlatched input buffer and an 8-bit output
latch/buffer. Port C can be split into two parts and each can be used for
control signal outputs/inputs for Port A and Port B in the handshake
mode.
Answer
A. Architecture : Refer Q. 3.14, Page 3–19B, Unit-3.
B. Modes :
i. Mode 0 (Basic input/output) :
1. In this mode, in addition to Port A and Port B, PC7 – PC4 and PC3 – PC0
of Port C can be considered as two individual 4-bit ports. Therefore,
four ports, each of which can be configured either as an input or an
output port are available.
2. Here the ports are simple input or output ports; data is written to or
read from the specified port without handshaking. The data send out
to the output ports are latched, whereas inputs are not latched.
ii. Mode 1 (Strobe input/output) :
1. In this mode, input or output data transfer is affected by strobe
(handshaking signals). The two groups, Group A and Group B, can be
configured separately, with each group consisting of an 8-bit port and
a 4-bit port.
2. The 8-bit port can be programmed for input or output. The 4-bit port is
used for handshaking.
iii. Mode 2 (Strobe bi-directional bus I/O) :
1. This mode allows bi-directional data transfer over a single 8-bit data
bus using handshaking signals.
2. This feature is available only in Group A with port A as the 8-bit
bi-directional data bus, and PC4 – PC7 are used for handshaking
purposes. In this mode, both input and output are latched.
iv. Bit Set-Reset (BSR) Mode :
1. In this mode, any of the 8-bits of port C can be set or reset by sending
an OUT instruction to the control register.
2. When port C is used for control/status operation, this feature can be
used to set or reset individual bits as if they were output ports.
16-bit Microprocessor 3–22 B (EC-Sem-5)
www.aktutor.in
Que 3.16. Write a BSR control word subroutine to set bits PC7 and
PC3 and reset them after 10 ms. The address of control word register
is 83 H. Also, write subroutine of 10 ms. AKTU 2016-17, Marks 7.5
Answer
BSR control word :
This control word, when written in the control register sets or resets
one bit at a time as specified in Fig. 3.16.1.
Example : Write a BSR control word subroutine to set bits PC7 and PC3
and reset them after 10 ms (Fig. 3.16.1).
D7 D6 D5 D4 D3 D2 D1 D0
0 × × × Bit Select S/R
Set = 1
BSR Not Used 000 = Bit 0 Reset = 0
Mode Generally 001 = Bit 1
Set = 0 010 = Bit 2
011 = Bit 3
100 = Bit 4
101 = Bit 5
110 = Bit 6
111 = Bit 7
Fig. 3.16.1. 8255 control word format in the BSR mode.
Que 3.17. Explain the interface between 8085 P with 8255 PPI.
Answer
Step 1 :
i. Lower order of 8-bit address A0-A7 is separated from AD0-AD7 using
address latch/buffer and ALE signal.
ii. The separated address lines A0-A7 are connected to A0-A7 input pins of
8255 and the separated data bus D0-D7 are connected to D0-D7 pins of
8255.
iii. Reset out of 8085 is connected to reset pin of 8255.
Step 2 :
i. 8255 does not have internal (separate) control logic generator, hence
the IO/ M , RD and WR control signals are not connected directly to
8255. These pins are first given to decoder and decoded using 3:8 decoder.
ii. The generated control signals IOR and IOW are connected to RD and
WR input of 8255.
Step 3 :
i. An active low signal of chip select logic is obtained by decoding remaining
address lines of lower order addresses A2- A7.
ii. Chip select logic and I/O port address for this interfacing circuit are as
follows :
16-bit Microprocessor 3–24 B (EC-Sem-5)
www.aktutor.in
Chip select Address lines HEX Selected
address lines to select port address I/O
A7 A6 A5 A4 A3 A2 A1 A0
PORT
1 0 0 0 0 0 0 0 80 H
A
PORT
1 0 0 0 0 0 0 1 81 H
B
PORT
1 0 0 0 0 0 1 0 82 H
C
Chip
1 0 0 0 0 0 1 1 83 H select
register
Interfacing diagram :
+5V +5V
VCC VCC
ALE
+VCC Enable
Address P 8-Bit
A8-A15 A1
Latch OA PA0-
R IC 74373 A0 R PA7
T
Bi-
Reset IN Directioal D0-D7
SW c Buffer
IC 74245
+VCC 8
GND
8 2
E1 E2 O0 5 P 8-Bit
C1 0 PB0-
RD C 3:8 O1 OB
x1 8 D 5 R PB7
WR B O2
5 E T
IO/M A C O3
O O4
x2 D IOR
O5 RD
E
C2 O6
IC R WR
74138 IOW
O7
Fig. 3.17.1.
www.aktutor.in
Microprocessor & Microcontroller 3–25 B (EC-Sem-5)
PART-3
8253/8254 Programmable Timer/Counter, 8259
Programmable Interrupt Controller.
Questions-Answers
Answer
1. Delay routines cannot give time delay precisely. 8253 facilitates the
generation of accurate time delays.
2. Also when 8253 is used as a timing and delay generation peripheral, the
microprocessor becomes free from the tasks related to counting and can
execute the programs in memory. This minimizes the software overhead
on the microprocessor.
3. The 8254 is an upgraded version of the 8253, and they are pin compatible.
Features of the two devices are almost identical except that
i. The 8254 can operate on higher frequency than the 8253.
ii. The 8254 includes a status read-back command that can latch the count
and the status of the counter.
Architecture and signal descriptions :
1. The internal block diagram of 8253 is shown in Fig. 3.18.1. The
programmable timer device 8253 contains three independent 16-bit
counters. It is thus possible to generate three independent delays or
three independent counters simultaneously.
2. The three counters are controlled by programming the three internal
command word registers.
3. The 8-bit, bi-directional data buffer interfaces internal circuit of 8253 to
microprocessor systems bus.
4. Data is transmitted or received by the buffer upon the execution of IN
or OUT instruction. The IN instruction reads data while OUT instruction
writes data to a peripheral.
5. The three counters available in 8253 are independent of each other in
operation, but they are identical to each other in organization.
6. The specialty of the 8253 counters is that they can be easily read on line
without disturbing the clock input to the counter.
16-bit Microprocessor 3–26 B (EC-Sem-5)
www.aktutor.in
D7 – D0 CLK 0
Data Bus Counter
GATE 0
Buffer 0
OUT 0
RD CLK 1
WR Read/Write Counter
A0 Logic GATE 1
1 OUT 1
A1
RD
CLK 2
Control Word Counter
GATE 2
Register 1
OUT 2
Table 3.18.1.
CS RD WR A1 A0 Selected Operation
0 1 0 0 0 Write Counter 0
0 1 0 0 1 Write Counter 1
0 1 0 1 0 Write Counter 2
0 1 0 1 1 Write Control Word
0 0 1 0 0 Read Counter 0
0 0 1 0 1 Read Counter 1
0 0 1 1 0 Read Counter 2
0 0 1 1 1 No Operation (tri-stated)
0 1 1 × × No Operation (tri-stated)
1 × × × × Disabled (tri-stated)
A control word register accepts the 8-bit control word written by the
microprocessor and stores it for controlling the complete operation of
the specific counter.
Answer
1. The 8253 can operate in anyone of the six different modes. A control
word must be written to initialize each of the counters of 8253 to decide
its operating mode.
2. All the counters can operate in anyone of the modes or they may be
even in different modes of operation, at a time.
3. The control word format is shown Fig. 3.19.1, along with the definition
of each bit :
D7 D6 D5 D4 D3 D2 D1 D0
SC1 SC0 RW1 RW 0 M2 M1 M0 BCD
Que 3.20. Define the modes of 8254 PIT in detail with the help of
Answer
The block diagram of 8259A is shown in Fig. 3.21.1. The functional explanation
of each block is given as follows :
1. Interrupt Request Register (IRR) : The interrupts at IRQ input lines
are handled by interrupt request register internally. IRR stores all the
interrupt requests in it in order to serve them one by one on the priority
basis.
2. In-Service Register (ISR) : This stores all the interrupt requests those
are being served, i.e., ISR keeps a track of the request being served.
www.aktutor.in
Microprocessor & Microcontroller 3–29 B (EC-Sem-5)
INTA INT
D0 – D7 Data
bus Control Logic
buffer
RD Read/
WR Write IR0
Interrupt
A0 logic In-Service IR1
Priority request
register
resolver reg.
CS (ISR)
(IRR) IR7
CAS0 Cascade
CAS1 Buffer/
CAS2 Comparator Interrupt mask register (IMR)
Answer
1. Upto eight 8259s may be cascaded together to act as slave unit to a
master 8259.
2. Thus, a total of 64 I/O devices may be connected to the P via the 8259 to
transfer data in interrupt driven mode.
3. Fig. 3.23.1 exhibits a system having two 8259s – one master and one
slave used for interfacing 15 I/O devices to 8085.
CS
14 IR7 A0
13 IR6
12 IR5 8259
11 IR4 (SLAVE)
10 IR3 D0–D7
9 IR2
8 IR1
INT
7 IR0
CAS2 CAS 1 CAS0
From
8085
VCC CS
IR7 A0
6 IR6
5 IR5 8259
4 IR4 (MASTER)
3 IR3
2 IR2 D0–D7
1 IR1
0 IR0
4. The INT output of the slave is connected to the IR7 input of the master.
5. If any of the seven devices 0-6 interrupts, the sequence of actions taken
by the master.
6. When any of devices 7-14 interrupts, the slave will issue an interrupt to
the P if no other higher priority interrupt is pending.
7. On receipt of the INTA pulse, the master will send out the first byte of
the CALL instruction. It will enable the slave by issuing a slave address
code on the CAS lines.
16-bit Microprocessor 3–32 B (EC-Sem-5)
www.aktutor.in
8. The slave corresponding to this code will send the next two bytes of the
CALL instruction directly to the P in the next tow INTA pulses. This
address would obviously correspond to the interrupting device.
PART-4
8251 USART and RS232C.
Questions-Answers
Answer
A. 8251 USART :
1. 8251A Universal Synchronous Asynchronous Receiver and Transmitter
(USART) is compatible with Intel’s processors.
2. This may be programmed to operate in any of the serial communication
modes built into it.
3. This chip converts the parallel data into a serial stream of bits suitable
for serial transmission.
4. It is also able to receive a serial stream of bits and convert it into parallel
data bytes to be read by a microprocessor.
B. Features of 8251 USART :
1. Single + 5 V supply.
2. Compatible with 8085 and 8086/8088 CPU.
3. Supports both synchronous and asynchronous modes of operations.
i. In synchronous mode it supports 5-8 bit characters, internal or external
character synchronization at receiver, automatic sync insertion at
transmitter.
ii. In asynchronous mode it supports 5-8 bit characters, clock rate selectable
1, 16 or 64 times baud rate, break character generation, ‘1, 11/2 or 2 stop
bits, false start bit detection, odd, even or no parity generation and
detection, automatic breaks detect circuitry are also available.
4. Transmitter and receiver contain full duplex, double buffered system.
5. Error detection-Parity, overrun, framing.
Microprocessor & Microcontroller
www.aktutor.in 3–33 B (EC-Sem-5)
6. Separate TXC and RXC clock inputs for transmitter and receiver. So
transmitter and receiver can be operated in different baud rates.
Answer
1. The architectural block diagram of 8251A or 8251 is shown in
Fig. 3.25.1, followed by the functional description of each block.
2. The data buffer interfaces the internal bus of the circuit with the system
bus.
3. The read/write control logic controls the operation of the peripheral
depending upon the operations initiated by the CPU. This unit also
selects one of the two internal addresses those are control address and
data address.
D7 – D0
Data Bus Transmit TXD
Buffer Buffer
I
WR
RD N
T
RESET E
Read/Write TXRDY
CLK Control R Transmit TXEMPTY
C/D Logic N Control TXC
A
CS L
B
U Receiver RXD
DSR
S Buffer
DTR Modem
CTS Control
RTS RXRDY
Receive RXC
Control SYNDET
/BRKDET
Answer
1. D0-D7 : This is an 8-bit data bus used to read or write status, command
word or data from or to the 8251A.
D2 1 28 D1
D3 2 27 D0
RXD 3 26 VCC
GND 4 25 RXC
D4 5 24 DTR
D5 6 23 RTS
D6 7 22 DSR
8251A
D7 8 21 RESET
TXC 9 20 CLK
WR 10 19 TXD
CS 11 18 TXEMPTY
C/D 12 17 CTS
RD 13 16 SYNDET/BD
RXRDY 14 15 TXRDY
7. RESET : A high on this input forces the 8251A into an idle state. The
device will remain idle till this input signal again goes low and a new set
of control word is written into it.
10. RXC -Receiver Clock Input : This receiver clock input pin controls
the rate at which the character to be received.
11. RXD-Receive Data Input : This input pin of 8251A receives a composite
stream of the data to be received by 8251A.
12. RXRDY-Receiver Ready Output : This output indicates that the 8251A
contains a character to be read by the CPU. The RXRDY signal may be
used either to interrupt the CPU or may be polled by the CPU.
13. TXRDY-Transmitter Ready : This output signal indicates to the CPU
that the internal circuit of the transmitter is ready to accept a new
character for transmission from the CPU.
16-bit Microprocessor 3–36 B (EC-Sem-5)
www.aktutor.in
14. DSR -Data Set Ready : This input may be used as a general purpose
one bit inverting input port. Its status can be checked by the CPU using
a status read operation. This is normally used to check if the data set is
ready when communicating with a modem.
15. DTR -Data Terminal Ready : This output may be used as a general
purpose one bit inverting output port. This is used to indicate that the
device is ready to accept data when the 8251A is communicating with a
modem.
16. RTS -Request to Send Data : This output also may be used as a
general purpose one bit inverting output port that can be programmed
low to indicate the modem that the receiver is ready to receive a data
byte from the modem. This signal is used to communicate with a modem.
17. CTS -Clear to Send : If the clear to send input line is low, the 8251A
is enabled to transmit the serial data, provided the enable bit in the
command byte is set to 1.
18. TXE-Transmitter Empty : If the 8251A, while transmitting, has no
characters to transmit, the TXE output goes high and it automatically
goes low when a character is received from the CPU, for further
transmission.
19. SYNDET/BD-Synch Detect/Break Detect : This pin is used in the
synchronous mode for detecting SYNC characters (SYNDET) and may
be used as either input or output.
Answer
A. The standards : There are several standards that specify protocol for
data transfer between the devices and the electrical characteristics of
line drivers and receivers. RS-232C, RS-422A, RS-423A and RS-485 are
the few standards. RS-232C is one of the most commonly used standards.
B. The RS-232C :
1. This standard was mainly designed to connect Data Terminal Equipment
(DTE) that are sending and receiving serial data (such as a computer)
and Data Communication Equipment (DCE) that are used to send data
over long distances (such as a modem).
www.aktutor.in
Microprocessor & Microcontroller 3–37 B (EC-Sem-5)
2. The driver for RS-232C converts TTL logic low into a signal of
+ 3 to + 25 V and TTL logic high into a signal of – 3 to 25 V. The receiver
converts the signals of + 3 to – 25 V to TTL logic low and – 3 to – 25 V to
TTL logic high.
3. The ICs MC1488 and MC1489A are used as line drivers and receivers for
RS-232C standard.
4. The MC1488 contains four drivers and each driver converts a TTL level
signal to RS-232C level signal. The MC1489A contains four receivers
that convert RS-232C level signals into TTL levels.
C. Pins and signals :
1. The standard prescribes the 25-pin connector for connecting the DTE
and DCE. The rate of data transmission is restricted to a maximum of
20 k band and to a maximum distance of 50 feet.
2. Fig. 3.24.1 shows the pins and signals of RS-232C and the connection
between DTE and DCE using line drivers and receivers.
i. TXD and RXD : The Transmit Data and Receive Data on the DTE are
the serial data lines. These lines have opposite functions on a DCE.
ii. RTS and CTS : The Request To Send is activated by the transmitter
when it wishes to send data over the line. This line is active till the end
of communication. The Clear To Send is activated by the receiver to
inform the transmitter whether it is ready or not ready to accept the
data. It is also held active throughout the transmission.
iii. DTR and DSR : The DTE informs the DCE through the Data Terminal
Ready line that it is in on-line mode and communication is possible. The
Data Set Ready signal is to indicate that DCE is ready for communication.
iv. DCD : The Data Carrier Detect is activated by the DCE to indicate that
it has established a contact with DTE. It is usually activated when RTS
is granted.
v. RI : The Ring Indicator is activated by DCE when it detects an incoming
call on the telephone line.
3. The following sequence of signal handshaking occurs when a computer
sends a data to a modem. The computer activates the RTS signal to
modem and the modem in turn activates the DCD and then CTS .
16-bit Microprocessor 3–38 B (EC-Sem-5)
www.aktutor.in
4. The computer then sends data on TXD. After the data transmission is
complete the computer deactivates the RTS which causes the modem
to deactivate CTS .
TTL TTL
Level RS-232C Level Level
Signal signal Signal
DTE DCE
MC1488 RS-232C cable MC1489A
2 2 Telephone
TXD RXD
lines
3 3
RXD TXD
MC1489A 4 4 MC1488
RTS RTS
5 5
CTS CTS
6 6
DSR DSR
8 8
DCD DCD
20 20
DTR DTR
20 20
(RI) (RI)
7 7
GND GND
1 1
PG PG
Microprocessor & Microcontroller 4–1 B (EC-Sem-5)
www.aktutor.in
4 8051 Microcontroller
Basics
CONTENTS
Part-1 : Inside the Computer, ................................. 4–2B to 4–5B
Microcontrollers and
Embedded Processors
CONCEPT OUTLINE
• An embedded system is a combination of special purpose
hardware and software for executing a specific set of applications.
• The 8051 is an 8-bit processor that can work only on 8-bit of data
at a time. It has 128 bytes of RAM, 4 Kbytes of on-chip ROM, two
timers, one serial port and four I/O port (each 8-bit wide).
Questions-Answers
Answer
1. The internal working of every computer can be broken down into
three parts : CPU (Central Processing Unit), memory and I/O
(Input/Output) devices as shown in Fig. 4.1.1.
Address bus
Memory Peripherals
CPU
(monitor,
(RAM, ROM)
printer etc.)
Data bus
Fig. 4.1.1. Inside the computer.
2. The function of the CPU is to execute (process) information stored in
memory.
3. The function of I/O devices such as the keyboard and video monitor is to
provide a means of communicating with the CPU.
4. The CPU is connected to memory and I/O through strips of wire called a
bus. The bus carries information from place to place inside a computer.
Microprocessor & Microcontroller 4–3 B (EC-Sem-5)
www.aktutor.in
5. In every computer there are three types of buses: address bus, data bus,
and control bus.
6. The CPU puts the address (in binary) on the address bus, and the
decoding circuitry finds the device. Then the CPU uses the data bus
either to get data from that device or to send data to it.
7. The control buses are used to provided read or write signals to the
device to indicate if the CPU is asking for information or sending it
information.
8. Of the three buses, the address bus and data bus determine the capability
of a given CPU.
Answer
A. Embedded system :
1. An embedded system is an electronic/electro-mechanical system designed
to perform a specific function and is a combination of both hardware and
firmware (software).
2. Every embedded system is unique, and the hardware as well as the
firmware is highly specialised to the application domain.
3. Embedded systems are becoming an inevitable part of any product or
equipment in all fie lds including ho usehold appliances,
telecommunications, consumer products etc.
B. Purpose :
Each embedded system is designed to serve the purpose of any one or a
combination of the following tasks :
1. Data collection/storage/representation.
2. Data communication.
3. Data (signal) processing.
4. Monitoring.
5. Control.
6. Application specific user interface.
C. Application :
1. Consumer electronics : Camcorders, cameras, etc.
2. Household appliances : T.V, washing machine, fridge, etc.
3. Home automation and security system : Air conditioners, sprinklers,
fire alarms, etc.
4. Telecom : Cellular telephones, telephone switches, etc.
5. Computer peripherals : Printer, scanners, etc.
6. Healthcare : EEG, ECG machines etc.
8051 Microcontroller Basics 4–4 B (EC-Sem-5)
www.aktutor.in
Que 4.3. List s ome important features and architecture
consideration of an embedded system.
Answer
A. Important features :
1. Embedded systems execute pre-programmed functions and they have a
particular set of requirements.
2. They are programmed hardware devices that run on hardware chips
that are programmable.
3. Embedded systems perform a specific function or a set of specific
functions unlike a computer, which is used to carry out a wide number
of functions.
4. Embedded systems form smaller parts of a much larger device that
carries out a specific task.
5. Embedded systems can either have no user interface or possess highly
advanced graphical interfaces. It mainly depends on the purpose of the
device or the function it is designed to carry out.
6. Simple embedded systems use LEDs, buttons or LCD displays with
simple menu options.
B. Architecture considerations :
1. The architecture of an embedded system is an abstraction of the
embedded device, meaning that it is a generalization of the system.
2. The hardware and software components in an embedded system are
instead represented as composition of interacting elements.
3. Architectural element can be internally integrated within the embedded
device or exist externally to the embedded system and interact with
internal elements.
Answer
A. Microcontroller :
1. A microcontroller contains a fixed amount of RAM, ROM, parallel I/O
ports, serial I/O parts, counter a clock circuit all on a single chip.
2. The block diagram of microcontroller is shown in Fig. 4.4.1.
Microprocessor & Microcontroller 4–5 B (EC-Sem-5)
www.aktutor.in
ALU Timer/Counter Parallel
I/O port
Accumulator
Serial
Register(s) I/O port
Internal Interrupt
Internal ROM circuits
RAM
Clock
Stack pointer circuit
Program counter
PART-2
Block Diagram of 8051, PSW and Flag Bits,
8051 Register Banks and Stack.
Questions-Answers
EXTERNAL
INTERRUPTS
ON-CHIP
COUNTER INPUTS
ROM
INTERRUPT for ETC.
ON-CHIP
CONTROL program TIMER 0
RAM
code TIMER 1
CPU
P0 P2 P1 P3 TXD RXD
ADDRESS/DATA
Fig. 4.5.1. Inside the 8051 microcontroller block diagram.
Answer
A. PSW : The Program Status Word (PSW) register is an 8-bit register. It is
also referred to as the flag register. Although the PSW register is 8 bits
wide, only 6 bits of it are used by the 8051. The two unused bits are
user-definable flags.
B. Format of PSW :
1. In this, four flags are called conditional flags, meaning that they indicate
some conditions that result after an instruction executed.
2. These four are CY (carry), AC (auxiliary carry), P (parity), and OV
(overflow) as shown in Fig. 4.6.1.
Microprocessor & Microcontroller 4–7 B (EC-Sem-5)
www.aktutor.in
3. The bits PSW.3 and PSW.4 are designated as RS0 and RS1 respectively,
and are used to change the bank registers.
4. The PSW.5 and PSW.1 bits are general-purpose status flag bits and can
be used by the programmer for any purpose. In other words, they are
user-definable.
CY AC F 0 RS1 RS0 OV P
Fig. 4.6.1.
CY, the carry flag : This flag is set whenever there is a carry out from
the D7 bit. This flag bit is affected after an 8-bit addition or subtraction.
It can also be set to 1 or 0 directly by an instruction such as “SETB C” and
“CLR C” where “SETB C” stands for “set bit carry” and “CLR C” stands
for “clear carry”.
AC, the auxiliary carry flag :
If there is a carry from D3 to D4 during an ADD or SUB operation, this
bit is set, otherwise, it is cleared. This flag is used by instructions that
perform BCD (binary coded decimal) arithmetic.
P, the parity flag :
The parity flag reflects the number of 1s in the A (accumulator) register
only. If the A register contains an odd number of 1s, then P = 1. Therefore,
P = 0 if A has an even number of 1s.
8051 Microcontroller Basics 4–8 B (EC-Sem-5)
www.aktutor.in
OV, the overflow flag :
This flag is set whenever the result of a signed number operation is too
large, causing the high-order bit to overflow into the sign bit. In general,
the carry flag is used to detect errors in unsigned arithmetic operations.
The overflow flag is only used to detect errors in signed arithmetic
operations.
There is no sign flag in 8051 because of the overflow problem.
Answer
1. A total of 32 bytes of RAM is set aside for the register banks and stack as
shown in the Fig. 4.7.1. These 32 bytes are divided into 4 banks of
registers in which each bank has 8 registers, R0-R7.
2. RAM locations from 0 to 7 are set aside for bank 0 of R0-R7 where R0 is
RAM location 0, R1 is RAM location 1, R2 is location 2, and so on, until
memory location 7, which belongs to R7 of bank 0.
3. The second bank of register R0-R7 starts at RAM location 08 and goes to
location 0F H.
4. The third bank of R0-R7 starts at memory location 10 H and goes to
location 17 H.
5. Finally, RAM location 18 H to 1F H are set aside for the fourth bank of
R0-R7.
7F
Scratch pad RAM
30
2F Bit-addressable RAM
20
1F Register bank 3
18
17
Register bank 2
10
0F Register bank 1 (stack)
08
07 Register bank 0
00
Fig. 4.7.1. RAM allocation in the 8051.
6. Bank 1 uses the same RAM space as the stack. This is a major problem
in programming the 8051. One must either not use register bank 1, or
allocate another area of RAM for the stack.
Microprocessor & Microcontroller 4–9 B (EC-Sem-5)
www.aktutor.in
Bank 0 Bank 1 Bank 2 Bank 3
7 R7 F R7 17 R7 1F R7
6 R6 E R6 16 R6 1E R6
5 R5 D R5 15 R5 1D R5
4 R4 C R4 14 R4 1C R4
3 R3 B R3 13 R3 1B R3
2 R2 A R2 12 R2 1A R2
1 R1 9 R1 11 R1 19 R1
0 R0 8 R0 10 R0 18 R0
Fig. 4.7.2. 8051 Register banks and their RAM addresses.
Que 4.8. Which are the most widely used registers of 8051
microcontroller ?
Answer
1. Registers are basically used to store the information temporarily. This
information can be a byte of a data to be processed, or an address
pointing to the data to be fetched.
2. The most widely used registers of 8051 microcontroller are A
(accumulator), B, R0, R1, R2, R3, R4, R5, R6, R7, DPTR (Data Pointer)
and PC (Program Counter).
3. All the above registers are 8-bits, except DPTR and PC.
PC PC (program counter)
PART-3
Internal Memory Organization of 8051, Pins of 8051, I/O Port Usage
in 8051, Types of Special Function Register and their uses in 8051.
Questions-Answers
Answer
1. Fig. 4.9.1 shows the basic memory organization for 8051. It can access
up to 64 K program memory and 64 K data memory. The 8051 has 4
Kbytes of internal program memory and 256 bytes of internal data
memory.
Program Memory : Program Memory (ROM) is used for permanent
saving program (CODE) being executed. The memory is read only.
Depending on the settings made in compiler, program memory may
also used to store constant variables. The 8051 executes programs
stored in program memory only.
Internal Data Memory :
1. Up to 256 bytes of internal data memory are available depending on
the 8051 derivative. Locations available to the user occupy addressing
Microprocessor & Microcontroller 4–11 B (EC-Sem-5)
www.aktutor.in
space from 0 to 7F H, i.e., first 128 registers and this part of RAM is
divided in several blocks.
2. The first 128 bytes of internal data memory are both directly and
indirectly addressable. The upper 128 bytes of data memory can be
addressed only indirectly.
External Data Memory :
1. Access to external memory is slower than access to internal data
memory. There may be up to 64 Kbytes of external data memory.
2. Several 8051 devices provide on-chip XRAM (External RAM) space
that is accessed with the same instructions as the traditional external
data space. This XRAM space is typically enabled via proper setting of
SFR register and overlaps the external memory space.
FFFF H FFFF H
EA = 0
Access
60 Kbytes
External External
memory 64 Kbytes
OR External
1000 H
0FFF H 60 Kbytes EA = 1
4 internal Access
0000 H Internal 0000 H
memory
(a) Program memory
FF H FFFF H
Accessible
Accessible
Upper by indirect
by direct
128 addressing 64 Kbytes
addressing AND
only external
80 H
7F H Accessible memory
by direct
Lower and indirect
128 addressing
0000 H
0
(b) Data momory
Fig. 4.9.1. Memory organization of 8051.
P1.0 1 40 VCC
P1.1 2 39 P0.0 (AD0)
P1.2 3 38 P0.1 (AD1)
P1.3 4 37 P0.2 (AD2)
P1.4 5 36 P0.3 (AD3)
P1.5 6 35 P0.4 (AD4)
P1.6 7 34 P0.5 (AD5)
P1.7 8 33 P0.6 (AD6)
RST 9 32 P0.7 (AD7)
(RXD) P3.0 10 31 EA/VPP
8051
(TXD) P3.1 11 30 ALE/PROG
(INT0) P3.2 12 29 PSEN
(INT1) P3.3 13 28 P2.7 (A15)
(T0) P3.4 14 27 P2.6 (A14)
(T1) P3.5 15 26 P2.5 (A13)
(WR) P3.6 16 25 P2.4 (A12)
(RD) P3.7 17 24 P2.3 (A11)
XTAL 2 18 23 P2.2 (A10)
XTAL 1 19 22 P.21 (A9)
GND 20 21 P2.0 (A8)
Fig. 4.10.1.
3. There are four ports P0, P1, P2 and P3 each use 8 pins, making them
8-bit ports. All the ports upon RESET are configured as inputs, ready to
be used as input ports. When the first 0 is written to a port, it becomes an
output. To reconfigure as an input, 1 must be sent to port.
4. VCC : Pin 40 provides supply voltage to the chip. The voltage source is
+ 5 V.
5. GND : Pin 20 is the ground.
Microprocessor & Microcontroller 4–13 B (EC-Sem-5)
www.aktutor.in
6. XTAL 1 and XTAL 2 :
i. The 8051 has an on chip oscillator but requires an external clock to run
it. A quartz crystal oscillator is connected to inputs XTAL1 (pin 19) and
XTAL2 (pin 18).
ii. The quartz crystal connected to XTAL1 and XTAL2 needs two capacitors
of 30 pF value. One side of each capacitor is connected to ground as
shown in Fig. 4.10.2.
C2
XTAL 2
30 pF
C1
XTAL 1
30 pF
GND
Fig. 4.10.2.
iii. There are various speeds of the 8051 family. Speed refers to the maximum
oscillator frequency connected to XTAL.
7. RST : Pin 9 is the reset pin. It is an input and is active high. On applying
a high pulse to this pin, the microcontroller will reset and terminate all
activities. This is referred to as a power-on reset.
8. EA :
i. EA stands for external access enable pin. In 8051 chips with on chip
ROM such as 8751/52 or DS89C4 × 0, EA is connected to VCC. For
family members like 8031 and 8032 in which there is no on-chip ROM,
code is stored on an external ROM and is fetched by the 8031/32.
ii. Thus for 8031, the EA pin must be connected to GND to indicate that
code is stored externally.
iii. EA pin is an input pin and must be connected to either VCC or GND. It
cannot be left unconnected.
9. PSEN : This is an output pin. PSEN stands for program store enable.
This is an active low output pin. It acts as a strobe to read the external
program memory.
10. ALE : Address Latch Enable (ALE) is an output pin and is active high. It
is used for demultiplexing the address and data bus by connecting to the
GND pin of 74LS373 chip. This ALE signal is valid only for external
memory access.
Que 4.12. Write a short note on SFR registers and their addresses.
Answer
A. SFR registers :
1. The 8051 operations that do not use the internal 128-bytes RAM addresses
from 00 H to 7F H are done by a group of specific internal register, each
called a special function register.
2. In 8051, register A, B, PSW and DPTR are a part of the group of registers
referred as SFR.
3. SFR can be accessed by names or by their addresses.
B. SFR register addresses :
1. SFR has addresses between 80 H and FF H. These addresses are above
80H, since address 00 to 7F H are addresses of RAM memory inside the
8051.
2. Not all address space of 80 to FF H are used by SFR.
Some SFR addresses are
Accumulator – 0E0 H
B Register – 0F0 H
PSW – 0D0 H etc.
Microprocessor & Microcontroller 4–15 B (EC-Sem-5)
www.aktutor.in
PART-4
Memory Address Decoding, 8031/8051 Interfacing with
External ROM and RAM, 8051 Addressing Modes.
Questions-Answers
Answer
There are three methods of memory address decoding.
i. Using the 74LS138
ii. Using programmable logic
iii. Using simple logic gates :
1. The simplest method of constructing decoding circuitry is the use of a
NAND gate. The output of a NAND gate is active low, and the CS pin is
also active low, which makes them a perfect match.
2. In cases where the CS input is active high, an AND gate must be used.
Using a combination of NAND gates and inverters, one can decode any
address range.
3. An example of this is shown in Fig. 4.13.1, which shows that A15 - A12
must be 0011 in order to select the chip.
D0
D7
D7 D0
A0
A0-A11
4K×8
A11
A12
A13
A14 CS
A15 RD WR
MEMR
MEMW
Fig. 4.13.1.
8051 Microcontroller Basics 4–16 B (EC-Sem-5)
www.aktutor.in
4. This results in the assignment of addresses 3000 H to 3FFF H to this
memory chip.
Answer
1. This is one of the most widely used address decoders.
2. The 3 inputs A, B, and C generate 8 active-low outputs Y0 - Y7 as
shown in Fig. 4.14.1.
3. Each Y output is connected to CS of a memory chip, allowing control of
8 memory blocks by a single 74LS138.
4. In the 74LS138, where A, B, and C select which output is activated,
there are three additional inputs, G2A, G2B, and G1. G2A and G2B are
both active low, and G1 is active high.
5. If any one of the inputs G1, G2A, or G2B is not connected to an address
signal (sometimes they are connected to a control signal), they must be
activated permanently either by VCC or ground, depending on the
activation level.
VCC GND
Y0
A Y1
Y2
B
Y3
C Y4
Y5
Y6
Y7
G2A G2B G1
Enable
Fig. 4.14.1.
6. Example 4.14.2 shows the design and the address range calculation for
the 74LS138 decoder.
Microprocessor & Microcontroller 4–17 B (EC-Sem-5)
www.aktutor.in
D0
D7
D7 D0
Y0
A0
A0-A11
A12 A Y1
A13 B 4K×8
Y2 A11
A14 C
A15 G2A Y3
Y4 CE
GND G2B
VCC G1 Y5 OE VPP
Y6 MEMR
VCC
Y7
Fig. 4.14.2.
Answer
1. To connect the 8051 to an external RAM both RD and WR are used.
2. In writing data to external data RAM, the instruction “MOVX @DPTR, A”
is used, here the contents of register A are written to external RAM
whose address is pointed by the DPTR register.
RD
P3.7
P3.6 WR
A15
PSEN A14 CE WE OE
P2.7 A12 A13
8051
A12
P2.0
G A8 16K × 8
ALE
Data
P0.7 AD7 A7
D Q RAM
P0.0 74LS373 OC A0 A0
AD0 D7 D0
D7
D0
Fig. 4.15.1. 8051 connection of external data RAM.
P3.7 RD
P3.6 WR
P1.2 CE WE OE
P1.1 A17
P1.0 A16
P2.7 A15
8051
256K × 8
P2.0 A8
Data
A8
ALE G NV-RAM
AD7 A7
P0.7 D Q
P0.0 74LS373 A0
AD0 A0
OC D7 D0
D7
D0
Fig. 4.16.1. 8051 accessing 256K × 8 external NV-RAM.
2. To solve the problem where we need a large amount of memory to store
data (for example, 256 Kbytes), we can connect A0-A15 of 8051 directly
to the external memory’s A0-A15 pins, and use some of the P1 pins to
access the 64 Kbyte blocks inside the single 256 K × 8 memory chip, as
shown in Fig. 4.16.1.
Answer
A. Addressing mode :
1. The CPU can access data in many ways. The data could be in a register
or in memory or be provided as an immediate value. Thus, the various
ways of accessing the data are called addressing modes.
Microprocessor & Microcontroller 4–19 B (EC-Sem-5)
www.aktutor.in
B. Types of addressing mode :
i. Immediate addressing mode :
1. In this mode, the source operand is constant. As the name implies, when
the instruction is assembled the operand comes immediately after the
opcode.
2. This mode can be used to load information into any of the registers
including DPTR.
3. Here immediate data must be preceded by the pound sign “#”.
Examples :
MOV A, #25 H; Load 25 H into A
MOV DPTR, #2550 H
ii. Register addressing mode :
1. This mode involves the use of registers to hold the data to be manipulated.
2. Here the source and destination registers must match in size.
Example :
MOV A, R0 ; Copy the contents of R0 into A
MOV DPTR, #25F5 H
iii. Direct addressing mode :
1. Direct addressing mode is provided to allow us access to internal data
memory, including Special Function Register (SFR). In direct addressing,
an 8 bit internal data memory address is specified as part of the instruction
and hence, it can specify the address only in the range of 00 H to FF H.
2. In this addressing mode, data is obtained directly from the memory.
Example :
MOV R0, 40 H ; Save content of RAM location 40 H in R0
MOV A, R4 ; which means copy R4 into A.
iv. Indirect addressing mode :
1. The indirect addressing mode uses a register to hold the actual address
that will be used in data movement. Registers R0, R1, and DPTR are the
only registers that can be used as data pointers.
2. Indirect addressing cannot be used to refer to SFR registers. Both R0
and R1 can hold 8 bit address and DPTR can hold 16 bit address.
Example :
MOV A, @ R0 ; Move the contents of RAM location
whose address is held by R0 into A
MOV @ R1, B ; Move the contents of B into RAM
8051 Microcontroller Basics 4–20 B (EC-Sem-5)
www.aktutor.in
location whose address is held by R1.
v. Indexed addressing mode :
1. In indexed addressing, a separate register (either the program counter
(PC), or the data pointer (DTPR)) is used to hold the base address, and
the A is used to hold the offset address.
2. Adding the value of the base address to the value of the offset address
forms the effective address.
3. Indexed addressing is used with JMP or MOVC instructions. Look up
tables are easily implemented with the help of index addressing.
Example :
MOVC A, @ A + DPTR
Answer
i. Indexed addressing mode.
ii. Register addressing mode.
iii. Immediate addressing mode.
iv. Direct addressing mode.
Microprocessor & Microcontroller 5–1 B (EC-Sem-5)
www.aktutor.in
5
Assembly
Programming
and Instruction of
8051
CONTENTS
Part-1 : Introduction to 8051 Assembly ............... 5–2B to 5–7B
Programming, Assembling and
Running an 8051 Program, Data
Types and Assembler Directives
CONCEPT OUTLINE
• The widely used directives of 8051 are :
1. ORG (Origin)
2. EQU (Equate)
3. END directive.
• Assembly language is referred to as a low level language because
it deals directly with the internal structure of CPU.
Questions-Answers
Answer
A. Machine language :
1. In the early days of the computer, programmers coded programs in
machine language. A program that consists of 0s and 1s is called machine
language.
2. Although hexadecimal system was used as an efficient way to represent
binary numbers, the process of working in machine code was still
cumbersome for humans.
3. Eventually, assembly languages were developed that provided
mnemonics for the machine code instructions, plus other features that
made programming faster and less prone to error.
4. The term mnemonic is frequently used in computer science to refer
codes and abbreviations that are relatively easy to remember.
B. Assembler : Assembly language programs must be translated into
machine code by a program called an assembler.
Microprocessor & Microcontroller 5–3 B (EC-Sem-5)
www.aktutor.in
C. Low-level language :
1. Assembly language is referred to as low-level language because it deals
directly with the internal structure of the CPU.
2. To program in assembly language, the programmer must know all the
registers of the CPU and the size of each.
D. High-level language :
1. Today, one can use many different programming languages, such as
BASIC, C, C++, Java, and numerous others.
2. These languages are called high-level languages because the programmer
does not have to be concerned with the internal details of the CPU
whereas an assembler is used to translate an assembly language program
into machine code (sometimes also called object code or opcode for
operation code).
3. High-level languages are translated into machine code by a program
called a compiler.
E. Assembly language programming :
1. An assembly language program consists of a series of lines of assembly
language instructions.
2. These instructions consist of mnemonic, optionally followed by one or
two operands. The operands are the data items being manipulated, and
the mnemonics are the commands to the CPU.
3. An assembly language instruction consists :
[Label :] mnemonic [Operands] [ ; Comment]
i. The label field allows the program to refer to a line of code by name. The
label field cannot exceed a certain number of characters.
ii. The assembly language mnemonic (instruction) and operand(s) fields
together perform the real work of the program and accomplish the
tasks for which the program was written.
For example :
ADD A, B
MOV A, #67
iii. The comment field begins with semicolon comment indicator “;”.
Comments may be at the end of a line or on a line by themselves.
4. An assembly language program given below is a series of statements, or
lines, which are either assembly language instructions such as ADD
and MOV, or statements called directives.
5. Here instructions tell the CPU what to do and directives (also called
pseudo-instructions) give directions to the assembler.
6. For example, in the given program the MOV and ADD instructions are
commands to the CPU and ORG, END are directives to the assembler.
Assembly Programming & Instruction of 8051 5–4 B (EC-Sem-5)
www.aktutor.in
7. ORG tells the assembler to place the opcode at memory location 0 while
END indicates to the assembler the end of the source code. In other
words, one is for the start of the program and the other one for the end
of the program.
For example :
ORG 0H ; start (origin) at location 0
MOV R5, #25 H ; load 25 H into R5
MOV R7, #34 H ; load 34 H into R7
MOV A, #0 ; load 0 into A
ADD A, R5 ; add contents of R5 to A
; now A = A + R5
ADD A, R7 ; add contents of R7 to A
; now A = A + R7
ADD A, #12 H ; add A to value 12 H
; now A = A + 12 H
HERE : SJMP HERE ; stay in this loop
END ; end of asm source file
Answer
1. The steps that illustrate how an assembly language program is created,
assembled and made ready to run is given in the Fig. 5.2.1.
Editor program
myfile.asm
Assembler program
myfile.lst
other obj files
myfile.obj
Linker program
myfile.abs
0 H program
myfile.hex
Fig. 5.2.1.
Microprocessor & Microcontroller 5–5 B (EC-Sem-5)
www.aktutor.in
Steps 1 :
i. Firstly an editor is used to create and/ or edit the program. A widely used
editor is the MS-DOS edit program (or notepad in windows), which
comes with all Microsoft operating systems.
ii. The editor must be able to produce an ASCII file. For many assemblers,
the file names follow the usual DOS convention, but the source file has
the extension “asm” or “src”, depending on which assembler you are
using. Check your assembler for the convention.
iii. The “asm” extension for the source file is used by an assembler in the
next step.
Steps 2 : The “asm” source file containing the program code created in
step 1 is fed to an 8051 assembler. The assembler converts the
instructions into machine code. The assembler will produce an object
file and a list file. The extension for the object file is “obj” while the
extension for the list file is “lst”.
Steps 3 : Assemblers require a third step called linking. The link program
takes one or more object files and produces an absolute object file with
the extension “abs”. This abs file is used by 8051 trainers that have a
monitor program.
Steps 4 : Next the “abs” file is fed into a program called “0 H” (object to
hex converter), which creates a file with extension “hex” that is ready to
burn into ROM. This program comes with all 8051 assemblers.
asm and obj files :
1. The “asm” file is also called the source file and for this reason some
assemblers require that this file have the “src” extension.
2. The 8051 assembler converts the asm file’s assembly language
instructions into machine language and provides the obj (object) file.
lst (list) file :
1. The lst (list) file, which is optional, is very useful to the programmer
because it lists all the opcodes and addresses as well as errors that the
assembler detected.
2. Many assemblers assume that the list file is not wanted unless you
indicate that you want to produce it.
3. This file can be accessed by an editor such as DOS EDIT and displayed
on the monitor or sent to the printer to produce a hard copy.
4. The programmer uses the list file to find syntax errors.
5. It is only after fixing all the errors indicated in the lst file that the obj file
is ready to be input to the linker program.
PART-2
Arithmetic, Logic Instruction and Programs, Jump,
Loop and Call Instructions.
Questions-Answers
Answer
Arithmetic instruction : These are the instructions used for arithmetic
operation like addition, subtraction etc.
1. ADD : This instruction is used to add two operands. The destination
operand is always in register A while the source operand can be a
register, immediate data or in memory.
Format : ADD A, Source
For example :
ADD A, R2 ; Adds contents of A and R2 and store result in A.
ADD A, # 20 H ; Add contents of A and 20 H and store result in A.
2. ADDC (Add with carry) : This instruction is used to add two 16-bit
operands. In this, add register, immediate data, or in memory to
accumulator with carry and store result in A.
Format : ADDC A, source
For example :
ADDC A, R2 ; Adds the contents of A, R2 and carry flag,
and stores result in A.
ADDC A, # 50 H ; Adds the contents of A and carry flag and 20 H and
stores result.
3. DA :
i. The DA (decimal adjust for addition) instruction in the 8051 is provided
to correct the aforementioned problem associated with BCD addition.
The mnemonic “DA” has as its only operand the accumulator “A”.
ii. The DA instruction will add 6 to the lower nibble or higher nibble if
needed; otherwise, it will leave the result alone.
Format : DA A
Assembly Programming & Instruction of 8051 5–8 B (EC-Sem-5)
www.aktutor.in
For example :
MOV A, #47 H ; A = 47 H first BCD operand
MOV B, #25 H ; B = 25 second BCD operand
ADD A, B ; hex (binary) addition (A = 6C H)
DA A ; adjust for BCD addition (A = 72 H)
4. SBB (Subtract with borrow) : This instruction is used for multibyte
numbers and will take care of the borrow of the lower operand. If
CY = 1 prior to executing the SUBB instruction, it also subtracts 1 from
the result.
Format : SUBB A, source
For example :
SUBB A, R3 : Subtracts contents of R3 and carry together from A and
stores result in A.
SUBB A, # 20 H : Subtracts 20 H from A and storage result in A.
5. MUL : In this multiplication, one of the operands must be in register A,
and the second operands must be in register B. After multiplication, the
result is in the A and B register; the lower byte is in A, and the upper
byte is in B.
Format : MUL AB
For example :
MOV A, # 25 H ; load 25 H to reg. A
MOV B, # 65 H ; load 65 H to reg. B
MUL AB ; 25 H * 65 H = E99 where
; B = 0E H and A = 99 H
6. DIV : In this, the numerator must be in register A and the denominator
must be in B. After the DIV instruction is performed, the quotient is in
A and the remainder is in B.
Format : DIV AB
For example :
DIV AB ; now A = quotient and B = remainder
Que 5.5. Write a program to add two 16-bit numbers the numbers
are FC45 H and 02EC H.
Answer
CLR C ; make CY = 0
MOV A, #45 H ; load the low byte into A
ADD A, #0EC H ; add the low byte, now A = 31, CY = 1
Microprocessor & Microcontroller 5–9 B (EC-Sem-5)
www.aktutor.in
MOV R0, A ; save the low byte of sum in R0
MOV A, #02 H ; load the high byte into A
ADDC A, #0FC H ; add the high bytes with carry
; 02 + FC H + 1 = FF H
MOV R1, A ; save the high byte of result in R1
Finally, we get the result as R0 = 31 H and R1 = FF H
Que 5.6. What do you mean by logical instructions ?
Answer
The logical instructions are :
1. AND : This instruction will perform a logical AND on the two operands
and place the result in the destination. The destination is normally the
accumulator. The source operand can be a register, in memory, or
immediate.
Format : ANL destination, source.
For example :
ANL A, R2 ;
2. OR : The destination and source operands are ORed, and the result is
placed in the destination. The ORL instruction can be used to set certain
bits of operands to 1. The destination is normally the accumulator. The
source operand can be a register, in memory, or immediate.
Format : ORL destination, source
For example : ORL C, ACC 7 ;
3. XOR : This instruction will perform the XOR operation on the two
operands, and place the result in the destination. The destination is
normally the accumulator. The source operand can be a register, in
memory, or immediate.
Format : XRL destination, source
For example : XRL A, # 78 H
4. CPLA (complement accumulator) : This instruction complements
the contents of register A. The complement action changes the 0s to 1s
and the 1s to 0s. This is also called 1’s complement.
Format : CPL A
For example : MOV A, # 55H
CPL A ; now A = AA H
PART-3
I/O Port Programming, Programming 8051 Timers, Serial
Port Programming, Interrupts Programming.
Questions-Answers
Que 5.8. Write a test program for the DS89C420/30 chip to toggle
all the bits of P0, P1 and P2 every 1/4 of a second. Assume a crystal
frequency of 11.0592 MHz.
Answer
; Tested for the DS89C420/30 with XTAL = 11.0592 MHz.
ORC 0
BACK: MOV A, #55 H
MOV P0, A
MOV P1, A
Assembly Programming & Instruction of 8051 5–12 B (EC-Sem-5)
www.aktutor.in
MOV P2, A
ACALL QSDELAY ; Quarter of a second delay
MOV A, # 0AAH
MOV P0, A
MOV P1, A
MOV P2, A
ACALL QSDELAY
SKMP BACK
; --------------1/4 SECOND DELAY
QSDELAY :
MOV R5, #11
H3 : MOV R4, #248
H2 : MOV R3, #255
H1 : DJNZ R3, H1 ; 4 MC for DS89C4x0
DJNZ R4, H2
DJNZ R5, H3
RET
END
Delay = 11 × 248 × 255 × 4 MC × 90 ns = 250,430 s
Use an oscilloscope to verify the delay size.
Answer
SETB P1 . 7 ; make P1.7 an input
AGAIN JB P1.2 OVER ; jump if P1.7 = 1
MOV P2, # N ; SW = 0, issue N to P2
SJMP AGAIN ; Keep monitoring
OVER : MOV P2, # Y ; SW = 1, issue Y to P2
SJMP AGAIN ; keep monitoring
Answer
The 8051 has two timers :
A. Timer 0 register :
1. This is a 16-bit register accessed as low byte and high byte.
Microprocessor & Microcontroller 5–13 B (EC-Sem-5)
www.aktutor.in
2. The low byte register is called TL0 (Timer 0 low byte) and high byte
register is referred as TH0 (Timer 0 high byte).
TH0 TL0
D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
Answer
1. TMOD re gister is a time r mo de registe r and bo th timers
(0 and 1) use this register to set the various timer operation modes.
2. It is an 8-bit register in which lower 4-bits are for Timer 0 and upper
4-bits for Timer 1. In each case, the lower two bits are used to set the
timer mode and upper two bits are used to specify the operation.
MSB LSB
GATE C/T M1 M0 GATE C/T M1 M0
Timer 1 Timer 0
Fig. 5.11.1. TMOD register.
Assembly Programming & Instruction of 8051 5–14 B (EC-Sem-5)
www.aktutor.in
Table 5.11.1.
M1 M0 Mode Operating Mode
0 0 0 13-bit timer mode
8-bit timer/counter THx with TLx as 5-bit
prescaler
0 1 1 16-bit timer mode
16-bit timer/counters THx and TLx are
cascaded; there is no prescaler
1 0 2 8-bit auto reload
8-bit auto reload timer/counter; THx holds
a value that is to be reloaded into TLx each
time it overflows.
1 1 3 Split timer mode
M1 and M0 :
1. M0 and M1 select the timer mode. There are basically three modes : 0, 1
and 2.
2. Mode 0 is a 13-bit timer, mode 1 is a 16-bit timer and mode 2 is an 8-bit
timer. The most widely used modes are 1 and 2.
C/T (Clock/Timer) :
1. This bit in the TMOD register is used to decide whether the timer is used
as a delay generator or an event counter.
2. If C/T = 0, it is used as a timer for time delay generation and the crystal
frequency attached to 8051 act as source of the clock for the timer.
3. This means that the size of the crystal frequency attached to 8051 also
decides the speed at which 8051 timer ticks.
4. The frequency for the timer is always 1/12th the frequency of the crystal
attached to the 8051.
GATE :
1. In the TMOD register both timers 0 and 1 have the GATE bit. It is
because every timer has a means of starting and stopping.
2. Some timers do this by software, some by hardware, and some have
both software and hardware controls. The timers in the 8051 have both.
3. The start and stop of the timer are controlled by way of software by the
TR (timer start) bit TR0 and TR1.
4. This is achieved by the instructions “SETB TR1” and “CLR TR1” for
Timer 1, and “SETB TR0” and “CLR TR0” for Timer 0.
5. The SETB instruction starts it, and it is stopped by the CLR instruction.
These instructions start and stop the timers as long as GATE = 0 in the
TMOD register.
Microprocessor & Microcontroller 5–15 B (EC-Sem-5)
www.aktutor.in
6. The hardware way of starting and stopping the timer by an external
source is achieved by making GATE = 1 in the TMOD register.
Answer
For Timer 1
SETB TR1 = SETB TCON.6
CLR TR1 = CLR TCON.6
SETB TF1 = SETB TCON.7
CLR TF1 = CLR TCON.7
Answer
a.
i. Mode 1 Timer 1 :
Microprocessor & Microcontroller 5–17 B (EC-Sem-5)
www.aktutor.in
Gate C/T M1 M0 Gate C/T M1 M0
0 0 0 1 0 0 0 0
Timer 1 Timer 0
Fig. 5.13.1.
Gate control bit and C/T bits are made 0, and unused timer is also made
0.
For mode 1, M1 = 0 and M0 =1
TMOD = 00010000 = 10 H
ii. Mode 0 Timer 0 :
Answer
1. For crystal frequency of 12 MHz :
1
The value of instruction cycle = 12 MHz = 1 MHz
12
1
T= = 1 s
1 106
2. For OFF time calculation :
5 ms/10–6 = 5000 cycle
Now, perform 65536 – n, where n is the decimal value given above.
65536 – 5000 = 60536 = EC78 H
3. For ON time calculation :
5 ms/10–6 s = 5000 cycle
65536 – 5000 = 60536 = EC78 H.
4. Let us use Timer 0 in Mode 1.
MOV TMOD, # 01 H ; Timer 0 in mode 1
BACK : MOV TL0, # 078 H ; to generate the OFF time, load TL0
MOV TH0, # 0EC H ; load OFF time value in TH0
Assembly Programming & Instruction of 8051 5–18 B (EC-Sem-5)
www.aktutor.in
MOV P0, # 00 H ; make port bits low
ACALL DELAY ; call delay routine
MOV TL0, # 078 H ; to generate ON time, load TL0
MOV TH0, # 0EC H ; load ON time value in TH0
MOV P0, # 0FF H ; make port bits high
ACALL DELAY ; call delay
SJMP BACK ; repeat for reloading counters to
get a continuous square wave
ORG 300 H
DELAY : SETB TR0 ; start the counter
AGAIN : JNB TF0, AGAIN ; check the timer overflow
CLR TR0 ; when TF0 is set, stop the timer
CLR TF0 ; clear timer flag
RET
END ; end of file.
Answer
A. Program :
MOV TMOD, #01 ; Timer 0, mode 1(16-bit mode)
HERE : MOV TL0, #0F2 H ; TL0 = F2 H, the low byte
MOV TH0, #0FF H ; TH0 = FF H, the high byte
CPL P1.5 ; toggle P1.5
ACALL DELAY
SJMP HERE ; load TH, TL Again
Delay using Timer 0
DELAY
SET B TR0 ; start Timer 0
AGAIN JNB TF0, AGAIN ; Monitor Timer 0 flag until
; it roll over
CLR TR0 ; stop timer 0
CLR TF0 ; clear timer 0 flag
RET
B. Algorithm :
1. TMOD is loaded.
2. FFF2 H is loaded into TH0 - TL0.
3. P1.5 is toggled for the high and low portions of the pulse.
4. The DELAY subroutine using the timer is called.
Microprocessor & Microcontroller 5–19 B (EC-Sem-5)
www.aktutor.in
5. In the DELAY subroutine, Timer 0 is started by the SETB TRO
instruction.
i. Timer 0 counts up with the passing of each clock, which is provided by
the crystal oscillator. As the timer counts up, it goes through the states
of FFF3, FFF4, FFF5, FFF6, FFF7, FFF8, FFF9, FFFA, FFFB, and so on
until it reaches FFFF H.
ii. One more clock rolls it to 0, raising the timer flag (TF0 = 1). At that point,
the JNB instruction falls through.
iii. Timer 0 is stopped by the instruction CLR TR0. The DELAY subroutine
ends and the process is repeated.
Answer
1. The serial port of 8051 is full duplex, means it can transmit and receive
simultaneously. It uses register SBUF to hold data. Register SCON
controls data communication, register-PCON controls data rates and
pin RxD (P3.0) and TxD (P3.1) do the data transfer.
2. SBUF is an 8-bit register dedicated for serial communication in 8051. Its
address is 99 H. It can be addressed like any other register in 8051.
3. Writing to SBUF loads data to be transmitted and reading SBUF accesses
received data.
4. There are two separate and distinct register, the transmit write-only
register, and the receive read-only register. This is shown in Fig. 5.16.1.
5. The way in which SBUF is used for the transmission and reception of
the data during serial communication is explained below :
a. Transmission : When a byte of data is to be transmitted via the TxD
pin, the SBUF is loaded with this data byte. As soon as a data byte is
written into SBUF, it is framed with the start and stop bits and transmitted
serially via the TxD pin.
b. Reception : When 8051 receives data serially via RxD pin of it, the 8051
deframes it. The start and stop bits are separated out from a byte of data.
This type is placed SBUF register.
Assembly Programming & Instruction of 8051 5–20 B (EC-Sem-5)
www.aktutor.in
RxD
(P3.0) D
SBUF TxD
Shift register CLK
(Write only) (P3.1)
CLK
Baud rate
clock Baud rate clock
(Receive) (Transmit)
SBUF
(Read only)
Answer
1. The 8051 provides four programmable modes for serial data
communication. A particular mode can be selected by setting the SM0
and SM1 bits in SCON. The mode selection also decides the baud rate.
2. The Fig. 5.17.1 shows the bit patterns for SCON.
7 6 5 4 3 2 1 0
SM0 SM1 SM2 REN TB8 RB8 T1 RI
Fig. 5.17.1.
Que 5.18. Draw and explain the bit pattern of PCON register of
8051,
Answer
Bit pattern of PCON register :
7 6 5 4 3 2 1 0
SMOD - - - GF1 GF0 PD IDL
Fig. 5.18.1.
PART-4
Interfacing : LCD & Keyboard Interfacing, ADC, DAC
and Sensor Interfacing.
Questions-Answers
P1.0 DB 0 VCC
P1.1 DB 1 20 character × 2 line
P1.2 DB 2
P1.3 DB 3 VEE
LCD
P1.4 DB 4 display
P1.5 DB 5 module
P1.6 DB 6 VSS
8051
P1.7 DB 7
RS R/W E
P3.2
P3.3
P3.4
Fig. 5.20.1.
Answer
Pin description : The LCD module consists of 14 pins. Each pin’s
description is shown in the table 5.21.1.
Assembly Programming & Instruction of 8051 5–24 B (EC-Sem-5)
www.aktutor.in
Table 5.21.1 : Pin descriptions for LCD
Que 5.22. Discuss the key press and key detection mechanism of
keyboard.
Answer
1. Keyboards are organized in a matrix of rows or columns.
2. The CPU accesses both rows and columns through ports; thus, with two
8-bit ports, an 8 × 8 matrix of keys can be connected to a microprocessor.
When a key is pressed, a row and a column make a contact.
3. To understand the mechanism let us consider a 4 × 4 matrix connected
to two ports as shown in Fig. 5.22.1.
VCC
4.7k
3 2 1 0 4.7k
D0
7 6 5 4
D1
B A 9 8
D2
F E D C
D3
Port 1 D3 D2 D1 D0 Port 2
(Out) (In)
Fig. 5.22.1.
4. The rows are connected to an output port and the columns are connected
to an input port.
5. If no key has been pressed, the input port will yield 1s for all columns
since they are all connected to high (VCC).
Assembly Programming & Instruction of 8051 5–26 B (EC-Sem-5)
www.aktutor.in
6. If all the rows are grounded and a key is pressed, one of the columns will
have 0 since the key pressed provides the path to ground.
7. It is the function of the microcontroller to scan the keyboard continuously
to detect and identify the key pressed.
8. To detect a pressed key, the microcontroller ground all rows by providing
0 to the output latch, then it reads the columns. If the data read from the
columns is D3-D0 = 1111, no key has been pressed and process continues
until a key press is detected.
9. However, if one of the column bits has a zero, this means that a key
press has occurred.
10. For example, if D3-D0 = 1101, this means that a key in the D1 column
has been pressed. After a key press is detected, the microcontroller will
go through the process of identifying the key.
11. Starting with the top row, the microcontroller grounds it by providing a
low to row D0 only; then it reads the columns.
12. If the data read is all 1s, no key in that row is activated and the process
is moved to the next row. It grounds the next row, reads the columns,
and checks for any zero. This process continues until the row is identified.
13. After identification of the row in which the key has been pressed the
next task is to find out which column the pressed key belongs to.
14. This should be easy since the microcontroller knows at any time which
row and column are being accessed.
Answer
MOV P2, #0FFH ; make P2 an input port
K1 : MOV P1, #0 ; ground all rows at once
MOV A, P2 ; read all col. ensure all keys open
ANL A, #00001111B ; masked unused bits
CJNE A, #00001111B, K1 ; check till all keys released
K2 : ACALL DELAY ; call 20 ms delay
MOV A, P2 ; see if any key is pressed
ANL A, #00001111B ; mask unused bits
CJNE A, #00001111B,OVER ; key pressed, await closure
SJMP K2 ; check if key pressed
OVER : ACALL DELAY ; wait 20 ms debounce time
MOV A, P2 ; check key closure
ANL A, #00001111B ; mask unused bits
CJNE A, #00001111B,OVER1 ; key pressed, find row
SJMP K2 ; if none, keep polling
OVER1 : MOV P1, #11111110B ; ground row 0
MOV A, P2 ; read all columns
ANL A, #00001111B ; mask unused bits
CJNE A, #00001111B, ROW 0 ; key row 0, find the col.
MOV P1, #11111101B ; ground row 1
MOV A, P2 ; read all columns
ANL A, #00001111B ; mask unused bits
Microprocessor & Microcontroller 5–27 B (EC-Sem-5)
www.aktutor.in
CJNE A, #00001111B, ROW 1 ; key row 1, find the col.
MOV P1, #11111011B ; ground row 2
MOV A, P2 ; read all columns
ANL A, #00001111B ; mask unused bits
CJNE A, #00001111B, ROW 2 ; key row, find the col.
MOV P1, #11110111B ; ground row 3
MOV A, P2 ; read all columns
ANL A, #00001111B ; mask unused bits
CJNE A, #00001111B, ROW 3 ; key row 3, find the col.
LJMP K2 ; if none, false input, repeat
ROW 0 : MOV DPTR, #KCODE0 ; set DPTR=start of row 0
SJMP FIND ; find col. key belongs to
ROW 1 : MOV DPTR, #KCODE1 ; set DPTR=start of row 1
SJMP FIND ; find col. key belongs to
ROW 2 : MOV DPTR, #KCODE2 ; set DPTR=start of row 2
SJMP FIND ; find col. key belongs to
ROW 3 : MOV DPTR, #KCODE3 ; set DPTR=start of row 3
SJMP FIND ; find col. key belongs to
FIND : RRC A ; see if any CY bit is low
JNC MATCH ; if zero, get the ASCII code
INC DPTR ; point to next col. address
SJMP FIND ; keep searching
MATCH :CLR A ; set A=0 (match is found)
MOVC A, @A+DPTR ; get ASCII code from table
MOV P0, A ; display pressed key
LJMP K1
; ASCII LOOK-UP TABLE FOR EACH ROW
ORG 300H
KCODE0 : DB ‘0’,‘1’, ‘2’, ‘3’ ; ROW 0
KCODE1 : DB ‘4’,‘5’, ‘6’, ‘7’ ; ROW 1
KCODE2 : DB ‘8’,‘9’, ‘A’, ‘B’ ; ROW 2
KCODE3 : DB ‘C’,‘D’, ‘E’, ‘F’ ; ROW 3
END
Answer
A. Interfacing of ADC 0804 with 8051 :
1. Fig. 5.24.1 shows the interfacing of ADC 0803/0804/0805 with 8051 using
port 1 and port 2.
2. Here, port 1 is used to read digital data from ADC and port 2 is used to
provide control signals to ADC 0803/0804/0805.
3. Potentiometer is used to adjust + Vin. The clock signal is provided using
internal clock generator and two external components, resistor and
capacitor as shown in the Fig. 5.24.1.
4. The frequency of such clock can be determined by,
f = 1/1.1RC
5. The typical values are R = 10 k and C = 150 pF. With these values we
get approximately 606 KHz clock frequency. In such case, the conversion
time is around 110 s.
Assembly Programming & Instruction of 8051 5–28 B (EC-Sem-5)
www.aktutor.in
+5V
VCC
POT Vin(+) RD P2.5
Vin(–) WR P2.6
ANLGGND
REF/2 D0 P1.0
10 K D1 P1.1 8051
CLK OUT D2 P1.2
R D3 P1.3
CLK IN D4 P1.4
D5 P1.5
150 pF C CS D6 P1.6
D7 P1.7
GND INTR P2.7
ADC 0803/0804/0805
Fig. 5.24.1.
B. A/D conversion program :
MOV P1, # 0FF H ; Configure port 1 as input
Back : CLR P2.6 ; [ Make WR = 0 and
SETB P2.6 ; Make WR = 1 to generate
; start of
; conversion pulse]
Again JB P2.7, Again ; Wait for end of conversion
CLR P2.5 ; Enable read
MOV A, P1 ; Read data through port 1
SETB P2.5 ; Disable read after reading data
SJMP Back ; go for next conversion cycle
Answer
1. The Fig. 5.25.1 shows the block schematic of DAC 0808 interfaced to
8051 at port P1.
2. The output current I0 can be given as,
Vref D0 D1 D2 D3 D4 D5 D D
I0 = 6 7
R14 2 4 8 16 32 64 128 256
Microprocessor & Microcontroller 5–29 B (EC-Sem-5)
www.aktutor.in
+5V
VCC 2.5 K
D0 + V ref +5V
P1.0
P1.1 D1 R14 2.5 K
P1.2 D2 D
P1.3 D3 A Rf
8051 P1.4 D4 C I
0 out –
P1.5 D5
D6 8 Vout
P1.6
D7 0 +
P1.7 8
COMP – V ref I to V converter
VEE GND
15 pF 2.5 K
+ 15 V
Fig. 5.25.1.
2 m A 255
= 1.992 mA
256
4. It shows that the full scale output current is always less than the
reference current source of 2 mA.
4. This output current is converted into voltage by I to V converter. The
output voltage for full scale input can be given as,
V0 = 1.992 × 2.5 K = 4.98 V
PART-5
External Memory Interface, Stepper Motor and Waveform
Generation.
Questions-Answers
Que 5.26. Draw the diagram external RAM interfacing with 8051.
Assembly Programming & Instruction of 8051 5–30 B (EC-Sem-5)
www.aktutor.in
Answer
Refer Q. 4.15, Page 4–17B, Unit-4.
Answer
1. A stepper motor is a digital motor. It can be driven by digital signal.
Fig. 5.27.1 shows the typical 2 phase motor interfaced using 8051.
2. Motor shown in the circuit has two phases, with center-tap winding.
The center taps of these windings are connected to the 12 V supply.
3. Due to this, motor can be excited by grounding four terminals of the two
windings.
4. Motor can be rotated in steps by giving proper excitation sequence to
these windings.
5. The lower nibble of port 1 of the 8051 is used to generate excitation
signals in the proper sequence.
6. The Table 5.27.1 shows typical excitation sequence. The given excitation
sequence rotates the motor in anticlockwise direction.
7. To rotate motor in anticlockwise direction we have to excite motor in a
reverse sequence.
+ 12 V
Stepper
motor
X1
P1.0 X2
7407
Y1 Y
2
P1.1 + 12 V
7407
P1.2
7407
P1.3
7407
Fig. 5.27.1.
Microprocessor & Microcontroller 5–31 B (EC-Sem-5)
www.aktutor.in
8. The excitation sequence for stepper motor may change due to change in
winding connections. However, it is not desirable to excite both the ends
of the same winding simultaneously. This cancels the flux and motor
winding may damage.
Table 5.27.1 Full step excitation sequence.
Step X1 X2 Y1 Y2
1 0 1 0 1
2 1 0 0 1
3 1 0 1 0
4 0 1 1 0
1 0 1 0 1
Answer
To generate triangular wave we have to output data from 00 initially,
and it should be incremented upto FF. When it reaches FF it should be
decremented upto 00.
Program :
MOV SP, #08 H ; Initialize stack pointer
MOV RO, # 00 H
REPEAT : MOV P1, R0 ; Send digital data to the input
; of DAC 0808
INC R0 ; Increment digital data
CJNE R0 #0FF H, REPEAT ; Check digital data for peak
; output if not repeat
REPEAT : MOV P1, R0 Send digital data to the input
; of DAC 0808
DJNZ R0, REPEAT 1 ; Decrement digital data and
check digital data for least
output if not repeat
LJMP REPEAT
Answer
To generate square wave we have to output FF and then 00 on port 1 of
8051. The port 1 is connected as an input to the DAC 0808. The port 1 is
connected as an input to the DAC 0808. According to frequency
requirement delay is provided between the two outputs.
Assembly Programming & Instruction of 8051 5–32 B (EC-Sem-5)
www.aktutor.in
Program :
MOV SP, #08 H ; Initialize stack pointer
REPEAT : MOV P1, OFFH ; Load all 1’s in port 1
LCALL DELAY ; Call delay routine
MOV P, #00 H ; Load all 0’s in Port 1
LCALL DELAY ; Call delay routine
LJMP REPEAT ; Repeat
DELAY : MOV R0, #0FF H ; Load delay count
BACK : DJNZ R0, BACK ; Decrement and check
whether delay count is zero if
not repeat the operation
RET ; Return to main program
Microprocessor & Microcontroller SQ–1 B (EC-Sem-5)
www.aktutor.in
1 Introduction to
Microprocessor
(2 Marks Questions)
1.9. List down the various control and status signals of 8085.
Ans. i. Address latch enable (ALE) ii. RD (Read)
iii. WR (Write) iv. IO/ M
v. S1 and S0
2 Marks Questions SQ–4 B (EC-Sem-5)
www.aktutor.in
2 Basic Programming
Concepts
(2 Marks Questions)
2.1. Describe briefly the concept of flow chart.
Ans. It is a pictorial representation that a programmer uses for planning
the procedure for solution of problems.
2.2. Discuss the data transfer operation.
Ans. The data transfer operation is used to copy data from one register
or memory location called source to another register or memory
location called destination.
2.3. List down the various data transfer operation.
Ans. i. MOV (Move)
ii. MVI (Move immediate data)
iii. LXI (Load register pair immediate)
iv. LDA (Load accumulator direct)
v. SHLD (Store H and L register direct)
vi. STAX (Store accumulator indirect)
Microprocessor & Microcontroller SQ–7 B (EC-Sem-5)
www.aktutor.in
3 16-bit Microprocessor
(2 Marks Questions)
3.1. Differentiate between 8085 and 8086 microprocessor.
Ans.
S. No. 8085 8086
3.11. Write the control word format for BSR mode of 8255.
Ans. Control word format for BSR mode of 8255 is given as :
BSR mode
3.12. What are the basic differences between 8253 and 8254
programmable timer/counter ?
Ans.
S. No. 8253 8254
1. Operating frequency Operating frequency 0-10 MHz.
0-2.6 MHz.
2. Re ad-back co mmand not Read-back command available.
available.
2 Marks Questions SQ–10 B (EC-Sem-5)
www.aktutor.in
4 8051 Microcontroller
Basics
(2 Marks Questions)
Application
Communication
Specific Central Processing Unit (CPU) Channels
Circuit
RAM ROM
(Random Access Memory) (Read Only Memory)
Microprocessor & Microcontroller SQ–13 B (EC-Sem-5)
www.aktutor.in
Assembly
5 Programming and
Instruction of 8051
(2 Marks Questions)
5.5. Why are the ORG and END directives also called
pseudocode ?
2 Marks Questions SQ–14 B (EC-Sem-5)
www.aktutor.in
Ans.
1. ORG and END directives are called pseudocodes because they are
directives to the assembler.
2. ORG tells the assembler to place the opcode at memory location 0
while END indicates to the assembler the end of source code.
5.9. Find the timer’s clock frequency and its period for various
8051 based systems, with the following crystal frequency :
a. 12 MHz
b. 16 MHz
c. 11.592 MHz
Ans.
a. Timer’s clock frequency = 1/12 × 12 MHz = 1 MHz
and T = 1/1 MHz = 1 s
Microprocessor & Microcontroller SQ–15 B (EC-Sem-5)
www.aktutor.in
b. Timer’s clock frequency = 1/12 × 16 MHz = 1.333 MHz and
T = 1/1.333 MHz = .75 s
c. Timer’s clock frequency = 1/12 × 11.592 MHz = 921.6 kHz;
T = 1/921.6 kHz = 1.085 s