Unit - II Microprocessors-and-Microcontrollers - Compressed
Unit - II Microprocessors-and-Microcontrollers - Compressed
1
hardware, thus allowing simpler and less expensive microcomputer systems to be built.
The "5" in the model number came from the fact that the 8085 requires only a +5-Volt
(V) power supply rather than the +5 V, −5 V and
+12 V supplies the 8080 needed. The main features of 8085 μP are:
It is an 8-bit microprocessor.
It is manufactured with N-MOS technology.
It has 16-bit address bus and hence can address up to 216= 65536bytes
(64KB) memory locations through A0–A15.
The first 8 lines of address bus and 8 lines of data bus are
multiplexed AD0–AD7
Data bus is a group of 8 lines D0–D7.
It supports external interrupt request.
A 16-bit program counter (PC)
A 16-bit stack pointer (SP)
Six 8-bit general purpose register arranged in pairs: BC, DE, HL.
It requires a signal +5V power supply and operates at 3.2 MHZsingle
phase clock.
It is enclosed with 40 pins DIP (Dual in line package).
8085 Architecture
8085 consists of various units as shown in Fig. 1 and each unit performs itsown
functions. The various units of a microprocessor are listed below
Accumulator
Arithmetic and logic Unit
General purpose register
Program counter
Stack pointer
Temporary register
Flags
Instruction register and Decoder
Timing and Control unit
Interrupt control
Address buffer and Address-Data buffer
Address bus and Data bus
Accumulator
Accumulator is nothing but a register which can hold 8-bit data. Accumulator aids
in storing two quantities. The data to be processed by arithmetic and logic unit is stored
in accumulator. It also stores the result of the operation carried out by the Arithmetic
and Logic unit. The accumulator is also called an 8-bit register. The accumulator is
connected to Internal Data bus and ALU (arithmetic and logic unit). The accumulator
2
can be used to send or receivedata from the Internal Data bus.
3
Program Counter and Stack Pointer
Program counter is a special purpose register.
Consider that an instruction is being executed by processor. As soon as the ALU
finished executing the instruction, the processor looks for the next instruction to be
executed. So, there is a necessity for holding the address of the next instruction to be
executed in order to save time. This is taken care by the program counter. A program
counter stores the address of the next instruction to be executed. In other words, the
program counter keeps track of the memory address of the instructions that are being
executed by the microprocessor and the memory address of the next instruction that is
going to be executed.
Microprocessor increments the program whenever an instruction is being
executed, so that the program counter points to the memory address of the next
instruction that is going to be executed. Program counter is a 16-bit register.
Stack pointer is also a 16-bit register which is used as a memory pointer. A stack is
nothing but the portion of RAM (Random access memory).
So, does that mean the stack pointer points to portion of RAM?
Yes. Stack pointer maintains the address of the last byte that is entered into stack.
Each time when the data is loaded into stack, Stack pointer gets decremented.
Conversely it is incremented when data is retrieved from stack.
Temporary Register
As the name suggests this register acts as a temporary memory during the
arithmetic and logical operations. Unlike other registers, this temporary register can
only be accessed by the microprocessor and it is completely inaccessible to
programmers. Temporary register is an 8-bit register.
Flags
Flags are nothing but a group of individual Flip-flops. The flags are mainly
associated with arithmetic and logic operations. The flags will show either a logical (0
or 1) (i.e.) a set or reset depending on the data conditions in accumulator or various
other registers. A flag is actually a latch which can hold some bits of information. It
alerts the processor that some event has taken place.
D7 D6 D5 D4 D3 D2 D1 D0
S Z AC P CY
Fig. 1.2 Flag Register
Intel processors have a set of 5 flags.
1. Carry flag
2. Parity flag
3. Auxiliary carry flag
4. Zero flag
5. Sign flag
4
Consider two binary numbers.
For example
1100 0000
1000 0000
When we add the above two numbers, a carry is generated in the most significant
bit. The number in the extreme right is least significant bit, while the number in
extreme left is most significant bit. So, a ninth bit is generated due to the carry. So how
to accommodate 9th bit in an 8-bit register?
For this purpose, the Carry flag is used. The carry flag is set whenever a carry is
generated and reset whenever there is no carry. But there is an auxiliary carry flag?
What is the difference between the carry flag and auxiliary carry flag?
Let’s discuss with an example. Consider the two numbers given below 0000
1100
0000 1001
When we add both the numbers a carry is generated in the fourth bit from the least
significant bit. This sets the auxiliary carry flag. When there is no carry, the auxiliary
carry flag is reset. So, whenever there is a carry in the most significant bit Carry flag is
set. While an auxiliary carry flag is set only when a carry is generated in bits other than
the most significant bit.
Parity checks whether it’s even or add parity. This flag returns a 0 if it is odd
parity and returns a 1 if it is an even parity. Sometimes they are also called as parity bit
which is used to check errors while data transmission is carried out.
Zero flag shows whether the output of the operation is 0 or not. If the value of Zero
flag is 0 then the result of operation is not zero. If it is zero the flag returns value 1.
Sign flag shows whether the output of operation has positive sign or negative sign.
A value 0 is returned for positive sign and 1 is returned for negative sign.
5
Control Signals: RD’, WR’, ALE
ALE is used for provide control signal to synchronize the components of
microprocessor and timing for instruction to perform the operation.
RD (Active low) and WR (Active low) are used to indicate whether the
operation is reading the data from memory or writing the data into
memory respectively.
READY: This signal synchronizes the fast CPU and the slow memory,
peripherals. If READY is high during a read or write cycle, it indicates that
the memory or peripheral is ready to send or receive data. If READY is
low, the CPU will wait an integral number of clock cycle for READY to go
high before completing the read or write cycle. READY must conform to
specified setup and hold times.
Reset Signals: Reset in, Reset Out
RESET IN: A low on this pin;
Sets the program counter to zero (0000H)
Resets the interrupt enables and HLDA flip-flops.
Tri-states the data bus, address bus and control bus.
Affects the content of processors internal registers randomly.
On Reset, The Program counter sets to 0000h which causes the 8085 to
execute; the first instruction from address 0000H.
RESET OUT: This active high signal indicates that the processor; is being
reset. This signal is synchronized to the processor clock and it can be used
to reset other devices connected in the system.
Interrupt control
As the name suggests this control interrupts a process. Consider that a
microprocessor is executing the main program. Now whenever the interrupt signal is
enabled or requested the microprocessor shifts the control from main program to
process the incoming request and after the completion of request, the control goes back
to the main program. For example, an Input/output device may send an interrupt
signal to notify that the data is ready for input. The microprocessor temporarily stops
the execution of main program and transfers control to I/O device. After collecting the
input data, the control is transferred back to main program. Interrupt signals present in
8085 are:
INTR
RST 7.5
RST 6.5
RST 5.5
TRAP
INTR is mask able 8080A compatible interrupt. When the interrupt occurs the
processor fetches from the bus one instruction, usually one of these instructions: One of
the 8 RST instructions (RST0 - RST7). The processor saves current program counter
into stack and branches to memory location N * 8 (where N is a 3 - bit number from 0
to 7 supplied with the RST instruction).
CALL instruction (3-byte instruction). The processor calls the subroutine, address of
which is specified in the second and third bytes of the instruction.
RST5.5 is a mask able interrupt. When this interrupt is received the processor saves the
contents of the PC register into stack and branches to 2CH (hexadecimal) address.
RST6.5 is a mask able interrupt. When this interrupt is received the processor saves the
contents of the PC register into stack and branches to 34H (hexadecimal) address.
RST7.5 is a mask able interrupt. When this interrupt is received the processor saves the
contents of the PC register into stack and branches to 3CH (hexadecimal) address.
TRAP is a non-mask able interrupt. When this interrupt is received the processor saves
the contents of the PC register into stack and branches to 24H (hexadecimal) address.
All mask able interrupts can be enabled or disabled using EI and DI instructions.
RST5.5, RST6.5 and RST7.5 interrupts can be enabled or disabled individually using SIM
instruction.
Serial Input/output control
The input and output of serial data can be carried out using 2 instructionsin
8085.
SID-Serial Input Data
SOD-Serial Output Data
Two more instructions are used to perform serial-parallel conversion
needed for serial I/O devices.
SIM
RIM
Arithmetic Instructions
These instructions perform arithmetic operations such as addition,subtraction,
increment, and decrement.
Opcode Operand Description
R
ADD Add register or memory to accumulator
M
R
ADC Add register or memory to accumulator with carry
M
ADI 8-bit data Add immediate to accumulator
ACI 8-bit data Add immediate to accumulator with carry
R
SUB Subtract register or memory from accumulator
M
SUI 8-bit data Subtract immediate from accumulator
R
INR Increment register or memory by 1
M
INX R Increment register pair by 1
R
DCR Decrement register or memory by 1
M
DCX R Decrement register pair by 1
Logical Instructions
These instructions perform various logical operations with the contents ofthe
accumulator.
Opcode Operand Description
R
CMP Compare register or memory with accumulator
M
R
CMP Compare register or memory with accumulator
M
CPI 8-bit data Compare immediate with accumulator
R
ANA Logical AND register or memory with accumulator
M
ANI 8-bit data Logical AND immediate with accumulator
R
XRA Exclusive OR register or memory with accumulator
M
R
ORA Logical OR register or memory with accumulator
M
ORI 8-bit data Logical OR immediate with accumulator
R
XRA Logical XOR register or memory with accumulator
M
XRI 8-bit data XOR immediate with accumulator
Branching Instructions
This group of instructions alters the sequence of program execution either
conditionally or unconditionally.
Opcode Operand Description
JMP 16-bit address Jump unconditionally
Jx 16-bit address Jump conditionally
Immediate Addressing
In immediate addressing mode, the data is specified in the instruction itself.
The data will be a part of the program instruction.
EX. MVI B, 3EH - Move the data 3EH given in the instruction to B register;LXI SP,
2700H.
Direct Addressing
In direct addressing mode, the address of the data is specified in the instruction.
The data will be in memory. In this addressing mode, the program instructions and data
can be stored in different memory.
EX. LDA 1050H - Load the data available in memory location 1050H in to
accumulator; SHLD 3000H
Register Addressing
In register addressing mode, the instruction specifies the name of the register in
which the data is available.
EX. MOV A, B - Move the content of B register to A register; SPHL; ADD C.
Implied Addressing
In implied addressing mode, the instruction itself specifies the data to be
operated. EX. CMA - Complement the content of accumulator; RAL
Timing Diagrams
Timing diagram is the display of initiation of read/write and transfer of data
operations under the control of 3-status signals IO/M’, S1 and S0. Each machine cycle is
composed of many clock cycles. Since, the data and instructions, both are stored in the
memory, the µP performs fetch operation to read the instruction or data and then
execute the instruction. The 3-status signals: IO / M’, S1 and S0 are generated at the
beginning of each machine cycle. The unique combination of these 3-status signals
identifies read or write operation and remain valid for the duration of the cycle. Thus,
time taken by any µP to execute one instruction is calculated in terms of the clock
period. The execution of instruction always requires read and writes operations to
transfer data to or from the µP and memory or I/O devices. Each read/ write operation
constitutes one machine cycle. Each machine cycle consists of many clock periods/
cycles, called T-states.
Processor Cycle
The function of the microprocessor is divided into fetch and execute cycle of any
instruction of a program. The program is nothing but number of instructions stored in
the memory in sequence. In the normal process of
operation, the microprocessor fetches (receives or reads) and executes one instruction
at a time in the sequence until it executes the halt (HLT) instruction. Thus, an
instruction cycle is defined as the time required to fetch and execute an instruction.
For executing any program, basically 2-steps are followed sequentially with the help of
clocks
Fetch, and
Execute.
The time taken by the µP in performing the fetch and execute operations are
called fetch and execute cycle. Thus, sum of the fetch and execute cycle is called the
instruction cycle as indicated in Fig.
Instruction Cycle (IC) = Fetch cycle (FC) + Execute Cycle (EC)
Processor cycle
The 1st machine cycle of any instruction is always an Opcode fetch cycle in which
the processor decides the nature of instruction. It is of at least 4-states. It may go up to
6-states.
In the opcode fetch cycle, the processor comes to know the nature of the instruction
to be executed. The processor during (M1 cycle) puts the program counter contents on
the address bus and reads the opcode of the instruction through read process. The T1,
T2, and T3 clock cycles are used for the basic memory read operation and the T4 clock
and beyond are used for its interpretation of the opcode. Based on these
interpretations, the µP comes to know the type of additional information/data needed
for the execution of the instruction and accordingly proceeds further for 1 or 2-machine
cycle of memory read and writes.
Instruction Fetch (FC)⇒An instruction of 1 or 2 or 3-bytes is extracted from the
memory locations during the fetch and stored in the µP’s instruction register.
Instruction Execute (EC)⇒The instruction is decoded and translated into specific
activities during the execution phase.
Opcode Fetch
The 1st step in communicating between the microprocessor and memory is reading
from the memory. This reading process is called opcode fetch. The process of
opcode fetch operation requires minimum 4-clock cycles T1, T2, T3, and T4and is the
1st machine cycle (M1) of every instruction. In order to differentiate between the data
byte pertaining to an opcode or an address, the machine cycle takes help of the status
signal IO/ M, S1, and S0. The IO/ M= 0 indicates memory operation and S1 = S0 = 1
indicates Opcode fetch operation. The opcode fetch machine cycle M1 consists of 4-
states (T1, T2, T3, and T4). The 1st 3-states are used for fetching (transferring) the
byte from the memory and the 4th-state is used to decode it.
Example
Fetch a byte 41H stored at memory location 2105H.
For fetching a byte, the microprocessor must find out the memory location where it
is stored. Then provide condition (control) for data flow from memory to the
microprocessor. The process of data flow and timing diagram of fetch operation are
shown .The µP fetches opcode of the instruction from the memory as per the sequence
below
A low IO/ M’ means microprocessor wants to communicate with
memory.
The µP sends a high on status signal S1 and S0 indicating fetch
operation.
The µP sends 16-bit address. AD bus has address in 1st clock ofthe
1st machine cycle, T1.
AD7to AD0 address is latched in the external latch when ALE =1.
AD bus now can carry data.
In T2, the RD control signal becomes low to enable the memoryfor
read operation.
The memory places opcode on the AD bus
The data is placed in the data register (DR) and then it istransferred
to IR.
During T3the RDsignal becomes high and memory is disabled.
Opcode Fetch
The high order address (A15 ⇔A8) and low order address (AD7 ⇔AD0) are
asserted on 1st low going transition of the clock pulse. The timing diagram for IO/M
read are shown in Fig. The A15 ⇔A8 remains valid in T1, T2, and T3
i.e. duration of the bus cycle, but AD7⇔AD0 remains valid only in T1. Since it has to
remain valid for the whole bus cycle, it must be saved for its use in the T2 and T3. ALE is
asserted at the beginning of T1 of each bus cycle and is negated towards the end of T1.
ALE is active during T1 only and is used as the clock pulse to latch the address
(AD7⇔AD0) during T1. The RD’ is asserted near the beginning of T2. It ends at the end
of T3. As soon as the RD’ becomes active, it forces the memory or I/O port to assert
data. RD’ becomes inactive towards the end of T3, causing the port or memory to
terminate the data.
Memory and I/O Write Cycle
Immediately after the termination of the low order address, at the beginning of the
T2, data is asserted on the address/data bus by the processor. WR’ control is activated
near the start of T2 and becomes inactive at the end of T3. The processor maintains
valid data until after WR’ is terminated. This ensures that the memory or port has valid
data while WR’ is active. It is clear from figures that for READ bus cycle, the data
appears on the bus as a result of activating RD’ and for the WR’ bus cycle, the time the
valid data is on the bus overlaps the time that the WR’ is active.
Memory Write Cycle
Assume the memory address for the instruction and let the content
of accumulator is C7H. So, C7H from accumulator is now stored in
526A.
Timing Diagram for STA 526AH
CPU
Microcontroller 8051 has an 8-bit CPU. It consists of Accumulator (A
Register), B register, Arithmetic Logic Unit (ALU) and Control Unit (CU). It is
used to perform basic mathematical calculations and Logical operations. 8051
CPU can process 8-bit data only.
Memory
The 8051 has internal RAM and ROM memories. 128 bytes of RAM and
4Kbytes of ROM are available with 8051. Internal RAM has 4 register banks
each having 8 registers.
I/O Ports
8051 consist of four 8-bit ports. They are port 0, port 1, port 2 and port 3.
These ports can be programmed either input or output port. These ports are
arranged in thirty-two input/output pins.
Timer/Counter
There are two timers timer 0 and timer 1 provided in 8051. Both timers are
16 bits wide. Timers are programmed to generate desired time delays.
Registers
In the CPU of 8051, registers are used to store information
temporarily. The majority of 8051 registers are 8-bit registers. Some of the
widely used general purpose registers are A (Accumulator), B, R0, R1, R2, R3,
R4, R5, R6, R7, Data Pointer and Program Counter. Only two registers Data
pointer (DPTR) register and Program Counter (PC) are 16-bit wide.
Interrupts
There are five interrupts available in 8051, in which three are internal interrupts
and two are external interrupts. Three internal interrupts are timer 0(TF0), timer
1(TF1) and serial I/O port (RI or TI) interrupts. Two external interrupts are INT0 and
INT1.
Center of a computer
Center of embedded system.
system.
Requires more
Requires less instructions
instructions