Notes-Module1-3-All in one
Notes-Module1-3-All in one
and
2. Register organization of 8086
Internal block diagram has been partitioned into two logical units;
(1) The Bus Interface Unit (BIU) (2) the Execution Unit
The Execution Unit (EU)
The EU contains the arithmetic and logic unit (ALU), the control unit, an internal bus, plus a
few registers.
Register sets:
8086 has four 16-bit general-purpose registers labeled as AX, BX, CX and DX. Each of these
registers can also be used as two separate and exclusive 8-bit registers also i.e., AX has two
parts AH and AL, where H and L stands for the high and low portions respectively.
AX: AL /AX is sometimes called the accumulator, but the relevance of the accumulator is
less for 8086 compared to the earlier 8085 in which one operand is implied to be in the A
register for many instructions.
BX, CX and DX:
These are the other working registers of the 8086, which means that temporary data storage,
arithmetic calculations and data manipulation can be done with these registers
Base register BX is frequently used as an address register in many based addressing modes.
Counting register CX is used as a counter in many instructions.
Data register DX is used in I/O instructions as a pointer to data by storing the address of the
I/O port.
Pointer and Index Registers: SP, BP, SI and DI are address registers, and can be used only
as
16-bit registers
BP and SP: They are the Base pointer and Stack pointer respectively. SP always points to the
top of the stack, while BP can point to any location in the stack.
SI and DI: These are Index registers, labeled as Source Index and Destination Index
respectively. They function as address registers in various addressing modes
× × × × OF DF IF TF SF ZF × AF × PF × CF
OF=1 if
i) There is an overflow into the MSB (8th or 16th bit) from the bit of lower significance, but
no carry out from the MSB,
ii) There is a carry out from the MSB, but no carry into the MSB.
SF=1 if the result contains a negative number
ZF=1 if arithmetic or logic operation is zero,
AF =1 if there is carry from bit D3 into D4.
PF=1 if there is even number of 1s in lower 8-bits
CF=1 if there is a carry out from the MSB
Control Flags: There are three control flags; the Trap flag, Direction flag & Interrupt flag.
The control flags have to be deliberately set or reset according to the requirements of the
program. The Trap flag (TF) is set to perform step by step execution, during debugging. The
Interrupt flag (IF) is set to enable interrupts. The Direction flag (DF) is used in string
operations.
Arithmetic Logic Unit: It is the part of a computer that performs all arithmetic and logic
computations. The ALU is the most important unit of the processor. Instructions that are
fetched and decoded are executed in the ALU. Thus the ALU has direct access to the general
purpose registers and flags.
Bus Interface Unit (BIU)
This unit BIU is responsible for address calculations, pre-fetching instructions for the queue
and sequencing instructions one by one.
The Instruction Queue
Instructions are found in memory, from where they are fetched and decoded as and
when they need to be executed.
However in 8086, there is a queue which fetches instructions ahead of the execution
time and places them in a 6-byte first-in-first-out (FIFO) queue. This pre-fetching is
done when the buses are free i.e., not being used for the execution of the current
instruction.
The advantage of pre-fetching is that when a particular instruction is to be executed,
there is a good chance of finding it in the queue (which is on-chip), rather than having
to go to memory to fetch it.
This pre-fetching belongs to a class of ideas called pipelining, which means that both
execution and fetching take place at the same time i.e., while the execution of one
instruction is going on, the fetching of another one can be done.
Pipelining greatly speeds up processing.
3. Pin diagram and Signal description of 8086
Min. mode Max. mode
19 CLK This is the clock pin to which a clock with at least Input
33% duty cycle is to be supplied
22 READY For the bus cycle to proceed normally, the READY Input
pin should be found to be at logic high when it is
sampled. If it is at logic low, WAIT states are
inserted into the current bus cycle
25 ALE Address Latch Enable – this signal goes high in the Output
beginning of a bus cycle and indicates that the
multiplexed address bus contains address
information
Advantages of Segmentation
1. It allows all address registers to have the same size as the data registers (16-bit), while
allowing the use of 20-bit physical addresses.
2. All addresses in memory are re-locatable. This means that any program or data can be
loaded in any address in memory. A re-locatable program is one which can be placed
in any area of memory and executed without change. Data is also re-locatable.
Changing the base address of the corresponding segment is the only action we need to
perform, in order to re-locate. All addresses within the program are relative to the
base address, as they are of the form Base address: off set. All processors in the x86
family have this kind of segmentation.
A bus is collection of signal wires which connect between the components of the computer
systems – the figure shows that the CPU is connected to the memory as well as I/O through
the system bus, but only one at a time – if the memory and I/O wants to use the bus at the
same time, there is a conflict, as there is only one system bus. The system bus comprises of
the address bus, data bus and the control bus.
The Data Bus: The set of lines used to transfer data is called the data bus. It is a bidirectional
bus, as data has to be sent from the CPU to memory and I/O, and has to be received as well
by the CPU. The width of the data bus determines the data transfer rate, size of the internal
registers of the CPU and the processing capability of the CPU. The 8086 has a data bus width
of 16 bits and therefore it can handle 16 bits.
The Address Bus: The address bus width determines the maximum size of the physical
memory that the CPU can access. With an address bus width of 20 bits, the 8086 can address
220 different locations. It can use a memory size of 2 20 bytes or 1 MB. When a particular
memory location is to be accessed, the corresponding address is placed on the address bus by
the CPU. I/O devices also have addresses. In both cases, it is the CPU which supplies the
address, and as such, the address bus is unidirectional.
The Control Bus: The control bus is a set of control signals which needs to be activated for
activities like writing/reading to/from memory/I/O, or special activities of the CPU like
interrupts and DMA. Thus, signals like Memory Read, I/O Read, Memory Write and
Interrupt Acknowledge are part of the control bus. These control signals dictate the actions
taking place on the system bus that involve communications with devices like memory or
I/O. For example, the Memory Read signal will be asserted for reading from memory. It is
sent to memory from the processor. A signal such as ‘Interrupt’ is received by the processor
from an I/O device. Hence in the control bus, we have signals traveling in either direction.
Some control lines may be bidirectional too.
For a computer to communicate with the outside world there is the need for what are called
peripherals. Some of these peripherals are purely input devices like the keyboard and mouse;
some are purely output devices like the printer and video monitor and some like the modem
transfer data in both directions. All this just means that such I/O devices are needed for us to
use a computer. However, it is difficult for a processor to deal directly with I/O devices,
because of their incompatibility with the processor – each peripheral is different and the
operating conditions, voltages, speeds and standards are not understandable to the processor.
The processor does not have the necessary control signals to deal with different peripherals.
Hence, the normal practice is for each peripheral to have a controller which acts as an
interface between the peripheral and the processor. This controller, which may be a special
purpose chip, understands the characteristics of the particular device and provides the
necessary control signals to the processor to communicate with the peripheral. Thus, we have
specialized controllers for most peripherals – like the keyboard display interfacing chip,
parallel port interfacing chip and serial communication chip. All these chips are
programmable – they have registers for commands, data and status. By suitably programming
these chips, we can get the processor to communicate correctly with any peripheral.
Fig. 6 I/O system
7. Special processor activities : Find it yourself
8. Minimum mode and maximum mode operation
Some pins have dual functions, and this corresponds to two modes of operation- minimum
and maximum modes. The minimum mode is used when the 8086 is used in single processor
systems, and the maximum mode is used when the system is a multi-processor system, in
which the 8086 / 8088 is one of the processors.
Minimum Mode Pins
For minimum mode operation, pin no. 33 MN / MX should be at logic high. Refer section 4
for minimum mode pin function explanation.
Maximum Mode Pins
It is necessary to use the maximum mode if the processor is to be used in multiprocessor
configurations. The most important issues in a multiprocessor environment are inter-
processor communication and bus contention. In this mode, 8086 has special pins for
resolving these issues. To use the maximum mode, pin No. 33 MN / MX must be connected
to ground.
Modes of operation of 8086
This mode of operation was designed by Intel for allowing the 8086 to communicate with
other processors like the arithmetic co-processor (8087) and the input /output processor 8089.
It was also used to allow 8086 to be used in large loosely coupled multiprocessor systems.
This mode was dropped from Intel’s designs from 80286 onwards. Later processors (80486
onwards) had the arithmetic co-processor integrated on the processor chip itself. From pin
number 24 to 31 in maximum mode, the functions of INTA, ALE, DT / R, M / IO, and WR are
generated externally by 8288 bus controller.
Table 2 Control Signals Generated by the Bus Controller 8288
Clock
All activities on the system bus is synchronized by the system clock which provides the basic
timing.
List of activities on the bus are:
i) Reading from memory / IO
ii) Writing to memory / IO
Depending on the type of activity, different control signals are activated. Any read or write
cycle is called a bus cycle. For 8086, a bus cycle takes 4 T states, where one T state is defined
as the ‘period’ of the clock. If the clock frequency is 10 MHz, one T state = 0.1μs or 100
nsecs.
A bus cycle is also called a machine cycle. During a machine cycle, a specific operation –
say, reading or writing is accomplished. So, we can have the following basic machine cycles:
i) Memory Read
ii) Memory Write
iii) I / O Read
iv) I / O Write
For computations in assembly language, we need an opcode and operands. The way in which
operands are specified in an assembly language instruction is called its addressing mode. Let
us use the MOV instruction for understanding these modes. This has the format
MOV destination, source ………. source data is copied into the destination.
Solution:
The factorial of a number ‘n’ is n × ( n−1 ) × ( n−2 ) × ( n−3 ) …
i.e. factorial of 4 is 4*3*2*1 = 24
Assumptions –
Starting address of program: 0400
Input memory location: 0500
Output memory location: 0600 and 0601
MNEMONICS COMMENTS
MOV CX, [0500] Move the content of memory address 0500 in register CX
MOV AX, 0001 Move 1 in the register AX
MOV DX, 0000 Move 0 in the register DX
MUL CX Multiply the contents of CX & DX and store product in
DX:AX
LOOP 040A Go to address [040A] till CX->00
MOV [0600], AX Move the content of AX in memory address 0600
MOV [0601], DX Move the content of DX in memory address 0601
HLT Stop Execution
Note –
The result of multiplication is stored in AX for byte data type.
For the word data type, the result of multiplication is stored in AX-DX. i.e.
90C3×12DA=AA8FC0E;
After multiplication AX=FC0E & DX=AA8
Algorithm –
1. Assign value 500 in SI and 600 in DI
2. Move the contents of [SI] in BL and increment SI by 1
3. Move the contents of [SI] and [SI + 1] in AX
4. Use DIV instruction to divide AX by BL
5. Move the contents of AX in [DI].
6. Halt the program.
MNEMONICS COMMENT
Problem – Write a program to add two 16-bit numbers where starting address is 2000H and
the numbers are at 3000H and 3002H memory address and store result
into 3004H and 3006H memory address
Mnemonics Comment
ADD AX, BX AX AX + BX
Add the contents of AX & BX and store the result in
AX
JNC L2 Jump to address 2010 if there is no carry
INC CX CX CX+ 1(0+1=1CX)
HLT Stop
Problem – Write a program to subtract two 16-bit numbers where starting address
is 2000 and the numbers are at 3000 and 3002 memory address and store result
into 3004 and 3006 memory address
Mnemonics Comment
MOV CX, 0000 [CX] 0000
Assign 0 into the reg. CX
MOV AX, [3000] [AX] [3000]
Move the data of address [3000] to reg. AX
MOV BX, [3002] [BX] [3002]
Move the data of address [3002] to reg. BX
SUB AX, BX AX AX - BX
JNC 2010 Jump to memory address 2010 if there is
no borrow
INC CX CX <- CX + 1
MOV [3004], AX [3004] AX
MOV [3006], CX [3006]CX
HLT Stop
8. Program to count the number of 1s in the contents of Accumulator
After Five number iterations of CL, the content of BL=1. This process will continue until
BL is not equal to 2
9. Program to transfer a block of 4-bytes by using string instruction
Problem – Write a program to transfer a block of 4 bytes, starting address is 0500 and
transfer the block at address 0600 by using string instructions
04 18 AD 0504 18 AD 05
Mnemonics Comments
MOV SI, 500 SI500 Move the offset address 500 of Data segment to SI
MOV DI, 600 DI600 Move offset address 600 of Extra segment to DI
MOV AX, 0000 AX0000
MOV DS, AX Move 0000H to DS register so that base address of data segment is
0000H
MOV ES, AX Move 0000H to ES register so that base address of Extra segment is
0000H
MOV CX, 0004 CX0004 since four data have to be moved
CLD Clear directional Flag
REP reduce CX and repeat till CX≠ 0
MOVSB Move the string byte from DS:[SI] to ES:[DI]
HLT End of the program
Problem – Write a program to convert a string of data to its two’s compliment form
Mnemonics Comment
MOV SI, 3000H SI [3000]
MOV DI, 4000H DI [4000]
MOV CX, 000AH CX 000A
LODSB Load the string byte at DS:[SI] into AL
NEG AL Negative of AL
STOSB Load the string byte from AL into ES:[DI]
LOOP NZ Loop through a sequence of instructions till CX>0
HLT Stop
Mnemonics Comments
MOV AX, 0000H Initialize AX equal to 0
MOV SI, 500 SI500 Move the offset address 500 to SI
MOV DI, 600 DI500 Move the offset address 600 to DI
MOV CX, 0004 Assume 4 data whose sum has to be found
L1: ADD AX, [SI] AXAX+[SI]
INC SI Increment SI; 500+1=501(SI)……… so on
LOOP L1 Decrement CX. Go to L1 if CX≠ 0
MOV [DI], AX Assign the value of AX to the memory address pointed by DI
HLT Stop
Mnemonics Comments
MOV AX, 0000H Initialize AX equal to 0
MOV SI, 500 SI500 Move the offset address 500 to SI
MOV DI, 600 DI500 Move the offset address 600 to DI
MOV CX, 0004 Assume 4 data whose sum has to be found
L1: ADD AX, [SI] AXAX+[SI]
INC SI Increment SI; 500+1=501(SI)……… so on
LOOP L1 Decrement CX. Go to L1 if CX≠ 0
DIV CX AX=AX/CX (Average of four numbers)
The memory can be RAM or ROM – the difference is that ROM can only be read from, so the
MEMWR signal from the processor does not have any relevance for ROM. A typical RAM has the
pin lines as shown in Fig 1. As shown, it has data lines D o to DM−1. If it is a byte organized memory,
the data lines are D0 to D7. The number of address lines (A0 to AN−1) depends on the number of
locations it contains.
For example in a 256 × 8 RAM chip, it has 8 data lines and a storage capacity of 256 locations – thus
it needs 8 address lines as 256 = 2 8. Thus, it is the capacity of the chip which decides the number of
address lines. The active low signals WE is to be connected to the MEMWR signal from the
processor side. Only if this pin is activated, can the write operation be done in the addressed
location. For reading, the pin MEMRD (from the processor side) is to be connected to the OE
(output enable) pin of the memory chip for reading. When this pin is low, the output lines are
activated. The pin CS (chip select) is the pin which enables the memory chip. No activity is possible if
this pin is inactivated, as the chip remains turned off.
A ROM chip is similar except that it does not have the WE pin, as it can only be read from.
The ROMs that are used are usually EPROM, which have a pin to enable the chip to be programmed
(PGM).
Memory Banks
8086 has a 16-bit memory bus – which means that data transfer can occur at a maximum rate
of 16 bits (one word) per bus cycle. However, sometimes only a byte needs to be accessed.
This means that the processor must have both options – i.e., both byte and word transfer must
be possible. We know that for a word transfer, two byte locations must be accessed i.e., two
addresses are actually needed. A 16-bit data can be obtained by accessing two memory chips
in parallel, each having 8 bits each of the word as shown in Fig 2.
This is the way memory is organized in 8086. A 16-bit word is obtained as the concatenation of two
bytes in two ‘memory banks’ i.e., memory is organized as two banks – one, the upper bank or high
bank with the data corresponding to the upper byte D8–D15, and the other, the lower bank or low
bank which has the data lines D0–D7. The upper bank is also called the odd memory bank, because it
has the odd addresses mapped to it – in the same way, the lower bank is called the even bank (Fig
3). Remember that a 16-bit word has one byte with an odd address and one byte with an even
address. If a byte alone is to be accessed, it may be in the odd bank or even bank. Thus for reading /
writing a byte, only one of the banks is to be accessed, but to access a word, both memory banks
have to be accessed.
Fig.4. Memory banks with the respective bank enable signals, along with the decoder
This chip is also called a parallel port chip and it eases out the problems and issues related to parallel
data transfer to/from memory or I/O devices. When I/O devices are more versatile and have more
features, a PPI is be very useful, especially when more than one I/O device is to be interfaced to the
processor. This chip ensures that no other extra hardware is required to interface peripheral devices
that perform parallel data transfer. As shown in Fig.5, the 8086 microprocessor is connected to 8255
using data bus. When data transfer takes place between microprocessor and 8255 then these data
are need storage (registers) in 8255. Therefore 8255 has registers called ‘ports’ – there are three
ports here – A, B and C, and these ports have pins connecting it to external devices. Thus, port A has
8 pins PA0 to PA7 – so also ports B and C, as well. To these port pins, external devices like keyboards,
displays, printers can be connected.
Fig.5. The connection between 8086, 8255 and three peripherals
Fig.6 (a) shows the pin configuration of the DIP (dual-in-line) version of the chip. It has 40 pins, which
consist of three 8-bit ports named Port A (PA), Port B (PB) and Port C (PC), each of which can be
programmed as input or output ports. Fig.2 (b) shows the internal block diagram of the chip with
various functional blocks as explained below
Data Bus Buffer There is a three state bi-directional 8-bit buffer which is used to interface the chip to
the data bus of the system. Upon execution of the processor’s input or output instructions, data and
control/status words are received or transmitted by the buffer.
Read/Write Control Logic It manages all data transfer between the chip and the processor, on
accepting control signals from the control and address buses of the system.
Group A and B Controls Functionally this chip has been divided as Group A and B and they have their
corresponding controls. The way the chip is to act is decided by a register called the control/status
register which can be written to and read from.
Programming the chip involves only the writing of a particular word to the control register.
Fig.6 (a) Pin diagram of 8255 (b) Internal block diagram of 8255
The control register is an 8-bit register which can be written into. The bits of this word (called the
control word) will decide the way the ports of the chip are to be configured. The Fig.7 shows the
control word format.
The ports A, B and C are grouped into two – Groups A and B. Group A consists of Port A and upper 4
bits (PC4–PC7) of Port C. Group B includes Port B and Port C lower (PC0–PC3). Thus Group A ports
has three operational modes (0, 1 and 2), but Group B ports have only two modes of operation.
Modes of Operation
The 8255 can be made to work in three modes as decided by the system designer. They are:
Mode 0: This is the simplest and most widely used mode. In this mode, the two 8-bit ports A and B,
and the 4-bit ports Port C upper and Port C lower, may be used independently. Here data is simply
taken in from an input port or given to an output port.
Mode 1: This is the ‘handshaking’ mode. Handshake implies data transfer in which the
communicating devices exchange request and acknowledge control signals with each other. For an
8255 operating in this mode, Ports A and B pins are used for data transfer, while 4 bits of each of
Port C are used for generating the handshaking signals for each of the 8-bit ports.
(1) Each group contains one 8-bit port and one 4-bit port. The 4-bit port is used for
‘handshaking’.
(2) The 8-bit port can be either an input or an output.
(3) Input and output are latched.
(4) The 4-bit port is used for control and status of the 8-bit data port.
(5) Interrupt logic is supported.
Mode 2: This is the bidirectional mode. Only Group A can use this mode. Here Port A is used for
transmitting as well as receiving data. Handshaking signals generated by the upper 4 bits of Port C
maintain bus discipline for proper flow of data in the required direction. Now, let us use the different
modes.
ISR is available in memory and must be accessed on occurrence of the specific interrupt. For that,
the address of the ISR must be obtained. The address of an ISR is called its ‘interrupt vector’. For
an 8086 based system, any address of code is in the following form, CS: IP. Thus, the interrupt
vector for any interrupt has 4 bytes – two for the CS value and two for the IP value. Thus, if the
interrupt vector for a particular interrupt is obtained, control can be transferred to the new location
by using the new values of CS and IP specified as the ‘interrupt vector’. The 8086 has 256
interrupt vectors and since each vector is specified by 4 bytes, it implies that 256 × 4 = 1024
bytes (1K) of memory are allocated to store the interrupt vectors. These 256 vectors are stored
in a table called the ‘Interrupt Vector Table’ (IVT) in system RAM from locations 00000 to
003FFH.
D1 D1 D1 D1 D1 D1 D D D D D D D D D D
5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
U U U U OF DF IF TF SF ZF U AF U P U CF
There are only two hardware interrupt lines for the 8086. An external device can place its interrupt
request on either of these pins. One pin called NMI is a ‘vectored’ interrupt, in the sense that its
interrupt handler is pointed to, by a particular type number and that is ‘2’. Thus, NMI is a Type 2
interrupt, and since it is non-maskable it is used for important and high priority services. As such, this
interrupt pin is not available for general interrupt requests from various peripherals. That leaves just
one pin for accepting hardware interrupt requests, and if many peripherals want to use this pin,
obviously a number of issues have to be resolved. It is in this context that a dedicated interrupt
controller like 8259 is necessary.
The PIC has eight interrupt request lines IR0 to IR7, on which peripherals can place their
interrupt requests. If one interrupt request alone is received on the chip, that request is channeled to
the INTR line of the processor. As is the usual sequence, the processor sends back an acknowledge
request in the form of the INTA signal. Then the PIC (on behalf of the peripheral which has made the
request) sends to the 8086 the interrupt type number corresponding to that specific interrupt.
Another activity of the chip is to resolve priorities. Suppose interrupt requests arrive at more
than one interrupt input of the chip. Which one of these requests should be channeled to the
processor? This decision is made by the PIC.
Block Diagram of 8259
Fig. 10 Block diagram of PIC 8259
Int (Interrupt) This output goes directly to processor interrupt input and causes the processor to
send back the INTA as an acknowledgement, to the 8259.
Interrupt Request Register (IRR) and In-Service Register (ISR): The interrupts at the IR input lines are
handled by two registers in cascade, the Interrupt Request Register (IRR) and the In-Service Register
(ISR). The IRR is used to store all the interrupt levels which are requesting service; and the ISR is used
to store the interrupt levels which are being serviced.
Priority Resolver This logic block determines the priorities of the bits set in the IRR. The highest
priority is selected and strobed into the corresponding bit of the ISR (in service register) during the
INTA pulse.
Interrupt Mask Register (IMR) The IMR stores the bits which mask the interrupt lines to be masked.
The IMR operates on the IRR. Masking of a higher priority input will not affect the interrupt request
lines of lower priority.
CAS0–CAS2: These three bi-directional lines can be used to cascade several such chips to expand the
number of interrupts up to 64, in a master or slave mode. The associated three I/O pins (CAS0-2) are
outputs when the 8259 is used as a master and are inputs when the 8259 is used as a slave.
SP / EN: This stands for Slave Program/Enable Buffer. This is also a bidirectional pin. In the buffered
mode, it can be used to control buffer transceivers (EN ). In other modes, it indicates whether the
8259 is a master (SP = 1), or whether it is a slave (SP = 0).
R / W LOGIC: Just as in the case of any other peripheral chip, the decoding logic on the CS and A0
determine the addresses of the registers within the chip, and in conjunction with the RD and WR
signals, the registers can be written into and read from (to get status information).
In 1981, Intel introduced an 8-bit microcontroller called the 8051. It was referred as system on
a chip because it had 128 bytes of RAM, 4K byte of on-chip ROM, two timers, one serial port,
and 4 ports (8-bit wide), all on a single chip. When it became widely popular, Intel allowed
other manufacturers to make and market different members of 8051 with its code compatible
with 8051. It means that if we write our program for one member of 8051, it will run on other
members too, regardless of the manufacturer. This has led to several versions with different
speeds and amounts of on-chip RAM.
Comparison between 8051 Family Members
8031 Microcontroller
Another member of 8051 family is the 8031 chip.
This chip is often referred to as a ROM-less 8051 since it has 0K bytes of on-chip
ROM.
To use this we have to add external ROM to it.
This external ROM must contain the program that 8031 will fetch and execute.
In process of adding external ROM, we loose two ports.
That leaves only 2 ports (of the 4 ports) for I/O operations.
To solve this problem, we can add external I/O to the 8031.
8751 Microcontroller
The UV-EPROM version of 8051 is the 8751.
8751 chip has 4K bytes of on-chip UV-EPROM.
Using this chip for development requires access to a PROM burner, as well as a UV-
EPROM eraser to erase the contents of UV-EPROM inside the 8751 chip before we
can program it again.
It takes around 20 minutes to erase the 8751 before it can be programed again.
This has led many manufacturers to introduce flash NV-RAM version of 8051
DS89C4×0 from Dallas semiconductor
To eliminate the waiting needed to erase the chip and thereby speed up the
development time, AT89C51 from Amtel corp. was introduced with flash ROM.
The erasing of flash is done by the PROM burner itself, which is why a separate
eraser is not needed.
To eliminate the need for a PROM burner, Dallas semiconductor has a version of
8051/52 called DS89C4×0 that can be programmed via the serial COM port of a IBM
PC.
2. Architecture of 8051 Microcontroller
Fig.1 shows the architecture of 8051, the system bus connects all the support devices to the
CPU. The system bus consists of an 8-bit data bus, a 16-bit address bus and bus control signals.
All other devices like program memory, ports, data memory, serial interface, interrupt control,
timers, and the CPU are all interfaced together through the system bus
Central Processor Unit (CPU)
The CPU is the brain of any processing device of the microcontroller. It monitors and
controls all operations that are performed on the Microcontroller units. The User has no
control over the work of the CPU directly. It reads program written in ROM memory and
executes them and do the expected task of that application.
Interrupts
Interrupt is a subroutine call that interrupts the microcontrollers main operations and causes it
to execute any other program, which is more important at the time of operation. The feature
of Interrupt is very useful as it helps in case of emergency operations. An Interrupts gives us
a mechanism to put on hold the ongoing operations, execute a subroutine and then again
resumes to another type of operations. The Microcontroller 8051 can be configured in such a
way that it temporarily terminates or pause the main program at the occurrence of interrupts.
When a subroutine is completed, then the execution of main program starts. Generally five
interrupt sources are there in 8051 Microcontroller. There are 5 vectored interrupts: INT0,
TF0, INT1, TF1, R1/T1.
Memory
Microcontroller requires a program which is a collection of instructions. This program tells
microcontroller to do specific tasks. These programs require a memory on which these can be
saved and read by Microcontroller to perform specific operations of a particular task. The
memory which is used to store the program of the microcontroller is known as code memory
or Program memory of applications. It is known as ROM memory of microcontroller also
requires a memory to store data or operands temporarily of the micro controller. The data
memory of the 8051 is used to store data temporarily for operation is known RAM memory.
8051 microcontroller has 4K of code memory or program memory (ROM) and also 128 bytes
of data memory of RAM.
BUS
Basically Bus is a collection of wires which work as a communication channel or medium for
transfer of Data. These buses consist of 8, 16 or more wires of the microcontroller. Thus,
these can carry 8 bits, 16 bits simultaneously.
Address Bus:
Microcontroller 8051 has a 16 bit address bus for transferring the data. It is used to address
memory locations and to transfer the address from CPU to Memory of the microcontroller.
Data Bus:
Microcontroller 8051 has 8 bits of the data bus, which is used to carry data of particular
applications.
Oscillator
It requires clock pulses for its operation of microcontroller applications. For this purpose,
microcontroller 8051 has an on-chip oscillator which works as a clock source for Central
Processing Unit of the microcontroller. The output pulses of oscillator are stable. Therefore, it
enables synchronized work of all parts of the 8051 Microcontroller.
Input/output Port
Normally microcontroller is used in embedded systems to control the operation of machines
in the microcontroller. Therefore, to connect it to other machines, devices or peripherals we
require I/O interfacing ports in the microcontroller interface. For this purpose microcontroller
8051 has 4 input, output ports to connect it to the other peripherals
Timers/Counters
8051 microcontroller has two 16 bit timers and counters. These counters are again divided
into a 8 bit register. The timers are used for measurement of intervals to determine the pulse
width of pulses.
3. Pin diagram of 8051
4. External memories
TF1: The TF1 stands for ‘timer1’ flag bit. Whenever calculating the time-delay in timer1, the
TH1 and TL1 reaches to the maximum value that is “FFFF” automatically.
TR1: The TR1 stands for timer1 start or stop bit. This timer starting can be through software
instruction or through hardware method.
TF0: The TF0 stands for ‘timer0’ flag-bit. Whenever calculating the time delay in timer1, the
TH0 and TL0 reaches to a maximum value that is ‘FFFF’, automatically.
TR0: The TR0 stands for ‘timer0’ start or stop bit; this timer starting can be through software
instruction or through hardware method.
7. Serial Communication
Microcontrollers need to communicate with external devices such as sensors, computers and
so on to collect data for processing. Data communication is generally done by means of two
methods – Parallel and Serial mode. In parallel mode data bits are transferred faster using
more data pins. But when comes to a Microcontroller, we cannot afford to dedicate many
pins for data transfer.
Serial communication may be synchronous or asynchronous. In synchronous communication,
the transmitter also transmits a clock along with data. This clock is used for synchronization
between transmitter and receiver devices In an asynchronous transfer of data, there is no
clock.
Method of serial communication:
There are two methods of Serial Communication:
SYNCHRONOUS: Transfer the block of data (characters) between sender and receiver
spaced by fixed time interval. This transmission is synchronized by an external clock.
Baud rate
There are 21 Special function registers (SFR) in 8051 microcontroller and 21 unique
locations are for these 21 SFR. Each of these register is of 1 byte size. The “Serial Control”
(SCON) is the SFR which is used to configure serial port.
SM0 SM1 SM2 REN TB8 RB8 T1 R1
Interrupts are the events that temporarily suspend the main program, pass the control to the
external sources and execute their task. It then passes the control to the main program where
it had left off.
Interrupts are of different types like software and hardware, maskable and non-maskable,
fixed and vector interrupts, and so on. Interrupt Service Routine (ISR) comes into the picture
when interrupt occurs, and then tells the processor to take appropriate action for the interrupt,
and after ISR execution, the controller jumps into the main program.
Types of Interrupts in 8051 Microcontroller
The 8051 microcontroller can recognize five different events that cause the main program to
interrupt from the normal execution. These five sources of interrupts in 8051are:
1. Timer 0 overflow interrupt- TF0
The Timer and Serial interrupts are internally generated by the microcontroller, whereas the
external interrupts are generated by additional interfacing devices or switches that are
externally connected to the microcontroller. These external interrupts can be edge triggered
or level triggered. When an interrupt occurs, the microcontroller executes the interrupt
service routine so that memory location corresponds to the interrupt that enables it. The
Interrupt corresponding to the memory location is given in the interrupt vector table below
Table 3 Interrupt vector table
Interrupt Priority Register (IP): It is also possible to change the priority levels of the
interrupts by setting or clearing the corresponding bit in the Interrupt priority (IP) register as
shown in the figure. This allows the low priority interrupt to interrupt the high-priority
interrupt, but prohibits the interruption by another low-priority interrupt. Similarly, the high-
priority interrupt cannot be interrupted. If these interrupt priorities are not programmed, the
microcontroller executes in predefined manner and its order is INT0, TF0, INT1, TF1, and
SI.
TCON Register: In addition to the above two registers, the TCON register specifies the type
of external interrupt to the 8051 microcontroller, as shown in the figure. The two external
interrupts, whether edge or level triggered, specify by this register by a set, or cleared by
appropriate bits in it. And, it is also a bit addressable register.
Set this bit (0) for an interrupt generated by a low level signal at INT1
Clear this bit (0) for an interrupt generated by a falling edge signal at INT1
Set this bit (0) for an interrupt generated by a low level signal at INT0
Clear this bit (0) for an interrupt generated by a falling edge signal at INT0