Professional Documents
Culture Documents
MP & MC Micro Doc-20240520-Wa0000
MP & MC Micro Doc-20240520-Wa0000
Memory write
3. I/O read
4. I/O write
1. ALU:-
As the name suggests, it performs arithmetic and logical operations like
Addition, Subtraction, AND, OR, etc. on 8-bit data.
It consists of accumulator, temporary register & flag flip flop.
during operating the first operand must be stored in accumulator and the
second operand comes from temporary register which is present in either
memory or any one of the general purpose register.
After the arithmetic and logical operation the result is also
stored in accumulator.
2. Register array:-
It has eight addressable 8-bit registers: A, B, C, D, E, H, L, F, and two 16-bit registers
PC and SP. These registers can be classified as −
General Purpose Registers
Temporary Registers: a) Temporary data register b) W and Z registers
Special Purpose Registers: a)Accumulator b) Flag registers c) Instruction register
Sixteen-bit Registers: a) ProgramCounter (PC) b) Stack Pointer (SP)
Temporary Registers
(a)Temporary Data Register - The ALU has two inputs. One input is supplied by the
accumulator and other from the temporary data register. The programmer cannot access
this temporary data register. However, it is internally used for execution of most of the
arithmetic and logical instructions.
(b) W and Z registers - W and Z registers are temporary registers. These registers are
used to hold 8-bit data during the execution of some instructions. These registers are not
available for the programmer since 8085Microprocessor Architecture uses them internally.
x S-Sign flag - After the execution of arithmetic or logical operations, if bit D7 of the result is
1, the sign flag is set. In a given byte if D7 is1, the number will be viewed as a negative
number. If D7 is U, the number will be considered as a positive number.
x Z-Zero flag -The zero flag sets if the result of the operation in ALU is zero and flag resets
if the result is non zero. The zero flags are also set if a certain register content becomes
zero following an increment or decrement operation of that register.
x AC-auxiliary Carry flag - This flag is set if there is an overflow out of bit 3 i.e. carry from
lower nibble to higher nibble (D3 bit to D4 bit). This flag is used for BCD operations and it
is not available for the programmer.
x P-Parity flag - Parity is defined by the number of ones present in the accumulator. After
arithmetic or logical operation, if the result has an even number of ones, i.e.even parity,
the flag is set. If the parity is odd, the flag is reset.
x CY-Carry flag - This flag is set if there is an overflow out of bit 7. The carry flag also
serves as a borrow flag for subtraction. In both the examples shown below, the carry flag
is set.
c) Instruction Register - In a typical processor operation, the processor first fetches the
opcodeof instruction from memory (i.e. it places an address on the address bus and
memory responds by placing the data stored at the specifiedaddress on the data bus). The
CPU storesthis opcode in a register called the instruction register. Thisopcode is further
sent to the instruction decoder to select one ofthe 256 alternatives.
SixteenBit Registers
a) Program counter (PC) - Program is a sequence of instructions. As mentioned earlier,
microprocessor fetches these instructions from the memory and executes them The program
counter is a special purpose register which, at a given time,stores the address of the next
instruction to be fetched. Program Counter acts as a pointer to the next instruction. How
processor increments program counter depends on the nature of the instruction;for one-byte
instruction it increments program counter by one, for two-byte instruction it increments
program counter by two and forthree-byte instruction it increments program counter by three
such that program counter always points to the address of the next instruction.
b)Stack Pointer (SP) - The stack is a reserved area of the memory in the RAM where
temporary information may be stored. A 16-bit stack pointer is used to hold the address of
the most recent stack entry.
3. Timing and Control Unit
It provides timing and control signal to the microprocessor to perform operations. Following
are the timing and control signals, which control external and internal circuits
The first byte specifies opcode and the following two bytes specify 16-bit address.
Direct addressing: The address of the data is specified in the instruction itself. STA 2000H, IN
07H.
Register addressing: The operands are in general purpose register. MOV A, B , ADD B.
Register indirect addressing: The address of the operand is specified by register pair indirectly.
MOV A, M , ADD M.
Immediate addressing: The operand is specified within the instruction itself.MVI A,03H, ADI
12H.
Arithmetic instruction
The arithmetic instructions are addition, subtraction, increment, and decrement.
Addition
Any 8-bit number, or the content of a register, or the content of a memory location can be added
to the content of accumulator. The sum is stored in the accumulator.
The DAD instruction adds 16-bit numbers in register pairs.
Subtraction
Any 8-bit number, or the content of a register, or the content of a memory location can be
subtracted from the content of accumulator. The result is stored in the accumulator. The
subtraction is performed in 2’s complement form.
Logical instruction
These instructions perform logical operation with content of accumulator. These instructions are
AND, OR, Ex-OR, rotate, compare, and complement.
Logical AND
Any 8-bit number, or the content of a register, or the content of a memory location can be
logically ANDed with the content of accumulator. The result is stored in the accumulator.
Branching Instructions
This instruction alters the sequence of program execution either conditionally or unconditionally.
These instructions are jump, call, return, and restart.
Machine
control
operation
These instruction
are halt, interrupt,
and do nothing etc.
Mnemonics Tasks performed Addressing mode Length of the
on execution Instruction
NOP No operation Implicit One byte
HLT Halt the Implicit One byte
microprocessor
execution
DI Disable interrupts Implicit One byte
EI Enable interrupts Implicit One byte
RIM Read interrupt Implicit One byte
mask
S IM Set interrupt mask Implicit One byte
(4000H) = 14H
(4001H) = 89H
Result = 14H + 89H = 9DH
Source program
LXI H 4000H : HL points 4000H
MOV A, M : Get first operand
INX H : HL points 4001H
ADD M : Add second operand
INX H : HL points 4002H
MOV M, A : Store result at 4002H
HLT : Terminate program execution
Statement: Subtract the contents of memory location 4001H from the memory location
2000H and place the result in memory location 4002H.
2.4.2 8085 program to find 1’s and 2’s complement of 8-bit number
Problem – W rite a program to find 1’s and 2’s complement of 8-bit number where starting
addr es s i s 200 0 an d t he num be r i s s t or ed at 3000 m em or y a ddr es s and s t or e r es ul t
i nt o 30 01 a nd 3 002 m em or y a ddr es s .
Program
Me mo r y Mnemonics O p e ra n d s Comment
2007 AD I 01 [ A] < - [ A] + 0 1
• Each count is checked to determine whether it has reached final number ;if not, the loop is
repeated.
Time Delay
x Procedure used to design a specific delay.
x A register is loaded with a number , depending on thec time delay required and then the
register is decremented until it reaches zero by setting up a loop with conditional jump
instruction.
DCR C ;Decrement C 4
decrement C
= 1785 μs
= 1.8 ms
N10 = Equivalent decimal number of hexadecimal count loaded in the delay register
DCX B Decrement BC by 1 6
= 109 ms
MVI C, FFH 7T
DCR C 4T
Counting-This technique allows programmer to count how many times the instruction/set of
instructions are executed.
Indexing-This technique allows programmer to point or refer the data stored in sequential
memory location one by one.
In other words, the programmer defines the bottom of the stack and the stack grows up into
reducing address range.
Given that the stack grows backwards into memory, it is customary to place the bottom of the
stack at the end of memory to keep it as far away from user programs as possible.
In the 8085, the stack is defined by setting the SP (Stack Pointer) register.
LXI SP, FFFFH
This sets the Stack Pointer to location FFFFH (end of memory for the 8085).
The Size of the stack is limited only by the available memory
LIFO
The order of PUSHs and POPs must be opposite of each other in order to retrieve information
back into its original location.
PUSH B
PUSH D
...
P OP D
P OP B
Reversing the order of the POP instructions will result in the exchange of the contents of BC and
DE.
Subroutines
A subroutine is a group of instructions that will be used repeatedly in different locations of the
program.
Rather than repeat the same instructions several times, they can be grouped into a subroutine
that is called from the different locations.
In Assembly language, a subroutine can exist anywhere in the code. However, it is customary to
place subroutines separately from the main program.
The 8085 has two instructions for dealing with subroutines.
The CALL instruction is used to redirect program execution to the subroutine.
The RET instruction is used to return the execution to the calling routine.
PROGRAM
Address of Hex Label opcode operand Comments
the code
memory
location
8004 00
next location
of the Data.
contents of
accumulator
8008 27 DAA
label FWD
stored in
memory
location 8502.
800E 02
800F 85
8010 79 M OV A, C Carry is
moved to
accumulator
8503
8012 03
8013 85
ALGORITHM:
Step1. : Initialise H-L pair with the address of second number (XX01).
Step2. : Find its ten’s complement
Step3. : Decrement the H-L pair for the first number (XX00)
Step4. : Add the first number to the 10’s complement of second number.
Step5. : Store the result in XX02.
Step6. : Stop the execution
PROGRAM:
ADDRESS HEX LAB OPCODE OPERAND COMMENTS
CODE EL
8000 21 LXI H,8500 Initialise H-L
pair and get
theSecond
number in to
8501
location
8001 00
8002 85
8003 3E M VI A,99 [A] 99
8004 99
8005 96 SUB M 9’s complement
of second
number
ALGORITHM:
Step1: First 16 bit number is in locations 8500 & 8501 respectively
Step2: Second 16-bit number is in locations 8502 & 8503
Step3: Add the two 16-bit numbers using DAD Instruction.
Step4: Sum is stored in locations 8504 & 8505.
Step5: Carry (if any) is stored in the location 8506.
Step6: Halt
PROGRAM:
ADDRESS HEX – LABEL OPCO OP E R A COMMENTS
CODE DE ND
8000 2A,00,85 LHLD 8500 H First 16-bit
8001 00 number in H-L
8002 85 pair
8003 EB XCHG Exchange first
number to D-E
Pair
8004 2A LHLD 8502 H
8005 02
8006 85
8007 0E M VI 00 MSB of the sum
is initially 00
8008 00
8009 19 DAD D Add tw o 16 –bit
numbers
800A D2 JNC FWD Is Carry? If yes
800B 0E go to the next
800C 80 line .Else go to
the 800E
LOCATION
800D OC INR C Increment carry
800E 22 FWD SHLD 8504 H Store the LSB
800F 04 of the Sum in
8010 85 8504 & MSB in
8505 locations
8011 79 M OV A,C MSBs of the
sum is in
accumulator
8012 ST A 8506 H Store the MSB
8013 (Carry) of the
8014 result in 8506
location
8015 HLT Stop execution
Ex: INPUT: 8500- 12 H LSB of the Ist Number RESULT : 8504 - 25H LSB of the Sum
8501- 13 H MSB of the Ist Number 8505 – 25H MSB of the Sum
8502 -13 H LSB of the IInd Number 8506 -- 00 Carry .
8503 -12H MSB of the IInd number.
ALGORITHM:
Step1. : Store the first number in the locations 8500 & 8501.
Step2. : Store the second number in the locations 8502 &8503.
Step4. : Subtract the second number from the first number with borrow.
Step5. : Store the result in locations 8504 & 8505.
Step6. : Store the borrow in location 8506
Step 7: Stop the execution
PROGRAM:
BLOCK TRANSFER
Write an assembly language program to transfer a block of data from source memory
location to destination memory location.
Given data:-
Source Destination
2500H=46H 2800H= 46H
2501H=35H 2801H=35H
2502H=37H 2802H=37H
2503H=3AH 2803H=3AH
2504H=4BH 2804H=4BH
ALGORITHM:
Step 1: initialized the H-L pair to get the 1st data
Step :2 load the no. of data into B register.
Step-3: initialize the destination address in DE register pair.
Step 4: initialize source address in H-L pair
Step 5: load the data into accumulator from source memory.
Step 6: store the data from accumulator into destination memory.
Step 7: increment H-L & D-E register pair
Step 8 : decrement B-register
PROGRAM:
ADDRESS LABE OPCOD OPERAN COMMENTS
L E D
3000H LXI H, 24FFH Load immediately
24FF in H-L pair.
3003H MOV B ,M Move the data
from memory to
B-register.
3004H LXI D,2800H Load the
destination
address(2800H)
into DE register
pair.
3007H LXI H,2500H Load the source
address (2500H)
into H-L pair.
300AH LOOP MOVE A ,M Move the data
from memory to
accumulator
300BH XCHG Exchange the DE
pair with H-L pair.
3000CH MOV M,A Move the data
from accumulator
to destination
memory location.
300EH INX D Increment the DE
register pair.
300FH DCR B Decrement the B
register.
3010H JNZ LOOP Jump if no zero
into the program
3013H HLT Stop the
program.
2.4.8 Largest & Smallest numbers in an Array
PROGRAM
ADD HEX – LABEL OPCOD OPERAN COMMENTS
RESS CODE E D
8000 21,00,8 LXI H, 8500 INITIALISE H-L
5 PAIR
8003 7E M OV C,M Count in the C
register
8004 23 INX H First number in
H-L pair
8005 4E M OV A,M Move first
number in to
Accumulator
8006 0D DCR C Decrement the
count
8007 91 LOOP1 INX H Get the next
number
8008 BE CMP M Compare the
next number
with previous
number
8009 D2 JNC LOOP2 Is next number
>previous
maximum?No,go
to the
loop2
800A 0D
800B 80
800C 7E M OV A,M If,yes move the
large
number in to
Accumulator
800D 0D LOOP2 DCR C Decrement the
count
800E C2 JNZ LOOP1 If count not
equal to
zero,repeat
800F 07
8011 80
8012 78
8013 32 ST A 85XX Store the largest
number in
the location
85XX
8014 XX
8015 85
8016 76 HLT Stop the
execution
ALGORTHM :
Step1: Store the count in the Memory location pointed by H-L register.
Step2: Move the I st number of the data array in to accumulator
Step3: Compare this with the second number in Memory location.
Step4: The smaller in the two is placed in Accumulator
Step5: The number in Accumulator is compared with the next number in memory .
Step 6: The smaller number is stored in Accumulator.
Step 7; The process is repeated until the count is zero.
Step 8: Final result is stored in memory location.
Step 9: Stop the execution
PROGRAM
ADD HEX – LABEL OPCOD OPERAN COMMENTS
RESS CODE E D
8000 21 LXI H 8500 Initialise the H-L
pair.
8001 00
8002 85
8003 7E M OV C,M Count in the C
register
1.1 Opcode:
It is the short form of instruction which specify the task to be performed by the
microprocessor.
Operand:
Operand may be a register, data & address on which the opcode work.
T-State:
x The time required by the microprocessor to complete an operation of accessing memory or
input/output devices is called machine cycle.
x A t-state is measured from the falling edge of one clock pulse to the falling edge of the next
clock pulse.
Instruction cycle:
Time required to execute and fetch an entire instruction is called instruction cycle. It consists:
x Fetch cycle – The next instruction is fetched by the address stored in program counter
(PC) and then stored in the instruction register.
x Decode instruction – Decoder interprets the encoded instruction from instruction register.
Reading effective address – The address given in instruction is read from main memory
x
and required data is fetched. The effective address depends on direct addressing mode
or indirect addressing mode.
Execution cycle – In fetch cycle the opcode is fetched from memory and it is moved to
the data register, then to the instruction register.
x After that it moves to the decoder circuit to decode the instruction.
x If the operand is GPRS the execution is immediately performed.
Machine cycle- The time required by the microprocessor to complete an operation of
accessing memory or input/output devices is called machine cycle.
x It is required to perform one of the following operation.
1. Opcode fetch(4 Tstate)
2. Memory read(3 T state)
3. Memory write(3 Tstate)
4. I/O read(3 Tstate)
5. I/O write(3 Tstate)
1.2 Timing diagram for opcode fetch
I n O p c o de f e t c h ( t 1 - t 4 T s t a t e s ) :
1. 00 – lower bit of address where opcode is stored, i.e., 00
2. 20 – higher bit of address where opcode is stored, i.e., 20.
3. ALE – provides signal for multiplexed address and data bus. Only in t1 it used as
address bus to fetch lower bit of address otherwise it will be used as data bus.
4. RD (low active) – signal is 1 in t1 & t4 as no data is read by microprocessor.
Signal is 0 in t2 & t3 because here the data is read by microprocessor.
5. WR (low active) – signal is 1 throughout, no data is written by microprocessor.
6. IO/M (low active) – signal is 1 in throughout because the operation is performing
on memory.
7. S0 and S1 – both are 1 in case of opcode fetching.
N e a t s k et c h f o r t h e t i m i n g d i a g r a m f o r 8 0 8 5 i n st r u ct i o n M V I :
Example: MVI B, 45
Opcode: MVI
Operand: B is the destination register and 45 is the source data which needs to be transferred
t o t he r egi s t er .
’45’ data will be stored in the B register.
I n O p co d e f et ch ( t 1- t 4 T st at e s ) –
x 00 – lower bit of address where opcode is stored.
x 20 – higher bit of address where opcode is stored.
x A LE – P r ov i des s i gnal f or m ul t i pl ex ed add r e s s and dat a b us . O nl y i n t 1 i t us ed as
address bus to fetch lower bit of address otherwise it will be used as data bus.
R D ( l ow ac t i v e) – S i gn al i s 1 i n t 1 & t 4, no dat a i s r ead b y m i c r opr o c es s or . S i gnal i s 0
i n t 2 & t 3, dat a i s r ead b y m i c r opr oc es s or .
W R (low active) – Signal is 1 throughout, no data is written by microprocessor.
IO/M (low active) – Signal is 0 in throughout, operation is performing on memory.
S0 and S1 – Signal is 1 in t1 to t4 states, as to fetch the opcode from the memory.
I n O p co d e r ead ( t 5- t 7 T st at e s ) –
Neat sketch for the timing diagram for 8085 instruction LDA:
COURSE MATERIAL
Chapter-4
(Microprocessor Based System Development Aids)
4.1 Concept of interfacing:
x I nt er f ac i ng i s a t ec hni q ue t o c onn ec t i nput d e v i c es , out put dev i c es and m em or y t o ot he r
peripheral with the microprocessor.
x W e knoe that the microprocessor is useless until and unless we do not connect any
peripherals with it.
4 . 2 D e f i n e Ma p p i n g :
Mapping is a technic by which we can address various memories ICs and it is of two types.
Differentiate betw een memory mapped I/O and I/O mapped I/O.
Features M e mo r y M a p p e d I O I O M a p p e d I O
I O d e v i c es a r e Th e y c a n n o t b e
accessed like any accessed like any
o t h e r m em o r y o t h e r m em o r y
Ad d r e s s i n g location. location.
Th e y a r e Th e y a r e
a s s i g n e d w i t h 16 - a s s i g n e d w i t h 8-
b i t a d dr e s s b i t a d dr e s s
Address Size values. values.
T h e i n s t r uc t i o n T h e i n s t r uc t i o n
I n s t r uc t i o n s u s e d ar e L D A an d u s e d ar e I N a n d
Used S TA , e t c . O U T.
Cycles involved
Cycles involved d u r i n g o p er a t i on
d u r i n g o p er a t i on a r e IO r e a d a n d
a r e M e m or y I O w r i t e s i n th e
R e a d , M e m or y c a s e of I O
Cycles W rite. Ma p p e d I O .
A n y r e g i s t e r ca n O n l y A c c u m u l a t or
c o m m un i c a t e w i t h can communicate
the IO device in with IO devices in
Re gister s c a s e of M e m o r y c a s e of I O
Communicating Ma p p e d I O . Ma p p e d I O .
N o s e p ar a t e
c o n t r o l s i g n al
required since we
have unified
m e m or y s p a c e i n S p e c i a l c o n tr o l
t h e c a se o f s i g n a l s ar e us e d
Me m o r y Ma p p e d in the case of IO
C o n t r o l Si g n a l IO. Ma p p e d I O .
Me m o r y Ma p p i n g :
In this technique memory location are identified by input &output devices.
Advantage:
x More than 256 number of memory location can be specified by this technique.
x The CPU can be transfer the data within the input or output device directly with the
ac c um ul at or s , s o t hi s t ec hni q ue i s v er y f as t .
D i sad van t ag e:
x T he c om pl ex i t y of t he pr og r am i s v er y l ar g e.
I / O Ma p p i n g :
x I n t hi s t ec hni qu e t he I / O dev i c es ar e c ons i de r ed as a m em or y l oc at i on.
x To access I/O devices we required two control signal that is IOR’ & IOW ’.
x W e c a n n o t a c c e s s m o r e t h a n 2 5 6 n u m b e r o f I/ O p o r t s .
Advantage :
x A ddr es s s pac e i s l es s .
x O nl y t w o i ns t r uc t i ons ar e us e d.
D i sad van t ag e:
MEMORY INTERFACING:
1. Microprocessor 8085 can access 64Kbytes memory since address bus is 16-bit. But it is
not always necessary to use full 64Kbytes address space. The total memory size depends
upon the application.
2. Generally EPROM (or EPROMs) is used as a program memory and RAM (or RAMs) as a
data memory. W hen both, EPROM and RAM are used, the total address space 64Kbytes
is shared by them.
3. The capacity of program memory and data memory depends on the application.
4. It is not always necessary to select 1 EPROM and 1 RAM. W e can have multiple EPROMs
and multiple RAMs as per the requirement of application.
5. We can place EPROM/RAM anywhere in full 64 Kbytes address space. But program
memory (EPROM) should be located from address 0000H since reset address of 8085
microprocessor is 0000H.
6. It is not always necessary to locate EPROM and RAM in consecutive memory For
example : If the mapping of EPROM is from 0000H to OFFFH, it is not must to locate RAM
from 1000H. W e can locate it anywhere between 1000H and FFFFH. W here to locate
memory component totally depends on the application.
In absolute decoding technique, all the higher address lines are decoded to select the memory
chip, and the memory chip is selected only for the specified logic levels on these high-order
address lines; no other logic levels can select the chip. Fig. 4.14 shows the Memory Interfacing in
8085 with absolute decoding. This addressing technique is normally used in large memory
systems.
Linear decoding:
In small systems, hardware for the decoding logic can be eliminated by using individual high-
order address lines to select memory chips. This is referred to as linear decoding. Fig. 4.15
shows the addressing of RAM with linear decoding technique. This technique is also
called partial decoding. It reduces the cost of decoding circuit, but it has a drawback of multiple
addresses (shadow addresses).
Fig. 4.15 shows the addressing of RAM with linear decoding technique. A15 address line, is
directly connected to the chip select signal of EPROM and after inversion it is connected to the
chip select signal of the RAM. Therefore, when the status of A15 line is ‘zero’, EPROM gets
selected and when the status of A15 line is ‘one’ RAM gets selected. The status of the other
address lines is not considered, since those address lines are not used for generation of chip
select signals.
x 8255 is a general purpose programmable device used for data transfer between processor
and I/O devices. • It has 3 programmable I/O ports (PA,PB &PC) and port operation
(IN/OUT Port) is defined by control word in the control word register. • Ports are operated
in two modes: • i) I/O modes: Mode 0, Mode 1,& Mode 2 • Ii) BSR (Bit set/Reset) mode
The 8255A has 24 input output pins that can be grouped primarily in two 8 bits parallel ports: A
and B, with the remaining 8 bits as port C. The 8 bits of port C can be used as individual bits or
be grouped in two four bits ports: Cupper (CU) and Clower (CL) as in figure (a). The functions of
these ports are defined by writing a control word in the control registers.
Ports A, B, and C
The 8255 contains three 8-bit ports (A, B, and C). All can be configured to a wide variety of
functional characteristics by the system software but each has its own special features or
"personality" to further enhance the power and flexibility of the 8255.
Port A One 8-bit data output latch/buffer and one 8-bit data input latch. Both "pull-up" and "pull-
down" bus-hold devices are present on Port A.
Port B One 8-bit data input/output latch/buffer and one 8-bit data input buffer.
Port C One 8-bit data output latch/buffer and one 8-bit data input buffer (no latch for input). This
port can be divided into two 4-bit ports under the mode control. Each 4-bit port contains a 4-bit
latch and it can be used for the control signal output and status signal inputs in conjunction with
ports A and B.
D6 & D5 These are used to set port A mode. for 00, it is m0 mode, for 01, it is m2 mode and 10 or 11, it is m
D3 1 when higher nibble of port C is taking input, and 0 when higher nibble is sending output.
D0 1 when lower nibble of port C is taking input, and 0 when lower nibble is sending output.
PA0 to PA1
These pins are the data lines for the port A. These pins are equally distributed on both sides of
the top of the 8255 IC. The keys 1 to 4 and 37 to 40 are the pins devoted for port A.
PB0 to PB1
These pins are the data lines for Port B and the keys 18 to 25 are the pins that carry the data of
port B.
PC0 to PC1
These pins are the data lines for the port C. The keys 10 to 17 carry the data bits of port A.
Among these, the pins 10 to 13 are the Port C upper pins, and 314 to 17 are the pins devoted for
port C lower.
D0 to D7
These pins carry the 8-bit binary code which is used to instruct the working of the entire IC.
These pins together are called as the control word or control register. The keys 27 to 34 carry the
contents of the control word.
A0 and A1
These pins decide which port will be selected for transferring the data. These keys are present at
pins 8 and 9.
A0 A1 Port selected
0 0 Port A
0 1 Port B
1 0 Port C
1 1 Control Register
RD'
It is an active low signal key which puts the IC in reading mode. It is present at key number 5.
WR'
It is an active low signal key which puts the IC in writing mode. It is present at key number 36.
CS'
It is also an active low signal key which is responsible for chip selection. The key number 6 is
devoted to chip select key.
RESET
This key present at 35 number when in set mode, resets the entire data present in all the keys to
their default values.
GND
VCC
The VCC key is from where the IC receives the 5V input. It is present at the key 26.
Follow the initial 3 steps of interfacing of 8255 with 8085 that are explained before.
• Therefore I to V converter is used to convert analog output current of DAC to equivalent analog
voltage. • PA 0 -PA 7 pins of Port A are connected to D 0 -D 7 pins of DAC.
• In above DAC dual power supply of +/- 10 V is applied with reference voltage 10 V as shown in
diagram.
The control word format of 8255 for above interfacing is given as: • Control word = 80 H
PROGRAM CODE
8009 C3, 02, 80 JMP ROTATE Jump to ROTATE for next phase
MVI A, 24H
MVI A, 12H
MVI A, 24H
MVI A, 09H
MVI A, 12H
JMP START
Delay Subroutine:
DELAY: LXI D, Count: Load count to give 0.5 sec delay
JNZ DELAY
These are
1. Instruction pointer(IP)
5. Flag Register(FR)
x The 8086 has a total of fourteen 16-bit registers including a 16 bit register called the status
register (flag register), with 9 of bits implemented for status and control flags.
x There are four different 64 KB segments for instructions, stack, data and extra data. To
specify where in 1 MB of processor addressable memory these 4 segments are located
the processor uses four segment registers:
Segment Registers
1.Code segment (CS)
It is a 16-bit register containing address of 64KB segment with program stack. By default, the
processor assumes that all data referenced by the stack pointer (SP) and base pointer (BP)
registers is located in the stack segment. SS register can be changed directly using POP
instruction.
It is a 16-bit register containing address of 64KB segment with program data. By default, the
processor assumes that all data referenced by general registers (AX, BX, CX, and DX) and
index register (SI, DI) is located in the data and Extra segment.
Data Registers
1) AX (Accumulator)
It is consists of two 8-bit registers AL and AH, which can be combined together and used
as a 16-bit register AX. AL in this case contains the loworder byte of the word, and AH
contains the high-order byte. Accumulator can be used for I/O operations and string
manipulation.
2) BX (Base register)
x It is consists of two 8-bit registers BL and BH, which can be combined together and
used as a 16-bit register BX. BL in this case contains the loworder byte of the word,
and BH contains the high-order byte.
3) CX (Count register)
x It is consists of two 8-bit registers CL and CH, which can be combined together and
used as a 16-bit register CX. W hen combined, CL register contains the low-order
byte of the word, and CH contains the high-order byte.
x 8086 has the LOOP instruction which is used for conuter purpose when it is
executed CX/CL is automatically decremented by 1.
4) DX (Data register)
x In integer 32-bit multiply and divide instruction the DX register contains high-
order word of the initial or resulting number.
Pointer register
1. Stack Pointer (SP) is a 16-bit register is used to hold the offset address for stack
segment.
2. Base Pointer (BP) is a 16-bit register is used to hold the offset address for stack segment.
i)BP register is usually used for based, based indexed or register indirect addressing.
ii)The difference between SP and BP is that the SP is used internally to store the address
in case of interrupt and the CALL instrn.
3. Source Index (SI) and Destination Index (DI ) These two 16-bit register is used to
hold the offset address for DS and ES in case of string manipulation instrn.
i. SI is used for indexed, based indexed and register indirect addressing, as well as a
source data addresses in string manipulation instructions.
ii. DI is used for indexed, based indexed and register indirect addressing, as well as a
destination data addresses in string manipulation instructions.
It is a 16-bit register. It acts as a program counter and is used to hold the offset address
for CS
Flag register
A flag is a 16-bit register containing 9 one bit flags.
x This flag is set if an overflow occurs. i.e. if the result of a signed operation is large
enough to be accommodated in a destination register.
x This is used by string manipulation instructions. If this flag bit is ‘0’, the string is
processed beginning from the lowest address to the highest address. i.e. auto-
incrementing mode.
x Otherwise, the string is processed from the highest address towards the lowest
address, i.e. auto-decrementing mode.
x If this flag is set, the maskable interrupts are recognized by the CPU.
Otherwise they are ignored. Setting this bit enables maskable interrupts.
x If this flag is set, the processor enters the single step execution mode. In
other words, a trap interrupt is generated after execution of each instruction.
The processor executes the current instruction and the control is transferred
to the Trap interrupt service routine.
x This flag is set when the result of any computation is negative. For signed
computations, the sign flag equals the MSB of the result.
x set if there was a carry from or borrow to bits 0-3 in the AL register.
x set if parity (the number of "1" bits) in the low-order byte of the result is even.
Minimum and Maximum Modes: – The minimum mode is selected by applying logic 1 to the MN /
MX input pin. This is a single microprocessor configuration. – The maximum mode is selected by
applying logic 0 to the MN / MX input pin. This is a multi micro processors configuration.
x It provides a full 16 bit bidirectional data bus and 20 bit address bus.
x The bus interface unit is responsible for performing all external bus operations.
x Instruction fetch , Instruction queuing, Operand fetch and storage, Address calculation
relocation and Bus control.
x These prefetching instructions are held in its FIFO queue. W ith its 16 bit data bus, the BIU
fetches two instruction bytes in a single memory cycle.
x After a byte is loaded at the input end of the queue, it automatically shifts up through the
FIFO to the empty location nearest the output.
x The EU accesses the queue from the output end. It reads one instruction byte after the
other from the output of the queue. If the queue is full and the EU is not requesting access
to operand in memory.
x These intervals of no bus activity, which may occur between bus cycles, are known as
Idle state.
x If the BIU is already in the process of fetching an instruction when the EU request it to
read or write operands from memory or I/O, the BIU first completes the instruction fetch
bus cycle before initiating the operand read / write cycle.
x The BIU also contains a dedicated adder which is used to generate the 20bit physical
address that is output on the address bus. This address is formed by adding an appended
16 bit segment address and a 16 bit offset address.
x For example: The physical address of the next instruction to be fetched is formed by
combining the current contents of the code segment CS register and the current contents
of the instruction pointer IP register.
x The EU extracts instructions from the top of the queue in the BIU, decodes them,
generates operands if necessary, passes them to the BIU and requests it to perform the
read or write bys cycles to memory or I/O and perform the operation specified by the
instruction on the operands.
x During the execution of the instruction, the EU tests the status and control flags and
updates them based on the results of executing the instruction.
x If the queue is empty, the EU waits for the next instruction byte to be fetched and shifted
to top of the queue.
x W henever this happens, the BIU automatically resets the queue and then begins to fetch
instructions from this new location to refill the queue.
The BIU fetches instructions using the CS and IP, written CS: IP, to contract the 20-bit address.
Data is fetched using a segment register (usually the DS) and an effective address (EA)
computed by the EU depending on the addressing mode.
AD15-AD0:
These are the time multiplexed memory I/O address and data lines. Address remains
on the lines during T1 state, while the data is available on the data bus during T2, T3, Tw and
T4.
A19/S6, A18/S5, A17/S4, A16/S3:
These are the time multiplexed address and status lines. During T1 these
are the most significant address lines for memory operations. During I/O
operations, these lines are low. During memory or I/O operations, status
information is available on those lines for T2, T3, Tw and T4.
• A16/S3,A17/S4-
A16,A17 are multiplexed with segment identifier signals S3
and S4 which combinedly indicate which segment register
is presently being used for memory accesses as in below
fig.
S4 S3 Indication
0 0 Extrasegment(ES)
0 Stack segment(SS)
1
1 Code segment(CS)
0
• A18/s5: A18 is multiplexed with status S5 of the interrupt enable flag bit
which is updated at the beginning of each clock cycle.
• A19/s6: A18 is multiplexed with status S6.
0 0 Whole W ord
1 1 None
(Read):
• This signal on low indicates the peripheral that the processor is performing s
memory or I/O read operation. The signal is active low.
READY:
• This is the acknowledgement from the slow device or memory that they have
completed the data transfer. The signal made available by the devices is
synchronized by the 8284A clock generator to provide ready input to the
8086. This signal is active high.
• enter into wait states and remain idle : READY = 0
• no effect on the operation of µ : READY = 1
:
This input is examined by a ‘W AIT’ instruction.
•
If the TEST pin goes low, execution will continue, else the processor remains
•
in an idle state.
CLK (Clock Input):
• The clock input provides the basic timing for processor operation and bus
control activity. VCC (power supply) : +5.0V, ±10% RESET:
• µ : reset if RESET is high
2.LOCK’:
• This output pin indicates that other system bus master will be prevented from gaining the
system bus, while the LOCK signal is low
• The LOCK signal is activated by the ‘LOCK’ prefix instruction and remains active until the
completion of the next instruction. W hen the CPU is executing a critical instruction which
requires the system bus, the LOCK prefix instruction ensures that other processors connected
in the system will not gain the control of the bus.
3. QS1, QS0 (queue status)
• These lines give information about the status of the code-prefetch queue. These are
active during the CLK cycle after while the queue operation is performed
QS 1 QS 0 Indication
0 0 No operation
1 0 Empty Queue
x These pins are used by the other local bus master in maximum mode, to force the
processor to release the local bus at the end of the processor current bus cycle.
x Each of the pin is bidirectional with RQ/GT0 having higher priority than RQ/GT1.
Addressing mode indicates a way of locating data or operands. Depending upon the data types
used in the instruction and the memory addressing modes, any instruction may belong to one or
more addressing modes, or some instruction may not belong to any of the addressing modes.
Thus the addressing modes describe the types of operands and the way they are accessed for
executing an instruction. Here, we will present the addressing modes of the instructions
depending upon their types. According to the flow of instruction execution, the instructions may
be categorized as
(i) Sequential control flow instructions and
Sequential control flow instructions are the instructions, which after execution, transfer
control to the next instruction appearing immediately after it (in the sequence) in the
program. For example, the arithmetic, logical, data transfer and processor control
instructions are sequential control flow instructions. The control transfer instructions, on
the other hand, transfer control to some predefined address somehow specified in the
instruction after their execution. For example, INT, CALL, RET and JUMP instructions fall
under this category.
The addressing modes for sequential control transfer instructions are explained as
follows:
1. Immediate:
In this type of addressing, immediate data is a part of instruction, and appears in the
form of successive byte or bytes.
In the above example, 0005H is the immediate data. The immediate data may be 8-bit
or 16-bit in size.
2. Direct:
In the direct addressing mode, a 16-bit memory address (offset) is directly specified in
the instruction as a part of it.
Here, data resides in a memory location in the data segment, whose effective address
may be computed using 5000H as the offset address and content of DS as segment
address. The effective address, here, is 10H*DS+5000H.
3. Register:
In register addressing mode, the data is stored in a register and it is referred using the
particular register. All the registers, except IP, may be used in this mode.
4. Register Indirect:
Sometimes, the address of the memory location, which contains data or operand, is
determined in an indirect way, using the offset registers. This mode of addressing is
known as register indirect mode. In this addressing mode, the offset address of data is
in either BX or SI or DI registers. The default segment is either DS or ES. The data is
supposed to be available at the address pointed to by the content of any of the above
registers in the default data segment.
Here, data is present in a memory location in DS whose offset address is in BX. The
effective address of the data is given as 10H*DS+ [BX].
5. Indexed:
In this addressing mode, offset of the operand is stored in one of the index registers.
DS and ES are the default segments for index registers SI and DI respectively. This
mode is a special case of the above discussed register indirect addressing mode.
Here, data is available at an offset address stored in SI in DS. The effective address,
in this case, is computed as 10H*DS+ [SI].
6. Register Relative:
In this addressing mode, the data is available at an effective address formed by adding
an 8-bit or 16-bit displacement with the content of any one of the registers BX, BP, SI and
DI in the default (either DS or ES) segment. The example given before explains this
mode.
7. Based Indexed:
The effective address of data is formed, in this addressing mode, by adding content of
a base register (any one of BX or BP) to the content of an index register (any one of SI
or DI). The default segment register may be ES or DS.
Here, BX is the base register and SI is the index register. The effective address is
computed as 10H*DS+ [BX] + [SI].
The effective address is formed by adding an 8-bit or 16-bit displacement with the sum
of contents of any one of the bases registers (BX or BP) and any one of the index
registers, in a default segment. Example: MOV AX, 50H [BX] [SI]
2. Arithmetic instructions
4. String instructions
POP : Pop the word from top of the stack to the specified location
XCHG : Exchange the contents of the specified source and destination operands one
of which may be a register or memory location.
Addition instructions:
4. NEG : Negate or invert each bit of a specified byte or word and add 1(2’s
complement)
Multiplication instructions:
Division instructions:
4. CBW : Fill upper byte of word with copies of sign bit of lower byte
5. CW D : Fill upper word of double word with sign bit of lower word.
3. Bit Manipulation instructions : These instructions include logical , shift and rotate
instructions in which a bit of the data is involved.
Logical instructions:
2. AND : ANDing each bit in a byte or word with the corresponding bit in another byte
or word.
3. OR : ORing each bit in a byte or word with the corresponding bit in another byte or
word.
4. XOR : Exclusive OR each bit in a byte or word with the corresponding bit in another
byte or word.
Shift instructions:
Rotate instructions:
1. ROL : Rotate bits of byte or word left, MSB to LSB and to Carry Flag [CF]
2. ROR : Rotate bits of byte or word right, LSB to MSB and to Carry Flag [CF]
4. String instructions:
These instructions are used to execute a series of instructions for certain number of
times.
ASSEMBLER DIRECTIVES :
Assembler directives are the directions to the assembler which indicate how an
operand or section of the program is to be processed. These are also called pseudo
operations which are not executable by the microprocessor. The various directives are
explained below.
1. ASSUME : The ASSUME directive is used to inform the assembler the name of the
logical segment it should use for a specified segment.
Ex: ASSUME DS: DATA tells the assembler that for any program instruction which
refers to the data segment ,it should use the logical segment called DATA.
2.DB -Define byte. It is used to declare a byte variable or set aside one or more
storage locations of type byte in memory. For example, CURRENT_VALUE DB 36H
tells the assembler to reserve 1 byte of memory for a variable named CURRENT_
VALUE and to put the value 36 H in that memory location when the program is loaded
into RAM .
3. DW -Define word. It tells the assembler to define a variable of type word or to
reserve storage locations of type word in memory.
4. DD(define double word) :This directive is used to declare a variable of type double
word or restore memory locations which can be accessed as type double word.
5.DQ (define quadw ord) :This directive is used to tell the assembler to declare a
variable 4 words in length or to reserve 4 words of storage in memory .
6.DT (define ten bytes):It is used to inform the assembler to define a variable which is
10 bytes in length or to reserve 10 bytes of storage in memory.
7. EQU –Equate It is used to give a name to some value or symbol. Every time the
assembler finds the given name in the program, it will replace the name with the value
or symbol we have equated with that name.
8.ORG -Originate : The ORG statement changes the starting offset address of the
data. It allows to set the location counter to a desired value at any point in the
program.For example the statement ORG 3000H tells the assembler to set the location
counter to 3000H.
10.END- End program .This directive indicates the assembler that this is the end of the
program module.The assembler ignores any statements after an END directive.
11. ENDP- End procedure: It indicates the end of the procedure (subroutine) to the
assembler.
12.ENDS-End Segment: This directive is used with the name of the segment to
indicate the end of that logical segment.
ORG 100h
MOV AL, VAR1 // check value of VAR1 by moving it to the AL.
LEA BX, VAR1 //get address of VAR1 in BX.
MOV BYTE PT R [BX], 44h // modify the contents of VAR1.
MOV AL, VAR1 //check value of VAR1 by moving it to the AL.
RET
VAR1 DB 22h
END
x The main difference between 8 bit and 16 bit microcontrollers is the width of the data pipe.
As you may have already deduced, an 8 bit microcontroller has an 8 bit data pipe while a
x This fundamental difference between 8 bit and 16 bit microcontrollers is felt during
mathematical operations. A 16 bit number gives you a lot more precision than 8 bit
numbers. Although relatively rare, using an 8 bit microcontroller may not suffice the
x 16 bit microcontrollers are also more efficient in processing math operations on numbers
that are longer than 8 bits. A 16 bit microcontroller can automatically operate on two 16 bit
numbers, like the common definition of an integer. But when you are using an 8 bit
x The functions implemented to operate on such numbers will take additional cycles.
Depending on how processing intensive your application is and on how many calculations
microcontrollers can only use 8 bits, resulting in a final range of 0x00 – 0xFF (0-255) every
cycle. In contrast, 16 bit microcontrollers, with its 16 bit data width, has a range of 0x0000
– 0xFFFF (0-65535) for every cycle. A longer timer maximum value can surely come in
x Initially, the price of 16 bit microcontrollers was way above that of 8 bit microcontrollers.
But as time progressed and designs improved, the price of 8 bit and 16 bit microcontrollers
has reduced quite a lot. 8 bit microcontrollers can be purchased dirt cheap. W hile 16 bit
microcontroller cost more, prices tend to vary a lot depending on the features that are
RISC Processor:
CISC Processor
x The CISC Stands for Complex Instruction Set Computer, developed by the Intel. It has
a large collection of complex instructions that range from simple to very complex and
specialized in the assembly language level, which takes a long time to execute the
instructions.
x So, CISC approaches reducing the number of instruction on each program and ignoring
the number of cycles per instruction.
x It emphasizes to build complex instructions directly in the hardware because the hardware
is always faster than software. However, CISC chips are relatively slower as compared to
RISC chips but use little instruction than RISC. Examples of CISC processors are VAX,
AMD, Intel x86 and the System/360.
x Irrespective of the manufacturer, the internal hardware design i.e. the 8051 Microcontroller
Architecture remains more or less the same. The following image shows the 8051
Microcontroller Architecture in a block diagram style.
We have seen the internal architecture of the 8051 Microcontroller in the above section.
Now, we will see the features of the 8051 Microcontroller Architecture.
Some of the features like internal ROM and RAM will vary with the specific model of the
8051 Microcontroller.
Pin 1 to Pin 8 are assigned to Port 1 for simple I/O operations. They can be configured
as input or output pins depending on the logic control i.e. if logic zero (0) is applied to the
I/O port it will act as an output pin and if logic one (1) is applied the pin will act as an
input pin. These pins are also referred to as P1.0 to P1.7 (where P1 indicates that it is a
pin in port 1 and the number after ‘.’ tells the pin number i.e. 0 indicates first pin of the
p o r t . S o , P 1 . 0 m e a n s f i r s t p i n o f p o r t 1 , P 1 . 1 m e a n s s e c o n d p i n o f th e p o r t 1 a n d s o o n ) .
T hes e pi ns ar e bi di r ec t i onal pi ns .
x P i n 9 ( R ST ) –
Reset pin. It is an active-high, input pin. Therefore if the RST pin is high for a minimum of
2 machine cycles, the microcontroller will reset i.e. it will close and terminate all
a c t i v i t i e s . It i s o f t e n r e f e r r e d a s “ p o w e r - o n - r e s e t ” p i n b e c a u s e i t i s u s e d t o r e s e t t h e
m i c r oc ont r ol l er t o i t ’ s i ni t i al v al u es w hen po w er i s on ( hi g h) .
x Pin 10 to pin 17 are port 3 pins which are also referred to as P3.0 to P3.7. These
pins are similar to port 1 and can be used as universal input or output pins. These
p in s a r e b id i r e c t io n a l p in s .
x These pins also have some additional functions which are as follows:
P 3. 0 ( R X D )
10th pin is RXD (serial data receive pin) which is for serial input. Through this input
s i gnal m i c r oc ont r ol l er r ec ei v es d at a f or s er i al c om m uni c at i on.
P 3. 1 ( T X D ) :
11th pin is TXD (serial data transmit pin) which is serial output pin. Through this
out put s i gn al m i c r oc on t r ol l er t r ans m i t s dat a f or s er i al c om m uni c at i o n.
P 3. 2 an d P 3. 3 ( I N T 0′ , I N T 1′ ) :
12th and 13th pins are for External Hardware Interrupt 0 and Interrupt 1 respectively.
W hen this interrupt is activated(i.e. when it is low), 8051 gets interrupted in whatever
it is doing and jumps to the vector value of the interrupt (0003H for INT0 and 0013H
for INT1) and starts performing Interrupt Service Routine (ISR) from that vector
l oc at i on.
P 3. 4 an d P 3. 5 ( T 0 an d T 1) :
14t h a nd 15t h pi n ar e f or T i m er 0 and T i m er 1 ex t er na l i np ut . T he y c an be c o nn ec t ed
with 16 bit timer/counter.
P 3. 7 ( R D ’ ) :
17th pin is for external memory read i.e. reading data from external memory.
P i n 20 ( G N D ) –
This pin is connected to the ground. It has to be provided with 0V power supply.
Hence it is connected to the negative terminal of the power supply.
P i n 2 9 ( PS E N ) –
P S E N s t ands f or P r ogr am S t or e E nabl e. I t i s out put , ac t i v e- l o w pi n. T hi s i s us ed t o
read external memory. In 8031 based system where external ROM holds the program
code, this pin is connected to the OE pin of the ROM.
Me m o r y o r g a n i z a t i o n :
x In the 8051, the memory is organized logically into program memory and data
memory separately. The program memory is read-only type; the
data memory is organized as read–write memory.
x Again, both program and data memories can be within the chip or
outside.
x The Intel 8051 has 128 bytes of RAM and 4 KB of ROM within the chip.
The address bus of the 8051 is 16 bits wide. So it can access 64 KB of
memory.
INTERNAL RAM STRUCTURE:
x The 8051 has 128 bytes of internal data RAM, which is accessible as
bytes or sometimes as bits.
x The address of the internal RAM starts at 00H and occupies space up to
7FH. The RAM space is divided into three blocks—the register banks, the
bit-addressable memory, and the scratch pad memory.
The 8051 has four register banks of eight registers each, with addresses from
00H to 1FH. In assembly language, they are addressed by the
names R0–R7.
x The register banks are identified with 2 bits in the processor status word.
The PSW has two bits for identifying the register bank, i.e., 00 represents
bank 0, 01 represents bank 1, 10 represents bank 2, and 11 represents
bank 3.
x In the 8051, bitwise operations are also possible with special instructions
using the bit addresses. The bit-addressable memory is both bit-
addressable (from 00H to 7FH) and byte-addressable (from 20H to 2FH).
Bit operations are helpful in many control algorithms.
x Using general-purpose scratch pad memory, programmers can read and
write data at any time for any purpose. This memory ranges from the
byte address 30H to the address 7FH.
SPECIAL FUNCTION REGISTERS (SFRs):
SFR, which occupies upper 128 bytes of internal memory are the
registers, that control the entire processor
They can e accessed by DIRECT addressing.
The registers available in the 8051 are as follows :
Accumulators - A and B
• Process Status W ord - PSW
• I/O port registers - P0, P1, P2, P3
• Data pointers - DPH and DPL
• Serial data buffer register - SBUF
• Stack pointer - SP
• Timer registers - TH0, TH1 and TL0, TL1
• Timer Control Registers - TCON, TMOD
• Power and Port control - PCON, SCON
• Interrupt Control Registers - IP, IE.
• Programmers should not use the addresses in the range 80H to FFH
(other than SFR) as it is used by INTEL CORPORATION for expansion
functions of 8051.
The 8051 has two accumulators -A register and B register. The register B
forms the accumulator for multiplication and division instructions and for
other instructions it can be accessed as a general purpose register.
The stack in the 8051 is organized within the internal RAM area.
The stack pointer is eight bits wide and has to be initialized with an
address in the RAM area. W hen the 8051 is reset, the stack pointer is by
default set to 07H.
The stack pointer is incremented before storing a data in the stack.
Similarly, while reading data from the stack, the data is read first and
then the stack pointer is decremented.
8051 Timers :
x The 8051 comes -with two 16 bit timers, both of which may be
controlled, set, read, and configured individually.
x he 8051 timers have three general functions: Programming predefined length
of time, and then issuing an interrupt request.
x Counting the transitions on an external pin,
Generating baud rates for the serial port.
x Basically the timers are the digital counters which are incremented at
the pulses given to it. The timers can be controlled to -function through
four SFRs namely, TMOD, TCON, TH0/TL0 and TH1/TL1.
x The timers will have overflow when it counts to full value and resets to 0
upon next count. The overflow in the timers will set the two bits in the TCON
SFR. This overflow can be programmed to interrupt the microcontroller execution
and execute a predefined subroutine .
x If the timer registers are incremented by the internal clock pulses from
the microcontroller, then the operation is termed as ‘Timing’ operation.
Meanwhile if the timer registers get their clock pulses from an external
device through the port 3 pins of 8051, then the operation is termed as ‘Counting’.
Timer 0 external input pin P3.4 (T0) is used give clock input to timer 0 to
act as counter.
x Timer 1 external input pin P3.5 (T1) is used give clock input to timer 1.
The 8051 has two timers and each of them will have similar operations
and functions. The timer in 8051 is basically a 16-bit register which can be
incremented depending upon the clock pulses applied to it. These
timer registers are configured as the Special Function Registers.
x These SFRs at any time has the timer/counter register content. So, the timers
can be stopped at any time and the contents can be read from
these registers .Since there are only two bytes devoted to the value of
each timer it is apparent that the maximum value a timer may have is 65,535.
If a timer contains the value 65,535 and is subsequently incremented, it
will reset to 0 with an indication of overflow.
x One timer is TIMER0 and the other is TIMER1. Each timer also has two 8
bit SFRs namely TH0 and TL0 forming the higher and lower order bytes of
Timer0 and TH1 and TL1 forming the higher and lower bytes of Timer1.
x The TMOD SFR -used to control the mode of operation of both timers.
Each bit of the SFR gives the micro controller specific information -how to run
a timer. The higher order four bits (bits 4 through 7) relate to
Timer 1 whereas the low four bits (bits 0 through 3) perform the same
functions for timer 0.
8051 interrupts:
8051 basically has following five interrupt sources so that any of the
following events will make 8051 to execute an interrupt service routine. Timer 0 Overflow.
Timer 1 Overflow. Reception/Transmission of Serial Character.
External hardware interrupt 0.
External hardware interrupt 1.
Different interrupt sources have to be distinguished and 8051 must execute
different subroutines depending –interrupt triggered.
This is accomplished by jumping or calling to a fixed address when interrupt
occurs. These addresses are called interrupt vector addresses or interrupt
handler addresses.
Interrupt Flag Interrupt Vector
Address
External 0 IE 0 0003h
Timer 0 TF0 000Bh
External 1 IE 1 0013h
Timer 1 TF1 001Bh
Serial RI/TI 0023h
Whenever Timer 0 overflows (i.e., the TF0 bit is set), the main program
will be temporarily suspended and control will jump to 000BH.
a)External 0 Interrupt
b)Timer 0 Interrupt
c)External 1 Interrupt
d)Timer 1 Interrupt
e)Serial Interrupt
The data fetched for execution depends upon the addressing mode.
This instruction adds the data 80h to the contents of the accumulator and the
result is stored in the accumulator
itself. This addressing mode will be used when the data for the arithmetic and
logical operation is needed only once and is a constant.
This instruction will add the contents stored in register R0 with the
accumulator contents and store the result in accumulator. The registers A,
DPTR and R0 to R7 are used in Register direct addressing.
This addressing mode uses temporary registers which hold the data for
the operation.
The value stored in the register R0 is now the address of the memory location
of the data to be fetched from this
memory location, the data is fetched and the instruction is
executed. The data pointer register (DPTR) is used to access
the data in the external memory with 16-bit addresses.
The indirect addressing mode is very much useful for accessing data
which are continuously stored in memory and accessed consecutively in
program.
This instruction adds the contents of the accumulator with the contents of the
data pointer and the result forms the actual
address of the data from where it is fetched. This data is moved on to
the accumulator.
The indexed addressing mode is useful in accessing data structures similar to
lookup tables. The base address will hold the address of the starting point of
the table and the offset will point the particular entry in the table.
Arithmetic Instructions:
Logical Instructions:
Branching Instructions:
x The syntax for AJMP instruction is “AJMP 11 bit jump address”. The
destination branching address -absolute jumping is calculated -
keeping MSB 5 bits of the Program counter as it is and changing the LSB
11 bits to that as given -instruction. For example, 8800: AJMP 7F0h •
This instruction branch the execution address 8FF0h. After fetching-
program counter content will be 8802h. Keeping the MSB 5 bits of the
PC (10001) as it is, and changing the LSB 11 bits to that given
in the
instruction (111 1111 0000) , the branching address becomes 8FF0h.
The micro controller 8051 -single instruction for counter operation
to
Serial communication:
Computers transfer data in two ways:
i) Parallel:Often 8 or more lines (wire conductors) are
used to transfer data to a device that is only a few feet away.
At the transmitting end, the byte of data must be converted to serial bits
using parallel-in-serial-out shift register At the receiving end, there is a serialin-
parallel-out shift register to receive the serial data and pack them into byte.
Since the port 3 pins have an alternative function, the net result is that
only P1 is left for input and output operation.
One way to expand the number of I/O ports is to connect the 8255
programmable peripheral interface with the 8051.
The interfacing of the 8255 with the 8051 is done assuming the 8255 as a memory
location, because the 8051 supports only memory-mapped I/O.
For accessing the external memory in the 8051, the MOVX instruction is used.
The lower-order address bus and the data bus are multiplexed and are
available in the port 0 pins. This is de-multiplexed using a latch and the ALE signal.
addresses for the port. The 8051 uses 16-bit addresses and the most significant
address lines are used for decoding and selecting the device.
Here, the higher-order address bus from port 2 is given to a decoder logic circuit.
The 8255 needs four addresses for interfacing with any processor—three
for the ports A, B, and C and one for the control register.
The lower-order address lines A0 and A1 are connected to select one of these four
registers.
The read and write control signals are available from the port 3 pins P3.7 and P3.6.
The external memory accesses are accomplished with the Ports 0 and 2 of 8051 as
external memory in 8051 is always accessed with 16 bit addresses. The 8051 outputs
In addition, the micro-controller sends the control signals on the Port3 lines.
The program memory can be placed outside the chip in addition to the internal program
Applying proper the voltage level on the input line EA of 8051 can do the
all program memory accesses are done to external memory. The Read
strobe signal given by the micro-controller is PSEN. This active low signal is
The data memory in the system - be Random Access memory as it should facilitate both
read and write operation of data. The external data memory is interfaced in the
The major difference is that the read and writes operations can be
done in Read /W rite Random Access Memory. The control signals for reading and
writing to data memory are available from the port3 pins. P3.6 pin
enable signal and P3.7 pin gives out the RAM read enable signal.