EC8691 Answers For Important Questions
EC8691 Answers For Important Questions
Important Questions
Unit- I
Architecture of 8086
Addressing Modes
Instruction set & Byte & String Manipulation
Interrupts ( 7 Marks)
Unit – II
Unit- III
Set A Set B
8255-PPI 8279- Keyboard / display interface
8251- Serial Interface 8259- Interrupt controller
A/D & D/A 8237/8257- DMA Controller
8253- Timer
Unit-IV
Unit V
Architecture of 8086
Features
16-bit microprocessors
1 MB main memory
The Execution unit tells the BIU where to fetch instructions or data
from
• decodes instructions and
• Executes instructions The Execution unit contains:
1) Control circuitry
2) ALU
3) FLAGS
4) General purpose Registers
5) Pointer and Index Registers
Control Circuitry:
• It directs internal operations.
• A decoder in the EU translates instructions fetched from memory Into series of
actions which the EU carries out
2. Control flags
Conditional Flags
Carry Flag (CY): This flag indicates an overflow condition for unsigned integer arithmetic. It is also
used in multiple-precision arithmetic.
Auxiliary Flag (AC): If an operation performed in ALU generates a carry/barrow from lower nibble
(i.e. D0 – D3) to upper nibble (i.e. D4 – D7), the AC flag is set i.e. carry given by D3 bit to D4 is AC
flag. This is not a general-purpose flag, it is used internally by the Processor to perform Binary to
BCD conversion.
Parity Flag (PF):This flag is used to indicate the parity of result. If lower order 8-bits of the result
contains even number of 1’s, the Parity Flag is set and for odd number of 1’s, the Parity flag is reset.
Zero Flag (ZF):It is set; if the result of arithmetic or logical operation is zero else it is reset.
Sign Flag (SF):In sign magnitude format the sign of number is indicated by MSB bit. If the result of
operation is negative, sign flag is set.
Control Flags
Control flags are set or reset deliberately to control the operations of the execution unit. Control flags
are as follows:
Trap Flag (TF): It is used for single step control. It allows user to execute one instruction of a
program at a time for debugging. When trap flag is set, program can be run in single step mode.
Interrupt Flag (IF):It is an interrupt enable/disable flag. If it is set, the maskable interrupt of 8086 is
enabled and if it is reset, the interrupt is disabled. It can be set by executing instruction sit and can be
cleared by executing CLI instruction.
Direction Flag (DF):It is used in string operation. If it is set, string bytes are accessed from higher
memory address to lower memory address. When it is reset, the string bytes are accessed from
lower memory address to higher memory address.
CS register contains the Upper 16 bit of the starting address of the code segment in the 1 Mbyte
address range the instruction pointer contains a 16 bit offset which tells wherein that 64 Kbyte code
segment the next instruction byte has to be fetched from.
Stack Register and Stack Pointer:
Stack: is a section of memory set aside to store addresses and data while subprogram executes is
often called segment base . The stack segment register always holds the upper 16 bit starting
address of program stack. The Stack pointer (SP) holds the 16 bit offset from the starting of the
segment to the memory location where a word was most recently stored
.The memory location where the word is stored is called as top of the stack
These three registers are used to store temporary storage of data like general purpose registers
.They hold the 16 bit offset data of the data word in one of the segment
Addressing Modes
The different ways in which a source operand is denoted in an instruction are known as
addressing mode the addressing modes for sequential control flow instructions are
The addressing mode in which the data operand is a part of the instruction itself is known as
immediate addressing mode.
Example
The 16-bit data (0A9FH) given in the instruction is moved to AX register (AX)
0A9FH
The addressing mode in which the effective address of the memory location at which the data
operand is stored is given in the instruction. The effective address (Offset) is just a 16-bit number
written directly in the instruction.
Example:MOV BX, [1354H] MOV
BL, [0400H]
The square brackets around the 1354H denote the contents of the memory location. When
executed, this instruction will copy the contents of the memory location into BX register. This
addressing mode is called direct because the displacement of the operand from the segment
base is specified directly in the instruction.
The instruction will specify the name of the register which holds the data to be operated by the instruction. All
registers except IP may be used in this mode
Example:
MOV CL, DH
The content of 8-bit register DH is moved to another 8-bit register CL (CL)
(DH)
This addressing mode allows data to be addressed at any memory location through an offset
address held in any of the following registers: BP, BX, DI & SI.
Example
MOV AX, [BX]; suppose the register BX contains 4895H, then the contents
; 4895H are moved to AX
ADD CX, {BX}
In this addressing mode, the operands offset address is found by adding the contents of SI or DI
register and 8-bit/16-bit displacements. DS and ES are the default segments for index registers
SI and DI respectively. This is the special case of the of register indirect addressing mode.
Example
In register relative Addressing, BX, BP, SI and DI is used to hold the base value for
effective address and a signed 8-bit or unsigned 16-bit displacement will be specified in the
instruction. In case of 8-bit displacement, it is sign extended to 16-bit before adding to the base
value. When BX holds the base value of EA, 20-bit physical address is calculated from BX and
DS.When BP holds the base value of EA, BP and SS is used.
Example:
In this addressing mode, the offset address of the operand is computed by summing the base
register to the contents of an Index register. The default segment registers may be ES or DS
Example:
In this addressing mode, the operands offset is computed by adding the base register contents.
An Index registers contents and 8 or 16-bit displacement.
Example
The control transfer instructions transfer control to some predefined address or the address
somehow specified in the instruction after their execution
Examples : INT , CALL ,RET and JUMP instructions
The control transfer instruction the addressing modes depend upon whether destination location
is within the same segment or a different one .It also depends on the method of passing the
destination address to the processor
Basically there are two methods for passing control transfer instructions
1. Intersegment addressing mode
2. Intrasegment addressing mode
INTRASEGMENT ADDRESSING MODE
If the destination location is within the same segment the mode is called intrasegment addressing
mode
There are two types
1. Intrasegement direct mode
2. Intrasegment indirect mode
INTRASEGMENT DIRECT MODE:
In this mode the address to which the control is to be transferred lies within the segment in which
the control transfer instruction lies and appears directly in the instruction as an immediate
displacement value .The displacement is computed relative to the content of the instruction
pointer IP.
JMP SHORT LABEL;
is a control transfer instruction following intra segment direct mode. Here, SHORT LABEL
represents a signed displacement.
INTRASEGMENT INDIRECT MODE :
In this mode the displacement to which the control is to be transferred is in the same segment in
which the control transfer instruction lies but it is passed to the instruction indirectly Here the
branch address is found as the content of a register or a memory location .
Example
JMP [A
If the destination location is in the different segment the mode is called intersegment addressing
mode
There are two types
1. Intersegment direct mode
2. Intersegment indirect mode
INTERSEGMENT DIRECT MODE:
In this mode the address to which the control is to be transferred is in a different segment this
addressing mode provides a means of branching from one code segment to another code
segment. Here the CS and IP of the destination address are specified directly in the instruction.
Example
In this the address to which the control is to be transferred lies in a different segment and it is
passed to the instruction indirectly .Content of memory block containing four bytes IP(LSB)
,IP(MSB),CS(LSB) and CS(MSB) sequentially The starting address of the memory block may be
referred using any of the addressing mode except immediate mode .
Example
JMP [5000H];
INSTRUCTION SET OF 8086
1. DATA TRANSFERINSTRUCTIONS
These instructions are used to transfer the data from the source operand to the
destination operand. Following are the list of instructions under this group −
MOV − Used to copy the byte or word from the provided source to the provided
destination.
PPUSH − Used to put a word at the top of the stack.
POP − Used to get a word from the top of the stack to the provided location.
PUSHA − Used to put all the registers into the stack.
POPA − Used to get words from the stack to all registers.
XCHG − Used to exchange the data from two locations.
XLAT − Used to translate a byte in AL using a table in the memory.
IN − Used to read a byte or word from the provided port to the accumulator.
OUT − Used to send out a byte or word from the accumulator to the provided
port.
LEA − Used to load the address of operand into the provided register.
LDS − Used to load DS register and other provided register from the memory
LES − Used to load ES register and other provided register from the memory.
LAHF − Used to load AH with the low byte of the flag register.
SAHF − Used to store AH register to low byte of the flag register.
PUSHF − Used to copy the flag register at the top of the stack.
POPF − Used to copy a word at the top of the stack to the flag register.
2. ARITHMETIC INSTRUCTIONS
These instructions are used to perform arithmetic operations like addition,
subtraction, multiplication, division, etc.
Following is the list of instructions under this group −
DIV − Used to divide the unsigned word by byte or unsigned double word by
word.
IDIV − Used to divide the signed word by byte or signed double word by word.
AAD − Used to adjust ASCII codes after division.
CBW − Used to fill the upper byte of the word with the copies of sign bit of the
lower byte.
CWD − Used to fill the upper word of the double word with the sign bit of
the lower word.
3. LOGICAL INSTRUCTIONS
These instructions are used to perform operations where data bits are involved,
i.e. operations like logical, shift, etc.
Following is the list of instructions under this group −
SHL/SAL − Used to shift bits of a byte/word towards left and put zero(S) in LSBs.
SHR − Used to shift bits of a byte/word towards the right and put zero(S) in
MSBs.
SAR − Used to shift bits of a byte/word towards the right and copy the old
MSB into the new MSB.
ROL − Used to rotate bits of byte/word towards the left, i.e. MSB to LSB and to
Carry Flag [CF].
ROR − Used to rotate bits of byte/word towards the right, i.e. LSB to MSB and to
Carry Flag [CF].
RCR − Used to rotate bits of byte/word towards the right, i.e. LSB to CF and CF to
MSB.
RCL − Used to rotate bits of byte/word towards the left, i.e. MSB to CF and CF to
LSB.
4. STRING INSTRUCTIONS
String is a group of bytes/words and their memory is always allocated in a
sequential order.
Following is the list of instructions under this group −
REP − Used to repeat the given instruction till CX ≠ 0.
REPE/REPZ − Used to repeat the given instruction until CX = 0 or zero flag ZF = 1.
REPNE/REPNZ − Used to repeat the given instruction until CX = 0 or zero flag ZF
= 1.
MOVS/MOVSB/MOVSW − Used to move the byte/word from one string to
another.
COMS/COMPSB/COMPSW − Used to compare two string bytes/words.
INS/INSB/INSW − Used as an input string/byte/word from the I/O port to
the provided memory location.
OUTS/OUTSB/OUTSW − Used as an output string/byte/word from the provided
memory location to the I/O port.
SCAS/SCASB/SCASW − Used to scan a string and compare its byte with a byte in
AL or string word with a word in AX.
LODS/LODSB/LODSW − Used to store the string byte into AL or string word into
AX.
6. PROCESSOR CONTROLINSTRUCTIONS
These instructions are used to control the processor action by setting/resetting the
flag values.
Following are the instructions under this group −
STC − Used to set carry flag CF to 1
CLC − Used to clear/reset carry flag CF to 0
CMC − Used to put complement at the state of carry flag CF.
STD − Used to set the direction flag DF to 1
CLD − Used to clear/reset the direction flag DF to 0
STI − Used to set the interrupt enable flag to 1, i.e., enable INTR input.
CLI − Used to clear the interrupt enable flag to 0, i.e., disable INTR input.
In a minimum mode 8086 system, the microprocessor 8086 is operated in minimum mode by strapping its
MN/MX* pin to logic1. In this mode, all the control signals are given out by the microprocessor chip itself.
There is a single microprocessor in the minimum mode system. The remaining components in the system
are latches, transreceivers, clock generator, memory and I/O devices. Some type of chip selection logic
may be required for selecting memory or I/O devices, depending upon the address map of the system.
Latches:
The latches are generally buffered output D-type flip-flops, like, 74LS373 or 8282. They are used for
separating the valid address from the multiplexed address/data signals and are controlled by the ALE
signal generated by 8086.
Transreceivers
Transreceivers are the bidirectional buffers and some times they are called as data amplifiers. They are
required to separate the valid data from the time multiplexed address/data signal. They are controlled by
two signals, namely, DEN* and DT/R*. The DEN* signal indicates that the valid data is available on the
data bus, while DT/R indicates the direction of data, i.e. from or to the processor.
Memory:
The system contains memory for the monitor and users program storage. Usually, EPROMS are used for
monitor storage, while RAMs for users program storage.
IO Devices:
A system may contain I/O devices for communication with the processor as well as some special purpose
I/O devices.
Clock Generator:
The clock generator generates the clock from the crystal oscillator and then shapes it and divides to make
it more precise so that it can be used as an accurate timing reference for the system. The clock generator
also synchronizes some external signals with the system clock.
The general system organization is shown in above fig .Since it has 20 address lines and 16 data lines,
the 8086 CPU requires three octal address latches and two octal data buffers for the complete address
and data separation.
The working of the minimum mode configuration system can be better described in terms of the timing
diagrams rather than qualitatively describing the operations. The opcode fetch and read cycles are
similar. Hence the timing diagram can be categorized in two parts.
The read cycle begins in T1 with the assertion of the address latch enable (ALE) signal and also M/IO*
signal. During the negative going edge of this signal, the valid address is latched on the local bus. The
BHE* and A0 signals address low, high or both bytes. From Tl to T4, the M/IO* signal indicates a
memory or I/O operation. At T2 the address is removed from the local bus and is sent to the output. The
bus is then tristated. The read (RD*) control signal is also activated in T2
Maximum mode of 8086 with timing diagrams
In the maximum mode, the 8086 is operated by strapping the MN/MX* pin to ground.
In this mode, the processor derives the status signals S2*, S1* and S0*. Another chip called bus
controller derives the control signals using this status information. In the maximum mode, there may be
more than one microprocessor in the system configuration. The other components in the system are the
same as in the minimum mode system. The general system organization is as shown
The basic functions of the bus controller chip IC8288, is to derive control signals like RD* and WR* (for
memory and I/O devices), DEN*, DT/R*, ALE, etc. using the information made available by the processor
on the status lines.
The bus controller chip has input lines S2*, S1* and S0* and CLK. These inputs to 8288 are driven by the
CPU. It derives the outputs ALE, DEN*, DT/R*, MWTC*, AMWC*, IORC*, IOWC* and AIOWC*.
The AEN*, IOB and CEN pins are specially useful for multiprocessor systems. AEN* and IOB are
generally grounded. CEN pin is usually tied to +5V
INTA* pin is used to issue two interrupt acknowledge pulses to the interrupt controller or to an interrupting
device.IORC*, IOWC* are I/O read command and I/O write command signals respectively. These signals
enable an IO interface to read or write the data from or to the addressed port. The MRDC*, MWTC* are
memory read command and memory write command signals respectively and may be used as memory
read and write signals. All these command signals instruct the memory to accept or send data from or to
the bus. For both of these write command signals, the advanced signals namely AIOWC* and AMWTC*
are available. They also serve the same purpose, but are activated one clock cycle earlier than the
IOWC* and MWTC* signals, respectively.
The maximum mode system timing diagrams are also divided in two portions as read (input) and write
(output) timing diagrams. The address/data and address/status timings are similar to the minimum mode.
ALE is asserted in T1, just like minimum mode. The only difference lies in the status signals used and the
available control and advanced command signals.
Multiprocessor means a multiple set of processors that executes instructions simultaneously. There are
three basic multiprocessor configurations.
Coprocessor configuration
Coprocessor Configuration
A Coprocessor is a specially designed circuit on microprocessor chip which can perform the same task
very quickly, which the microprocessor performs. It reduces the work load of the main processor. The
coprocessor shares the same memory, IO system, bus, control logic and clock generator. The
coprocessor handles specialized tasks like mathematical calculations, graphical display on screen, etc.
The 8086 and 8088 can perform most of the operations but their instruction set is not able to perform
complex mathematical operations, so in these cases the microprocessor requires the math coprocessor
like Intel 8087 math coprocessor, which can easily perform these operations very quickly.
The coprocessor and the processor is connected via TEST, RQ-/GT- and QS0 & QS1 signals.
The TEST signal is connected to BUSY pin of coprocessor and the remaining 3 pins are
connected to the coprocessor’s 3 pins of the same name.
TEST signal takes care of the coprocessor’s activity, i.e. the coprocessor is busy or idle.
The coprocessor uses QS0 & QS1 to track the status of the queue of the host processor.
Closely coupled configuration is similar to the coprocessor configuration, i.e. both share the same
memory, I/O system bus, control logic, and control generator with the host processor. However, the
coprocessor and the host processor fetches and executes their own instructions. The system bus is
controlled by the coprocessor and the host processor independently.
Communication between the host and the independent processor is done through memory space.
None of the instructions are used for communication, like WAIT, ESC, etc.
The host processor manages the memory and wakes up the independent processor by sending
commands to one of its ports.
Then the independent processor accesses the memory to execute the task.
After completion of the task, it sends an acknowledgement to the host processor by using the
status signal or an interrupt request.
Loosely coupled configuration consists of the number of modules of the microprocessor based systems,
which are connected through a common system bus. Each module consists of their own clock generator,
memory, I/O devices and are connected through a local bus.
Having more than one processor results in increased efficiency.
Each of the processors have their own local bus to access the local memory/I/O devices. This
makes it easy to achieve parallel processing.
The system structure is flexible, i.e. the failure of one module doesn’t affect the whole system
failure; faulty module can be replaced later.
BASIS OF
LOOSELY COUPLED SYSTEMS CLOSELY COUPLED SYSTEMS
COMPARISON
Loosely coupled systems have a CLOSELY coupled systems have a shared
Memory Concept
distributed memory concept. memory concept.
The interconnections in a CLOSELY
coupled system are Processor-memory
The interconnection network in a
interconnection network (PMIN), I/O-
Interconnection loosely coupled system is Message
Processor interconnection network (IOPIN)
Transfer System (MTS).
and the interrupt-signal interconnection
network (ISIN).
Data rate of the loosely coupled The data rate of CLOSELY coupled system
Data Rate
system is low. is high.
They are widely used in distributed They are widely used in parallel processing
Application
computing systems. systems.
Throughput in this type of systems is
Throughput Throughput in this type of systems is high.
low.
Power Power consumption is high. Power consumption is low.
Operating It operates on multiple operating
It operates on single operating system.
System systems.
Delay It has high delay. It has low delay.
Unit-IV
Program counter,
ALU
Working registers
Clock circuits.
Internal ROM and RAM
I/O ports with programmable pins
Timers and counters
Serial data communication
A and B Registers
The A and B registers are called CPU registers. They are used to hold the data for most of the
CPU (ALU) operations. The size of A and B registers are 8-bit and they are mapped as on-chip data
memory with byte address E0H and F0H respectively. These registers are also bit-addressable.
In most of the ALU operations, the result is stored in the A-register and so, it is also known
as the accumulator.
I/O Ports
The 8051 has four numbers of 8-bit ports, namely, port-0, port-1, port-2 and port-3. Each
port has a latch and driver (or buffer). When external memory is employed the port-0 lines will
function as multiplexed low byte address/data lines and port-2 lines will function as high byte
address lines. Also, the port pins P3.7 and P3.6 are used to output read and write control signals
respectively. In fact, each pin of port-3 has an alternate function
The program status word store the status of the result of the ALU operations and some of the
status of the processor by means of a 1-bit status called flags. The PSW is also known as a flag
register. The flags are useful for the programmer to test the condition of the result and make decisions.
The format of the PSW of an 8031/8051 microcontroller
PSW consists of four math flags and two register bank select bits. The math flags are carry, auxiliary
carry, overflow and parity flags. These flags are altered after arithmetic and logical operations
depending on the result. The carry flag is set when the result has a carry. When there is a carry
from the lower nibble to the upper nibble, the auxiliary carry is set. When the result has even parity,
the parity flag is set. In certain mathematical operations if the size of the result exceeds the size of
the destination register then the overflow flag is set.
2.Addressing mode of 8051
The instruction set of microcontroller 8051 can be divided into the following groups:
Memory
Since the size of the address pointers are 16-bit they can address up to 216 = 64 k memory
locations. Hence 8031/8051 supports two memory banks of 64 kb each, one for program and
the other
for data. In 8051, when the EA pin is tied to the VCC (logic-1), the first 4 kb of program
memory address
space refers to 4 kb internal ROM and the remaining 60 kb refer to external (EPROM/RAM)
memory.
In 8051, when the EA pin is tied to the ground (logic-0), the entire 64 kb of program address
space
refers to external (EPROM/RAM) memory. In 8031 there is no internal ROM and so EA pin is
always
grounded and in this case the entire program memory is external.
The 8031/8051 has separate 256 bytes internal RAM accessed by using an 8-bit address. In
this 256 bytes address space, the first 128 addresses are allotted to internal RAM and the
next 128
bytes are allotted to SFR. The internal RAM/SFR can be accessed by using MOV
instructions and
external data memory (RAM) can be accessed by using MOVX instruction.
The 8031/8051 is provided with 21 special function registers and they are used for selecting
various programmable features of the microcontroller. The special functions of most of the
SFR
are distinguishable. Each SFR has an internal one-byte address assigned to it. Some of the
registers
are both byte and bit-addressable.
5.Ports
Port 0
Port 0 pins may serve as inputs, outputs, or, when used together, as a bi-
directional low order address and data bus for external memory.
When used as an output, the pin latches that are programmed to a 0 will
turn on the lower FET, grounding the pin. All latches that are
programmed to a 1 still float; thus, external pullup resistors will be
needed to supply a logic high when using port 0 as an output . When port
0 is used as an address bus to external memory, internal control signals
switch the address lines to the gates of the Field Effect Transistories
(FETs). A logic I on an address bit will turn the upper FET on and the
lower FET off to provide a logic high at the pin. When the address bit is a
zero, the lower FET is on and the upper FET off to provide a logic low at
the pin. After the address has been formed and latched into external
circuits by the Address Latch Enable (ALE) pulse, the bus is turned
around to become a data bus. Port 0 now reads data from the external
memory and must be configured as an input, so a logic 1 is automatically
written by internal control logic to all port 0 latches.
Port l
Used as an input, a 1 is written to the latch, turning the lower FET off; the
pin and the input to the pin buffer are pulled high by the FET load. An
external circuit can overcome the high impedance pull up and drive the
pin low to input a 0 or leave the input high for a 1.
Port 2
Port 2 pins are momentarily changed by the address control signals when
supplying the high byte of a 16-bit address. Port 2 latches remain stable
when external memory is addressed, as they do not have to be turned
around (set to 1) for data input as is the case for port 0.
Port3
Port 3 is an input/output port similar to port I. The input and output functions can be
programmed under the control of the P3 latches or under the control of various other special
function registers. The port 3 alternate uses are shown in the following table:-
Unlike ports 0 and 2, which can have external addressing functions and change
all eight port bits when in alternate use, each pin of port 3 may be individually
programmed to be used either as I/O or as one of the alternate functions
Unit V
Timers of 8051
The 8051 has two timers: timer0 and timer1. They can be used either as timers or as counters. Both
timers are 16 bits wide. Since the 8051 has an 8-bit architecture, each 16-bit is accessed as two separate
registers of low byte and high byte.
Timer0 registers is a 16 bits register and accessed as low byte and high byte. The low byte is referred as
a TL0 and the high byte is referred as TH0. These registers can be accessed like any other registers.
Timer1 registers is also a 16 bits register and is split into two bytes, referred to as TL1 and TH1.
TMOD (timer mode) Register: This is an 8-bit register which is used by both timers 0 and 1 to
set the various timer modes. In this TMOD register, lower 4 bits are set aside for timer0 and the
upper 4 bits are set aside for timer1. In each case, the lower 2 bits are used to set the timer
mode and upper 2 bits to specify the operation.
In upper or lower 4 bits, first bit is a GATE bit. Every timer has a means of starting and
stopping.. The hardware way of starting and stopping the timer by an external source is
achieved by making GATE=1 in the TMOD register. And if we change to GATE=0 then we do
no need external hardware to start and stop the timers.
The second bit is C/T bit and is used to decide whether a timer is used as a time delay
generator or an event counter. If this bit is 0 then it is used as a timer and if it is 1 then it is used
as a counter.
In upper or lower 4 bits, the last bits third and fourth are known as M1 and M0 respectively.
These are used to select the timer mode.
M1 M2 Mode
1 1 Spilt mode.
Mode0- Both Timer 1 and Timer 0 in Mode 0 operate as 8-bit counters (with a divide-by-32
prescaler). Timer register is configured as a 13-bit register consisting of all the 8 bits of TH1 and
the lower 5 bits of TL1. The upper 3 bits of TL1 are indeterminate and should be ignored.
Setting the run flag (TR1) does not clear the register. The timer interrupt flag TF1 is set when
the count rolls over from all 1s to all 0s. Mode 0 operation is the same for Timer 0 as it is for
Timer 1.
Mode 1- It is a 16-bit timer; therefore it allows values from 0000 to FFFFH to be loaded into the
timer’s registers TL and TH. After TH and TL are loaded with a 16-bit initial value, the timer must
be started. We can do it by “SETB TR0” for timer 0 and “SETB TR1” for timer 1.
After the timer is started. It starts count up until it reaches its limit of FFFFH. When it rolls over
from FFFF to 0000H, it sets high a flag bit called TF (timer flag). This timer flag can be
monitored. When this timer flag is raised, one option would be stop the timer with the
instructions “CLR TR0“ or CLR TR1 for timer 0 and timer 1 respectively. Again, it must be noted
that each timer flag TF0 for timer 0 and TF1 for timer1.
After the timer reaches its limit and rolls over, in order to repeat the process the registers TH
and TL must be reloaded with the original value and TF must be reset to 0.
.
Mode 2-
Both the timer registers are configured as 8-bit counters (TL1 and TL0) with automatic reload.
Overflow from TL1 (TL0) sets TF1 (TF0) and also reloads TL1 (TL0) with the contents of Th1
(TH0), which is preset by software. The reload leaves TH1 (TH0) unchanged.
Mode3- Mode 3 is also known as a split timer mode. Timer 0 and 1 may be programmed to be
in mode 0, 1 and 2 independently of similar mode for other timer. This is not true for mode 3;
timers do not operate independently if mode 3 is chosen for timer 0. Placing timer 1 in mode 3
causes it to stop counting; the control bit TR1 and the timer 1 flag TF1 are then used by timer0.
TCON register- Bits and symbol and functions of every bits of TCON are as follows:
7 TF1 Timer1 over flow flag. Set when timer rolls from all 1s to 0. Cleared
When the processor vectors to execute interrupt service routine.
The 8051 microcontroller is parallel device that transfers eight bits of data simultaneously over eight data
lines to parallel I/O devices. Parallel data transfer over a long is very expensive. Hence, a serial
communication is widely used in long distance communication. In serial data communication, 8-bit data is
converted to serial bits using a parallel in serial out shift register and then it is transmitted over a single
data line. The data byte is always transmitted with least significant bit first.
1. SBUF Register: Serial Buffer (SBUF) register is an 8-bit register. It has separate SBUF registers for
data transmission and for data reception. For a byte of data to be transferred via the TXD line, it must be
placed in SBUF register. Similarly, SBUF holds the 8-bit data received by the RXD pin and read to accept
the received data.
2. SCON register: The contents of the Serial Control (SCON) register are shown below. This register
contains mode selection bits, serial port interrupt bit (TI and RI) and also the ninth data bit for
transmission and reception (TB8 and RB8).
INITIALIZATION AND ACCESSING SERIAL PORT REGISTERS
Receiver Enable The receiver enable bit (REN) in SCON must be set by software to enable the reception
of characters. This is usually done at the beginning of a program when the serial port, timers, etc., are
initialized.
This can be done in two ways. The instruction sets REN and sets or clears the other bits in SCON, as
required. SETB REN ; explicitly sets REN, or the instruction Interrupt Flags
The receive and transmit interrupt flags (RI and TI) in SCON play an important role in 8051 serial
communications. Both bits are set by hardware, but must be cleared by software.
Typically, RI is set at the end of character reception and indicates "receive buffer full." This condition is
tested in software or programmed to cause an interrupt.
TI is set at the end of character transmission and indicates "transmit buffer empty." If software wishes to
send a character to the device connected to the serial port, it must first check that the serial port is ready.
In other words, if a previous character was sent, wait until transmission is finished before sending the next
character.
3. PCON register: The SMOD bit (bit 7) of PCON register controls the baud rate in asynchronous mode
transmission.
Mode 0 In this mode serial port runs in synchronous mode. The data is transmitted and received through
RXD pin and TXD is used for clock output. In this mode the baud rate is 1/12 of clock frequency.
Mode 1 In this mode SBUF becomes a 10 bit full duplex transceiver. The ten bits are 1 start bit, 8 data bit
and 1 stop bit. The interrupt flag TI/RI will be set once transmission or reception is over. In this mode the
baud rate is variable and is determined by the timer 1 overflow rate.
Mode 2
This is similar to mode 1 except 11 bits are transmitted or received. The 11 bits are, 1 start bit, 8 data bit,
a programmable 9th data bit, 1 stop bit. Baud rate = [2smod/64] x Oscillator Clock Frequency
1. TMOD register is loaded with the value 20H, indicating the use of timer 1 in mode 2 (8-bit auto-reload)
to set baud rate
2. The TH1 is loaded with one of the values to set baud rate for serial data transfer
3. The SCON register is loaded with the value 50H, indicating serial mode 1, where an 8- bit data is
framed with start and stop bits
7. The TI flag bit is monitored with the use of instruction JNB TI, xx to see if the character has been
transferred completely
Stepper Motor
Stepper motors are used to translate electrical pulses into mechanical movements. In some disk drives,
dot matrix printers, and some other different places the stepper motors are used. The main advantage of
using the stepper motor is the position control. Stepper motors generally have a permanent magnet shaft
(rotor), and it is surrounded by a stator.
Interfacing Stepper Motor with 8051 Microcontroller
Weare using Port P0 of 8051 for connecting the stepper motor. HereULN2003 is used. This is basically a
high voltage, high current Darlington transistor array. Each ULN2003 has seven NPN Darlington pairs. It
can provide high voltage output with common cathode clamp diodes for switching inductive loads.
Wave Drive Mode − In this mode, one coil is energized at a time. So all four coils are energized
one after another. This mode produces less torque than full step drive mode.
The following table is showing the sequence of input states in different windings .
1 1 0 0 0
2 0 1 0 0
3 0 0 1 0
4 0 0 0 1
Full Drive Mode − In this mode, two coils are energized at the same time. This mode
produces more torque. Here the power consumption is also high
The following table is showing the sequence of input states in different windings.
1 1 1 0 0
2 0 1 1 0
3 0 0 1 1
4 1 0 0 1
Half Drive Mode − In this mode, one and two coils are energized alternately. At first,
one coil is energized then two coils are energized. This is basically a combination of
wave and full drive mode. It increases the angular rotation of the motor
The following table is showing the sequence of input states in different windings.
1 1 0 0 0
2 1 1 0 0
3 0 1 0 0
4 0 1 1 0
5 0 0 1 0
6 0 0 1 1
Steps Winding A Winding B Winding C Winding D
7 0 0 0 1
8 1 0 0 1
In many applications, an analog device has to be interfaced to the digital system. But the digital devices
cannot accept the analog signals directly and so the analog signals are converted to equivalent digital
signal (data) using an Analog-to-Digital Converter (ADC).
The analog to digital (A/D) conversion is the reverse process of Digital-to-Analog (D/A) conversion. The
A/D conversion is also called quantization, in which the analog signal is represented by an equivalent
binary data.
The analog signals vary continuously and defined for any interval of time. The digital signals (or data) can
take only finite values and defined only for discrete instant of time. If the digital data is represented by n-
bit binary then it can have 2n different values. In A/D conversion the given analog signal has to divided
into steps of 2n values, and each step is represented by one of the 2n values.
Analog to digital converters can be classified into two groups based on the technique involved for
conversion. The first group includes successive-approximation, counter and flash-type converters. The
technique involved in these devices is that the given analog signal is compared with internally generated
analog signal. The second group includes integrator converters and voltage to frequency converters. In
the devices of the second group, the given analog signal is converted to time or frequency and the new
parameters (time or frequency) is compared with known values to produce digital signal.
. The successive-approximation type converters are used for high speed conversion and integrating type
converters are used for high accuracy.
The resolution of the converter is the minimum analog value that can be represented by the digital data. If
the ADC gives n-bit digital output and the full scale analog input is X volts, then the resolution is 1 /2n × X
volts.
In ADC, another critical parameter is conversion time. The conversion time is defined as the total time
required to convert an analog signal into its digital equivalent. It depends on the conversion technique and
the propagation delay in various circuits.
The generated digital data is converted to analog signal by D/A converter and then compared with given
analog signal. When the analog signals are equal, the comparator output informs the control unit to stop
generation of digital signal. The digital data available at this instant is given as output through output
register. Also, the control unit generates a signal to indicate the End Of Conversion (EOC) process to the
processor.
In simple systems when the ports are free the ADC0809 can be directly interfaced through the port pins of
8x5x family of controllers. An example of a ADC interface with a 8x5x controller
In this system the channel address (A, B, C) and the control signals (ALE,SOC, EOC, OE) are applied
through port-0 pins. The ADC data (i.e, converted digital data) is read through port 1. The program for
ADC conversion can be permanently stored in the internal program memory of the controller.
The DAC will accept a digital (binary) input and convert to analog voltage or current. Every DAC will have
"n" input lines and an analog output. The DAC requires a reference analog voltage (Vref) or current (Iref)
source. The smallest possible analog value that can be represented by the n-bit binary code is called
resolution. The resolution of DAC with n-bit binary input is 1 / 2 n of reference analog value. Every analog
output will be a multiple of the resolution.
In some converters, the input reference analog signal will be multiplied or divided by a constant to get full
scale value. In this case, the resolution will be 1 / 2 n of full scale value.
For example, consider an 8-bit DAC with reference analog voltage of 5-Volts. Now the resolution of the
DAC is (1/28 ) × 5-Volts. The 8-bit digital input can take, 28 = 256 different values. The analog values for all
possible digital
The DAC0800 is an 8-bit, high speed, current output DAC with a typical settling time (conversion time) of
100 ns. It produces complementary current output which can be converted to voltage by using simple
resistor load.
In simple systems, when the ports are free the DAC0800 can be directly interfaced to an 8-bit port of any
8x5x family of controller, as shown in Fig. 9.87. In this system, the controller can be programmed to work
as a signal generator for various applications and the program can be permanently stored in the internal
program memory of the controller. Since the 8x5x ports are internally provided with latch there is no need
for external latch to interface DAC0800.
The DAC0800 can also be interfaced to an 8031/8051 microcontroller as memory-mapped IO, as shown
in Fig. 9.88. In this case an 8-bit latch such as 74LS273 is interfaced to the system bus and mapped in
the data memory address space with 16-bit address. The DAC0800 is connected to output lines of the
latch. The controller will load the digital data to the latch and it will hold the data on its output lines. The
next data will be loaded to the latch only when previous data has been converted to analog value. The
loading of consecutive data to the latch of DAC is controlled by software time delay.
The address lines A13, A14 and A15 are decoded to generate 8 chip select signals and in this the
signal CS3 is used as logic low enable for the DAC latch 74LS273. The signals RD and WR are
logically ANDed and used as logic low enable for the decoder and the signal PSEN is used as logic
high enable for the decoder.
Pin 5 R/W (high for read from register, low for write to the register)
Pin 6 EN (sends data to data pins when high to low pulse is given)
Data register
Command register
Data register: It is for placing the data which is to be displayed. Data can be any character, alphabet or
number.High logic at the RS pin will select the data register. By making RS pin high and putting data in
the 8 bit data line (DB0 to DB7), the LCD module will recognize it as a data to be displayed.
Command register:It is for placing the commands. There is a set of commands for LCD to perform
specific tasks. Low logic at the RS pin will select the command register.By making RS pin low and putting
data on the data line, the LCD module will recognize it as a command.Some of the
instructions/commands are given below:
R/W pin is for selecting between read and write modes. High level at this pin enables read mode and low
level at this pin enables write mode.
DB0 to DB7 are the data pins. The data to be displayed and the commands are placed on these pins.
For glowing backlight LED, LED+ (anode of back light LED)is connected to Vcc through a suitable series
current limiting resistor (for contrast adjustment). LED-(cathode of the back light LED) is connected to
ground.