EC6504 SCAD MSM by WWW - Learnengineering.in
EC6504 SCAD MSM by WWW - Learnengineering.in
in
ENGINEERING COLLEGES
Prepared by
Sl.
Name of the Faculty Designation Affiliating College
No.
1. Ms.K.Jayalakshmi AP SCADIT
2. Ms.K.Kokila AP SCADIT
TEXT BOOKS:
1. Yu-Cheng Liu, Glenn A.Gibson, “Microcomputer Systems: The 8086 / 8088 Family
-Architecture, Programming and Design”, Second Edition, Prentice Hall of India,
2007.
2. Mohamed Ali Mazidi, Janice Gillispie Mazidi, Rolin McKinlay, “The 8051
microcontroller and Embedded Systems: Using Assembly and C”, Second
Edition, Pearson Education, 2011
REFERENCE:
1. Doughlas V.Hall, “Microprocessors and Interfacing, Programming and
Hardware:,TMH, 2012
TABLE OF CONTENTS
Sl. Page
Topic
No No.
A Aim and Objective 1
C Part A 4
D Part B 7
5. Modular Programming 42
7. Stacks 47
8. Procedures 48
9. Macros 49
E Part C 58
F Part A 65
G Part B 68
Sl. Page
Topic
No No.
H. PART C 83
I. Part A 90
J. Part B 92
K. PART C 148
UNIT IV MICROCONTROLLER
L. Part A 155
M. Part B 158
N. PART C 175
Sl. Page
Topic
No No.
36. Square wave generation 175
O. Part A 177
P. Part B 180
Q. PART C 198
Text Book
1. Yu-Cheng Liu, Glenn A.Gibson, “Microcomputer Systems: The 8086 / 8088
Family -Architecture, Programming and Design”, Second Edition, Prentice Hall of
India, 2007.
2. Mohamed Ali Mazidi, Janice Gillispie Mazidi, Rolin McKinlay, “The 8051
Microcontroller and Embedded Systems: Using Assembly and C”, Second
Edition, Pearson Education, 2011
References
1. Doughlas V.Hall, “Microprocessors and Interfacing, Programming and Hardware:,
TMH, 2012
Hours Books
Sl. Cumulati
Unit Topic / Portions to be Covered Required Referre
No ve Hrs
/ Planned d
UNIT-I : INTRODUCTION
1. 1 Introduction to 8086& Architecture 1 1 TB1
2. 1 Addressing modes, Instruction set 1 2 TB1
3. 1 Assembler directives 1 3 TB1
4. 1 Assembly language programming 2 5 TB1
5. 1 Modular Programming 1 6 TB1
6. 1 Linking and Relocation 1 7 TB1
7. 1 Stacks, Procedures , Macros 1 8 TB1
8. 1 Interrupts and interrupt service routines 1 9 TB1
9. 1 Byte and String Manipulation 1 10 TB1
UNIT – II : 8086 SYSTEM BUS STRUCTURE
Hours Books
Sl. Cumulati
Unit Topic / Portions to be Covered Required Referre
No ve Hrs
/ Planned d
17. 2 Introduction to advanced processors. 1 20 TB1
UNIT- III: I/O INTERFACING
18. 3 Memory Interfacing and I/O interfacing 1 21 TB1
19. 3 Parallel communication interface 1 22 TB1
20. 3 Serial communication interface 1 23 TB1
21. 3 D/A and A/D Interface 1 24 RB1
22. 3 Timer 1 25 TB1
23. 3 Keyboard /display controller 1 26 TB1
24. 3 Interrupt controller 1 27 RB1
25. 3 DMA controller 1 28 TB1
Programming and applications Case
studies: Traffic Light control, LED WEB
26. 3 2 30
display, LCD display, Keyboard display NOTES
interface and Alarm Controller
UNIT – IV : MICROCONTROLLER
27. 4 Architecture of 8051 2 32 TB2
28. 4 Special Function Registers(SFRs) 1 33 TB2
29. 4 I/O Pins Ports and Circuits 1 34 TB2
30. 4 Instruction set 2 36 TB2
31. 4 Addressing modes 1 37 TB2
32. 4 Assembly language programming 2 39 TB2
UNIT-V : INTERFACING MICROCONTROLLER
33. 5 Programming 8051 Timers 1 40 TB2
34. 5 Serial Port Programming 1 41 TB2
35. 5 Interrupts Programming 1 42 TB2
36. 5 LCD & Keyboard Interfacing 2 44 TB2
37. 5 ADC, DAC & Sensor Interfacing 2 46 TB2
38. 5 External Memory Interface 2 48 TB2
Stepper Motor and Waveform
39. 5 2 50 TB2
generation.
PART A
1. Write about the different types of interrupts supported in 8086. [Apr/May
2015]
The following are the various types of interrupts:
Type 0 interrupts: This interrupt is also known as the divide by zero interrupt.
For cases where the quotient becomes particularly large to be placed /
adjusted an error might occur.
Type 1 interrupts: This is also known as the single step interrupt. This type of
interrupt is primarily used for debugging purposes in assembly language.
Type 2 interrupts: also known as the non-maskable NMI interrupts. These types
of interrupts are used for emergency scenarios such as power failure.
Type 3 interrupts: These types of interrupts are also known as breakpoint
interrupts. When this interrupt occurs a program would execute up to its break
point.
Type 4 interrupts: Also known as overflow interrupts is generally existent after
an arithmetic Operation was performed.
CALL PUSH
When CALL is executed the
The programmer uses the
microprocessor automatically
instruction PUSH to save the
stores the 16-bit address of the
contents of the register pair on
instruction next to CALL on the
the stack
stack
Procedure Macro
Accessed by CALL & RET instruction Accessed during assembly with name
during program execution given to macro when defined
Machine code is generated for
Machine code for instruction is put
instruction each time when macro is
only once in the memory
called
With procedures less memory is
With macro more memory is required
required
Parameters can be passed in Parameters passed as part of
registers, memory locations or stack statement which calls macro
There are 4 segment registers present in 8086. They are Code Segment (CS)
register, Data Segment (DS) register, Stack Segment (SS) register, Extra Segment
(ES) register. The code segment register gives the address of the current code
segment. ie. It will points out where the instructions, to be executed, are stored in the
memory. The data segment register points out where the operands are stored in the
memory. The stack segment registers points out the address of the current stack,
which is used to store the temporary results. If the amount of data used is more, the
Extra segment registers points out where the large amount of data is stored in the
memory.
from the memory. Due to this, overlapping instruction fetch with instruction execution
increases the processing speed.
10. Draw the Flag register format of 8086? [April/May 2011] [May/June-2016]
[Nov/Dec 16]
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
U U U U OF DF IF TF SF ZF U AF U PF U CF
11. What are the two modes of operations present in 8086? [May/June2007]
1. Minimum Mode (or) Uniprocessor System
2. Maximum Mode (or) Multiprocessor System
13. What is the processing element inside the microprocessor? What process
it does? [Nov/Dec 2014]
The processing element inside the microprocessor is the ALU. It performs all
computing operation such as Addition, Subtraction, Multiplication, and Division and
Logical operation.
15. Calculate the physical address, when segment address is 1085H and
effective address is 4537H[Nov/Dec 2015]
Effective address = 4 5 3 7
Segment address =1 0 8 5 0
Physical address = 1 4 D 8 7
PART B
Intel 8086 is a 16 bit processor. It has 16-bit data bus and 20-bit address bus. The
lower 16-bit address lines and 16-bit data lines are multiplexed (AD0-AD15). Since
20-bit address lines are available, 8086 can access up to 220 or 1 Giga byte of
physical memory. The architecture of the 8086 can be internally divided into two
separate functional units as shown in figure 1.1
The BIU fetches instructions, reads data from memory and IO ports, writes
data to memory and IO ports. The BIU contains segment registers, instruction
pointer, instruction queue, address generation unit and bus control unit. The Bus
Interface Unit (BIU) generates the 20-bit physical memory address. To speed up the
execution, 6-bytes of instruction are fetched in advance and kept in a 6-byte
Instruction Queue called pipe-lining. In 8086 microprocessor memory are divided into
four parts which is known as the segments as shown in figure 1.2. These segments
are data segment, code segment, stack segment and extra segment. Each
segments of 64 kilo bytes.
The BIU has four numbers of 16-bit segment registers. They are Code
Segment (CS) register, Data Segment (DS) register, Stack Segment (SS) register
and Extra Segment (ES) register. The 4 segment registers are used to hold four
segment base addresses.
Code segment (CS) is a 16-bit register containing address of 64 KB segment
with processor instructions. The programs will be stored in code segment region.
The processor uses CS segment for all accesses to instructions referenced by
instruction pointer (IP) register.
Stack segment (SS) is a 16-bit register containing address of 64KB segment with
program stack. Data related with stack operation are stored in this segment region.
All data referenced by the stack pointer (SP) and base pointer (BP) registers is
located in the stack segment.
Data segment (DS) is a 16-bit register containing address of 64KB segment with
program data. Data referenced by general registers (AX, BX, CX, DX) and index
register (SI, DI) is located in the data segment.
Accumulator register consists of two 8-bit registers AL and AH, which can be
combined together and used as a 16-bit register AX.
Base Register consists of two 8-bit registers BL and BH, which can be combined
together and used as a 16-bit register BX. BX register
Count Register consists of two 8-bit registers CL and CH, which can be combined
together and used as a 16-bit register CX. Count register can be used as a counter
in string manipulation and shift/rotate instructions.
Data Register consists of two 8-bit registers DL and DH, which can be combined
together and used as a 16-bit register DX. Data register can be used as a port
number in I/O operations
Overflow Flag (OF) - set if the result is too large positive number, or is too small
negative number to fit into destination operand.
Direction Flag (DF) - if set then string manipulation instructions will auto-
decrement index registers. If cleared then the index registers will be auto-
incremented.
Interrupt-enable Flag (IF) - setting this bit enables maskable interrupts.
Single-step Trap Flag (TF) - if set then single-step interrupt will occur after the
next instruction.
Sign Flag (SF) - set if the most significant bit of the result is set.
Zero Flag (ZF) - set if the result is zero.
10
Auxiliary carry Flag (AF) - set if there was a carry from or borrow to bits 0-3 in the
AL register during BCD operation.
Parity Flag (PF) - set if parity (the number of "1" bits) in the low-order byte of the
result is even.
Carry Flag (CF) - set if there was a carry from or borrow to the most significant bit
during last result calculation.
11
12
b. ARITHMETIC INSTRUCTIONS
IMUL BL Multiply signed byte in AL with signed byte in BL; result in AX.
IMUL BX Multiply BX with AX; result in DX and AX
14
15
DAA
AL = 37 BCD, CF = 1
1. AL = 07 After AAA AL = 07
2. AL = 6A, AH = 00 ie AX 006A after AAA AX = 0100
16
c. LOGICAL INSTRUCTIONS
OR – OR Destination, Source
This instruction ORs each bit in a source byte or word with the same numbered bit in
a destination byte or word. The result is put in the specified destination.
17
CF ZF SF
CX = BX 0 1 0 Result of subtraction is 0
CX > BX 0 0 0 No borrow required, so CF = 0
CX < BX 1 0 1 Subtraction requires borrow, so CF = 1
Compare immediate number 01H with byte in
CMP AL, 01H AL
CMP BH, CL Compare byte in CL with byte in BH
This instruction ANDs the byte / word in the specified source with the byte / word in
the specified destination.
Flags are updated, but neither operand is changed. The test instruction is often
used to set flags before a Conditional jump instruction.
TEST AL, BH AND BH with AL. No result stored; Update PF, SF, ZF.
18
CF
To rotate the operand by one bit position, specify this by putting a 1 in the count
position of the instruction. To rotate by more than one bit position, load the desired
number into the CL register and put “CL” in the count position of the instruction.
CF
If you want to rotate the operand by one bit position, you can specify this by putting a
1 in the count position of the instruction. To rotate more than one bit position, load
the desired number into the CL register and put “CL” in the count position of the
instruction.
19
CF
If you to want rotate the operand by one bit position, you can specify this by putting 1
in the count position in the instruction. To rotate more than one bit position, load the
desired number into the CL register and put “CL” in the count position of the
instruction.
CF
To rotate the operand by one bit position, specify this by putting 1 in the count
position in the instruction. To rotate by more than one bit position, load the desired
number into the CL register and put “CL” in the count position of the instruction.
CF 0
To shift the operand by one bit position, specify this by putting a 1 in the count
position of the instruction. For shifts of more than 1 bit position, load the desired
number of shifts into the CL register, and put “CL” in the count position of the
instruction.
Shift word in BX 1 bit position left, 0 in LSB
20
SAL BX, 1
MOV CL, 02H Load desired number of shifts in CL
Shift word in BX left CL bit positions, 0 in
SAL BX, CL LSBs
CF
To shift the operand by one bit position, specify this by putting a 1 in the count
position of the instruction. For shifts of more than 1 bit position, load the desired
number of shifts into the CL register, and put “CL” in the count position of the
instruction.
SAR DX, 1 Shift word in DX one bit position right, new MSB = old MSB
SHR – SHR Destination, Count
This instruction shifts each bit in the specified destination some number of bit
positions to the right. As a bit is shifted out of the MSB position, a 0 is put in its place.
The bit shifted out of the LSB position goes to CF.
0 CF
To shift the operand by one bit position, specify this by putting a 1 in the count
position of the instruction. For shifts of more than 1 bit position, load the desired
number of shifts into the CL register, and put “CL” in the count position of the
instruction.
21
This instruction will fetch the next instruction from the location specified in the
instruction rather than from the next location after the JMP instruction. Two types of
Jump instruction. Far Jump and Near Jump
If the destination is in the same code segment as the JMP instruction, then only
the instruction pointer will be changed to get the destination location. This is
referred to as a near jump.
If the destination for the jump instruction is in a segment with a name different
from that of the segment containing the JMP instruction, then both the instruction
pointer and the code segment register content will be changed to get the
destination location. This referred to as a far jump. The JMP instruction does not
affect any flag.
JMP CONTINUE
This instruction fetches the next instruction from address at label CONTINUE.
JB / JC / JNAE
(JUMP IF BELOW / JUMP IF CARRY / JUMP IF NOT ABOVE OR EQUAL)
If, after a compare or some other instructions which affect flags, the carry flag is a 1,
this instruction will cause execution to jump to a label given in the instruction. If CF is
0, the instruction will have no effect on program execution.
22
JGE / JNL (JUMP IF GREATER THAN OR EQUAL / JUMP IF NOT LESS THAN)
This instruction is usually used after a Compare instruction. The instruction will
cause a jump to the label given in the instruction, if the sign flag is equal to the
overflow flag.
CMP BL, 39H Compare by subtracting 39H from BL
Jump to label NEXT if BL more positive
JGE NEXT than or equal to 39H
CMP BL, 39H Compare by subtracting 39H from BL
Jump to label NEXT if BL not less than
JNL NEXT 39H
This instruction is usually used after a Compare instruction. The instruction will
cause a jump to the label given in the instruction if the sign flag is not equal to the
overflow flag.
23
DEC AL Decrement AL
JNS NEXT Jump to label NEXT if AL has not decremented to FFH
24
JCXZ SKIP
SUB [BX], 07H
SKIP: ADD C
If CX = 0, skip the process Subtract 7 from data value Next instruction
f. LOOP INSTRUCTIONS
25
This instruction is used to repeat a series of instructions some number of times. The
number of times the instruction sequence is to be repeated is loaded into CX. Each
time the LOOP instruction executes, CX is automatically decremented by 1.
g.
26
27
The CMPS instruction can be used with a REPE or REPNE prefix to compare all the
elements of a string.
28
REP is a prefix, which is written before one of the string instructions. It will cause the
CX register to be decremented and the string instruction to be repeated until CX = 0.
The instruction REP MOVSB, for example, will continue to copy string bytes until the
number of bytes loaded into CX has been copied.
REPE and REPZ are two mnemonics for the same prefix. They stand for repeat if
equal and repeat if zero, respectively. They are often used with the Compare String
instruction or with the Scan String instruction. They will cause the string instruction to
be repeated as long as the compared bytes or words are equal (ZF = 1) and CX is
not yet counted down to zero. In other words, there are two conditions that will stop
the repetition: CX = 0 or string bytes or words not equal.
Compare string bytes until end of string or until string bytes not
REPE CMPSB equal
REPNE and REPNZ are also two mnemonics for the same prefix. They stand
for repeat if not equal and repeat if not zero, respectively. They are often used with
the Compare String instruction or with the Scan String instruction. They will cause
the string instruction to be repeated as long as the compared bytes or words are not
equal (ZF = 0) and CX is not yet counted down to zero.
REPNE SCASW Scan a string of word until a word in the string matches the
word in AX or until all of the string has been scanned.
29
k. INPUT-OUTPUT INSTRUCTIONS
IN – IN Accumulator, Port
The IN instruction copies data from a port to the AL or AX register. If an 8-bit port is
read, the data will go to AL. If a 16-bit port is read, the data will go to AX.
For the variable-port form of the IN instruction, the port address is loaded into the DX
register before the IN instruction. Since DX is a 16-bit register, the port address can
be any number between 0000H and FFFFH. Therefore, up to 65,536 ports are
addressable in this mode.
For variable port form of the OUT instruction, the content of AL or AX will be copied
to the port at an address contained in DX. Therefore, the DX register must be loaded
with the desired port address before this form of the OUT instruction is used.
30
ESC (ESCAPE)
This instruction is used to pass instructions to a coprocessor, such as the 8087 Math
coprocessor, which shares the address and data bus with 8086. Instructions for the
coprocessor are represented by a 6-bit code embedded in the ESC instruction. As
the 8086 fetches instruction bytes, the coprocessor also fetches these bytes from the
data bus and puts them in its queue
31
32
Program:
DATA SEGMENT
BCD DB 17H
BIN DB ?
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
MOV AX, DATA
MOV DS, AX
MOV AL, BCD
MOV AH, BCD
AND AH, 0FH
MOV BL, AH
AND AL, 0F0H
MOV CL, 04H
ROR AL, CL
MOV BH, 0AH
MUL BH
ADD AL,BL
MOV BIN, AL
MOV AX, 4C00H
INT 21H
CODE ENDS
RESULT: The Binary Number for the given BCD Number 17H is 11H .
DATA SEGMENT
STR1 DB "ENTER YOUR STRING HERE ->$"
STR2 DB "YOUR STRING IS ->$"
STR3 DB "REVERSE STRING IS ->$"
INSTR1 DB 20 DUP("$")
RSTR DB 20 DUP("$")
NEWLINE DB 10,13,"$"
N DB ?
S DB ?
MSG1 DB "STRING IS PALINDROME$"
MSG2 DB "STRING IS NOT PALINDROME$"
A DB "1"
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START: MOV AX,DATA
MOV DS,AX
LEA SI,INSTR1 ;GET STRING
33
MOV AH,09H
LEA DX,STR1
INT 21H
MOV AH,0AH
MOV DX,SI
INT 21H
MOV AH,09H
LEA DX,NEWLINE
INT 21H ;PRINT THE STRING
MOV AH,09H
LEA DX,STR2
INT 21H
MOV AH,09H
LEA DX,INSTR1+2
INT 21H
MOV AH,09H
LEA DX,NEWLINE
INT 21H ;PRINT THE REVERSE OF THE STRING
MOV AH,09H
LEA DX,STR3
INT 21H
MOV CL,INSTR1+1
ADD CL,1
ADD SI,2
L1: INC SI
CMP BYTE PTR[SI],"$"
JNE L1
DEC SI
LEA DI,RSTR
L2: MOV AL,BYTE PTR[SI]
MOV BYTE PTR[DI],AL
DEC SI
INC DI
LOOP L2
MOV AH,09H
LEA DX,NEWLINE
INT 21H
MOV AH,09H
LEA DX,RSTR
INT 21H
MOV AH,09H
LEA DX,NEWLINE
INT 21H ;PRINT THE STRING IS PALINDROME OR NOT
LEA SI,INSTR1
LEA DI,RSTR
MOV AH,09H
LEA DX,NEWLINE
INT 21H
ADD SI,2
L7: MOV BL,BYTE PTR[DI]
34
35
36
LIST DB 0lH, 02H, 03H, 04H Reserve four memory locations for a list
named LIST and initialize them with the
above specified four values.
MESSAGE DB 'GOOD Reserve the number of bytes of memory
MORNING' equal to the number of characters in the
string named MESSAGE and initialize those
locations by the ASCII equivalent of these
characters.
DW: Define Word.
The DW directive makes the assembler reserve the number of memory words(16-
bit).
37
38
The EVEN directive updates the location counter to the next even address if the
current location counter contents are not even, and assigns the following routine or
variable or constant to that address. The structure given below explains the directive.
EVEN PROCEDURE ROOT
.
ROOT ENDP
The above structure shows a procedure ROOT that is to be aligned at an even
address.
MODULEl SEGMENT
PUBLIC FACTORIAL FAR
MODULEl ENDS
MODULE2 SEGMENT
EXTRN FACTORIAL FAR
MODULE2 ENDS
LABEL: Label
The Label directive is used to assign a name to the current content of the location
counter. At the start of the assembly process, the assembler initializes a location
counter to keep track of memory locations assigned to the program. As the program
assembly proceeds, the contents of the location counter are updated. During the
39
assembly process, whenever the assembler comes across the LABEL directive, it
assigns the declared label with the current contents of the location counter. The type
of the label must be specified, i.e. whether it is a NEAR or a FAR label, BYTE or
WORD label, etc.
A LABEL directive may be used to make a FAR jump as shown below. A FAR
jump cannot be made at a normal label with a colon. The label CONTINUE can be
used for a FAR jump, if the program contains the following statement.
CODE SEGMENT
MOV SI, OFFSET LIST
CODE ENDS
DATA SEGMENT
40
LIST DB 10H
DATA ENDS
ORG: Origin
The ORG directive directs the assembler to start the memory allotment for the
particular segment, block or code from the declared address in the ORG statement
While starting the assembly process for a module, the assembler initializes a location
counter to keep track of the allotted addresses for the module. If the ORG statement
is not written in the program, the location counter is initialized to 0000. If an ORG
200H statement is present at the starting of the code segment of that module, then
the code will start from 200H address in code segment) In other words, the location
counter will get initialized to the address 0200H instead of 0000H. Thus, the code for
different modules and segments can be located in the available memory as required
by the programmer. The ORG directive can even be used with data segments
similarly.
PROC: Procedure
The PROC directive marks the start of a named procedure in the statement. Also,
the types NEAR or FAR specify the type of the procedure, i.e whether it is to be
called by the main program located within 64K of physical memory or not.
RESULT PROC NEAR
ROUTINE PROC FAR
PTR: Pointer
The pointer operator is used to declare the type of a label, variable or memory
operand. The operator PTR is prefixed by either BYTE or WORD. If the prefix is
BYTE, then the particular label, variable or memory operand is treated as an 8-
bit quantity, while if WORD is the prefix, then it is treated as a 16-bit quantity. In
other words, the PTR operator is used to specify the data type - byte or word.
MOV AL, BYTE PTR [SI] Moves content of memory location addressed by SI (8-
bit) to AL
INC BYTE PTR [BX] Increments byte contents of memory location
addressed by BX
41
SHORT
The SHORT operator indicates to the assembler that only one byte is required to
code the displacement for a jump (i.e. displacement is within -128 to +127 bytes from
the address of the byte next to the jump opcode).
GLOBAL
The labels, variables, constants or procedures declared GLOBAL may be used by
other modules of the program. Once a variable is declared GLOBAL, it can be used
by any module in the program.
The primary aid used in subdividing a program into modules is the hierarchical
diagram which summarizes the relationships between the modules and submodules.
42
The main module corresponds to the president of the corporation, the Modules
A, B & C corresponds to the Vice president and so on. The concept of modular
programming refers to development of program codes in modules and merging the
codes of various modules into single program code. When the program to be
developed is too large to be developed by a single programmer, a team can be
formed to develop the program. The overall task can be divided into number of
smaller tasks and each smaller task can be developed as a module by a team
member, and the modules can be integrated by the team leader to obtain the
program for overall task.
The advantages of modular programming are,
43
Functions of Loaders
Operating System
Listing
Memory
map
Other
Make Object
corrections Modules
Library
In any event the resulting object modules, some of which are grouped into libraries
must be linked together to form a load module before the program can be executed.
In addition to outputting the load module normally the linker prints a memory map
44
that indicates where the linked object modules will be loaded into memory, After the
load module has been created it is loaded into the memory of the computer by the
loader and execution begins. Although the I/O can be performed by modules within
the program, normally the I/O is done by I/O drivers that are part of the operating
system. All that appears in the user program are references to the I/O drivers that
cause the operating system to execute them.
The object modules to be linked are determined by naming them in the command to
the linker and by the operating system searching through libraries. The order in
which the object modules appear in the linker command may determine the order in
which they are stacked together to form the load module.
Segment combination
where the combine-type indicates how the segment is to be located within the load
module. Segments that have different names cannot be combined and segments
with the same name but no combine-type will cause a linker error. The possible
combine-types are:
PUBLIC – If the segments in different modules have the same name and combine-
type PUBLIC, then they are concatenated into a single element in the load module.
The ordering in the concatenation is specified by the linker command.
COMMON – If the segments in different object modules have the same name and
the combine-type is COMMON, then they are overlaid so that they have the same
starting address. The length of the common segment is that of the longest segment
being overlaid.
45
STACK – If segments in different object modules have the same name and the
combine-type STACK, then they become one segment whose length is the sum of
the lengths of the individually specified segments. In effect, they are combined to
form one large stack
MEMORY – This combine-type causes the segment to be placed at the last of the
load module. If more than one segment with the MEMORY combine-type is being
linked, only the first one will be treated as having the MEMORY combine type; the
others will be overlaid as if they had COMMON combine-type.
By causing two or more code segments to be put in a single segment the use of
PUBLIC eliminates the need to change the contents of CS register as the program
passes between sets of instructions within the code segment ie. It allows
intersegment branches to be replaced by intra segment branches. Data segments
can be given the PUBLIC combine type to cause several sets of data to be combined
into one larger set.
Code in Source
Code Segment
Module 1
Code in Source
Module 2
46
The offset for local identifiers are inserted by the assembler. However, the offset for
the external identifiers and all segment address are inserted by the linking process.
Linking process determines the exact address for segment to be put in memory and
then the address are assigned to segment. This process is known as relocation.
6a.STACKS
In 8086 microprocessor based system, the stack is created by loading a 16-bit base
address in Stack Segment (SS) register and a 16-bit offset address in Stack Pointer
(SP). The 20-bit physical address of the stack is computed by multiplying the
contents of SS register by 1610 and then adding the contents of SP to this product.
Here the content of SP is the offset address of the stack. Upon reset, the SS-register
and SP are cleared to zero. For every write operation into stack, the SP is
automatically decremented by two and for every read operation from stack, the SP is
automatically incremented by two. The contents of SS register will not be altered
while reading or writing into the stack.
In an 8086 processor, the content of the register can be stored in the stack using the
PUSH instruction and the stored information can be retrieved back to the register
using the POP instruction. when a number of registers have to be stored and
retrieved in the stack, the order of retrieval should be reverse that of the order of the
storageFor example, let BX be pushed to the stack first and DX next. When the
stored information has to be retrieved to appropriate registers then the top of stack
47
should be popped to DX first and then to BX next. The storage and retrieval in stack
are in reverse order, because the SP is decremented for every write operation into
the stack and SP is incremented for every read operation form the stack. Therefore
the stack in an 8086 is called Last- In-First-Out (LIFO) stack, i.e., the last stored
information can be read first. A typical example of stack in 8086 is shown in the
figure
6b. PROCEDURES
48
stored in the same segment where the main program is also stored. A procedure can
be called using far call instruction if the procedure and main program are stored in
different memory segments. The procedures are terminated with RET instructions.
The 8086 has two types of RET instructions and they are near return and far return.
The near return instruction is used to terminate a procedure stored in the same
segment. The far return instruction is used to terminate a procedure stored in a
different segment.
When a procedure is called by using far call instruction, the 8086 processor will
push the contents of IP and CS-register in stack and the segment base address of
procedure is loaded in CS register and the effective address of procedure is loaded
in IP. Now the program control is transferred to procedure stored in another segment
and so the processor will start executing the instructions of the procedure. At the end
of procedure, RET instruction is encountered. On executing the RET instruction, the
top of stack (which is the previous stored value) is popped to CS register and IP.
Thus the program control is returned to main program.
When a procedure is called by using near call instruction, the 8086 processor
will push the contents of IP alone in stack and the effective address of procedure is
loaded in IP. Here the content of CS register is not altered. Now the program control
is transferred to procedure stored in same segment and so the processor will start
executing the instructions of the procedures. At the end of procedure, RET
instruction is encountered. On executing the RET instruction, the top of stack (which
is the previous stored value) is popped to IP. Thus, the program control is returned to
main program.
The main advantage of using a procedure is that the machine codes for the
group of instructions in the procedure has to be put in memory only once. The
disadvantages of using the procedure are the need for a stack, and the overhead
time required to call the procedure and return to the calling program.
Disadvantages of Procedure
1. Linkage associated with them.
2. It sometimes requires more code to program the linkage than is needed to
perform the task. If this is the case, a procedure may not save memory and
execution time is considerably increased.
Hence a means is needed for providing the programming ease of a procedure while
avoiding the linkage. This need is fulfilled by Macros
6c. MACROS
How does one define and call macro parameters of 8086 microprocessor? (4
Marks) [April/May 2010]
When a group of instructions are to be used several times to perform a same
function in a program and they are too small to be written as a procedure, then they
can be defined as a macro. Macro is a small group of instructions enclosed by the
49
assembler directives MACRO and ENDM. Macros are identified by their name and
usually defined at the start of a program.
The macro is called by its name in the program. Whenever a macro is called in
a program, the assembler will insert the defined group of instructions in place of the
call. In other words, the macro call is like shorthand expression which tells the
assembler, “Every time you see a macro name in the program, replace it with the
group of instructions defined as macro”. Actually the assembler generates machine
codes for the group of instructions defined as macro, whenever it is called in the
program. The process of replacing the macro with the instructions it represent is
called expanding the macro. Hence, macros are also known as open subroutines
because they get expanded at the point of macro invocation.
When macros are used, the generated machine codes are right-in-line with the
rest of the program and so the processor does not have to go off to a procedure call
and return. This results in avoiding the overhead time involved in calling and
returning from a procedure. The disadvantage of using macro is that the program
may take up more memory due to insertion of the machine codes in the program at
the place of macros. Hence, the macros should be used only when its body has a
few program statements.
50
MOV XYZ[BX],AX
POP AX
POP DX
It is possible to define a macro with no dummy parameters, but in this case the call
must not include any parameters. Consider a macro for pushing the contents at
beginning of a procedure.
Macro definition consists of
%*DEFINE(SAVEREG)
( PUSH AX
PUSH BX
PUSH CX
PUSH DX
)
This macro is called using the statement
%SAVEREG
The above macro can be called at the beginning of the each procedure to save the
register contents. A similar macro could be used to restore the register contents at
the end of each procedure.
%*DEFINE (RESTORE)
( POP DX
POP CX
POP BX
POP AX )
51
Interrupt: The process of interrupting the normal program execution to carry out a
specific task/work.
The interrupt is initiated by a signal generated by an external device or by a
signal generated internal by the processor. When a microprocessor receives an
interrupt signal it stops executing current normal program, save the status (or
content) of various registers (IP, CS and flag registers in case of 8086) in stack and
then the processor executes a subroutine/procedure in order to perform the specific
task/work requested by the interrupt. The subroutine/procedure that is executed in
response to an interrupt is also called Interrupt Service Subroutine. (ISR). At the
end of ISR, the stored status of registers in stack is restored to respective registers,
and the processor resumes the normal program execution from the point (instruction)
where it was interrupted.
Classification of Interrupts
In general the interrupts can be classified in the following three ways:
1. Hardware and software interrupts
2. Vectored and Non Vectored interrupt
3. Maskable and Non Maskable interrupts.
Hardware and Software Interrupts
The interrupts initiated by external hardware by sending an appropriate signal to the
interrupt pin of the processor is called hardware interrupt. The 8086 processor has
two interrupt pins INTR and NMI. The software interrupts are program instructions.
These instructions are inserted at desired locations in a program. While running a
program, if software interrupt instruction is encountered then the processor initiates
an interrupt. The 8086 processor has 256 types of software interrupts. The software
interrupt instruction is INT n, where n is the type number in the range 0 to 255.
52
1. One source is from an external signal applied to NMI or INTR input pin of the
processor. The interrupts initiated by applying appropriate signals to these
input pins are called hardware interrupts.
2. A second source of an interrupt is execution of the interrupt instruction "INT
n", where n is the type number. The interrupts initiated by "INT n" instructions
are called software interrupts.
3. The third source of an interrupt is from some condition produced in the 8086
by the execution of an instruction. An example of this type of interrupt is divide
by zero interrupt. Program execution will be automatically interrupted if you
attempt to divide an operand by zero. Such conditional interrupts are also
known as exceptions.
Interrupts of 8086
The 8086 microprocessor has 256 types of interrupts. INTEL has assigned a
type number to each interrupt. The type numbers are in the range of 0 to 255. The
8086 processor has dual facility of initiating these 256 interrupts. The interrupts can
be initiated either by executing "INT n" instruction where n is the type number or the
interrupt can be initiated by sending an appropriate signal to INTR input pin of the
processor. For the interrupts initiated by software instruction" INT n ", the type
number is specified by the instruction itself.
53
The predefined interrupts are only defined by INTEL and INTEL has not
provided any subroutine/procedure to be executed for these interrupts. To use the
predefined interrupts the user/ system designer has to write Interrupt Service
Subroutine (ISS) for each interrupt and store them in memory. The corresponding
address of the ISS should be stored in interrupt vector table. If a predefined interrupt
is not used in a system then the user may assign some other functions to these
interrupts.
disabled or masked. Usually, the type-2 interrupt is used to save program data or
processor status in case of system ac power failure. The ac power failure is detected
by an external hardware and whenever the ac power fails, the external hardware will
send an interrupt signal to the NMI input pin of the processor.
The “INT n” instructions are called software interrupts. The “INT n” instruction
will initiate type-n interrupt, and the value of n is in the range of 0 to 255. Therefore,
all the 256 type interrupts including the INTEL predefined and reserved interrupts
can be initiated through “INT n” instruction. The software interrupts are nonmaskable
and has higher priority than hardware interrupts.
The interrupts initiated by applying appropriate signals to INTR and NMI pins of
8086 are called hardware interrupts. All the 256 types of interrupts including INTEL
predefined and reserved interrupts can be initiated by applying a high signal to INTR
55
pin of 8086. When a high signal is applied to the INTR pin and the hardware
interrupt is enabled/unmasked, then the processor runs an interrupt acknowledge
cycle to get the type number of the interrupt from the device which sends the
interrupt signal. The interrupting device can send a type number in the range of 0 to
25510. Therefore, all the 256 types of interrupts can be initiated through INTR pin.
The hardware interrupts initiated through INTR are maskable by clearing the
Interrupt Flag (IF), i.e., the hardware interrupts are masked/disabled when IF = 0 and
they are unmasked/enabled when IF = 1. The interrupts initiated through INTR has
lower priority than software interrupts.
The hardware interrupt NMI is nonmaskable and has higher priority than
interrupts initiated through INTR. The NMI is initiated by a rising edge (or low-to-high
transition) of the signal applied to NMI pin of the processor. The processor will
execute type-2 interrupt in response to interrupt initiated through NMI pin and this
type number is fixed by INTEL. The external device, interrupting the processor
through NMI pin, need not supply the type number for this interrupt.
56
The 8086 processor checks for interrupt request at the end of each instruction cycle.
If an interrupt request is deducted, then the 8086 processor responds to the interrupt
by performing the following operations:
1 The SP is decremented by two and the content of flag register is pushed to
stack memory.
2 The interrupt system is disabled by clearing Interrupt Flag (IF).
3 The single-step trap flag is disabled by clearing Trap Flag (TF).
4 The stack pointer is decremented by two and the content of CS-register is
pushed to stack memory.
5 Again, the stack pointer is decremented by two and the content of IP is pushed
to stack memory.
57
PART- C
58
59
Types of Microprocessor
Microprocessors are classified into five types, namely: CISC-Complex
Instruction Set Microprocessors, RISC-Reduced Instruction Set Microprocessor,
ASIC- Application Specific Integrated Circuit, Superscalar Processors, and DSP‟s-
Digital Signal Microprocessors.
60
Superscalar Microprocessors
Superscalar processor facsimiles the hardware on the processor to perform
various tasks at a time. These processors can be used for ALUs or multipliers. They
have different operational units and these processors can carry out more than a one
command by continuously transmitting several instructions to the extra operational
units inside the processor.
The Application Specific Integrated Circuit
The short term of Application Specific Integrated Circuit processor is an ASIC.
These processors are used for particular purposes that includes of automotive
emissions control or personal digital assistants computer. This type of processor is
made with proper specification, but apart from these it can also be made with off the
shelf gears.
Digital Signal Multiprocessors
Digital signal processors are also called as DSP‟s, these processors are used
to encode and decode the videos or to convert the D/A (digital to analog) &A/D
(analog to digital). They need a microprocessor that is excellent in mathematical
calculations. The chips of this processor are employed in RADAR, home theaters,
SONAR, audio gears, TV set top boxes and Mobile phones. There are many
companies like Intel, Motorola, DEC (Digital Equipment Corporation ), TI (Texas
Instruments) associated with many microprocessors such as 8085 microprocessors,
ASIC, CISM, RISC, DSPs and 8086 microprocessors like Intel
Advantages and Disadvantages of Microprocessors
The advantages of microprocessors are
The processing speed is high
Intelligence has been brought to systems
Flexible.
Compact size.
Easy maintenance
Complex mathematics
Some of the disadvantages of microprocessor are it might get overheated and the
limitation of the microprocessor imposes on size of data.
61
62
63
• It generates two files namely object file (.OBJ) and assembler list file (.LST).
Linker
• It is a program used to join several object files into large object files.
• While writing large programs it is good to divide them into modules so that
each modules can be written, tested, debugged independently and then use
linker to combine the modules to form the actual program.
• It produces two files link file which contains the binary codes of all the
combined modules and a link map file which contains the address information
about the linked files.
Locators
• A locator is the program used to assign the specific addresses of where the
segments of object code are to be loaded in to main memory.
• Examples include EXE2BIN which comes with the IBM PC DOS.
• Converts .exe to .bin files which has physical addresses
Debugger
• A debugger is the program which allows you to load your object code program
in to system memory.
• It allows you to look at the contents of the registers and memory locations
after your program runs.
• It also allows you to set breakpoints at any points in the program.
• It simply allows you to find the source of the problem into the program.
• There are lots of debuggers available like Borland Turbo Debugger,
Microsoft‟s Code view debugger etc.
Emulators
• One way to run your program
• It is mixture of hardware and software.
• Generally used to test the hardware and software of an external system such
as microprocessor based instruments.
64
8086 signals – Basic configurations – System bus timing –System design using 8086
– IO programming – Introduction to Multiprogramming – System Bus Structure –
Multiprocessor configurations – Coprocessor, Closely coupled and loosely Coupled
configurations – Introduction to advanced processors.
PART A
1. Define bus. Why bus request and cycle stealing are required. [Apr/May 2015,
Nov/Dec 16]
The microprocessors functions as the CPU in the stored program model
of the digital computer. Its job is to generate all system timing signals and
synchronize the transfer of data between memory, I/O, and itself. It accomplishes
this task via the three-bus system architecture named as address bus, data bus
and control bus.
The cycle stealing mode is used in systems in which the CPU should
not be disabled for the length of time needed for burst transfer modes. In the cycle
stealing mode, the DMA controller obtains access to the system bus the same way
as in burst mode, using BR (Bus Request) and BG (Bus Grant) signals, which are
the two signals controlling the interface between the CPU and the DMA controller.
However, in cycle stealing mode, after one byte of data transfer, the control of the
system bus is deserted to the CPU via BG. It is then continually requested again via
BR, transferring one byte of data per request, until the entire block of data has been
transferred.
2. What are the advantages of coprocessor? [May/Jun 2014]
A coprocessor is a special set of circuit in a microprocessor chip that is
designed to manipulate numbers or perform some other specialized function
more quickly than the basic microprocessor circuits could perform the same
task.
The coprocessor, also known as a math coprocessor, numeric coprocessor,
or floating-point unit ( FPU), became a physical part of the microprocessor chip.
Some coprocessors are still available as separate chips or circuit cards. These
are designed for specific applications such as high-end
graphics, broadband signal processing , and encryption / decryption .
Coprocessors of this type make it possible to customize the various models in a
line of personal or business computers.
65
during "hold" state. This pin is Low during T1 state for the first interrupt acknowledge
cycle.
4. What is meant by a loosely coupled configuration? [May/Jun 2014]
A loosely coupled configuration provides the following advantages:
High system throughput can be achieved by having more than one CPU.
The system can be expanded in a modular form. Each bus master module is
an independent unit and normally resides on a separate PC board. Therefore,
a bus master module can be added or removed without affecting the other
modules in the system.
A failure in one module normally does not cause a breakdown of the entire
system and the faulty module can be easily detected and replaced.
Each bus master may have a local bus to access dedicated memory or I/O
devices so that a greater degree of parallel processing can be achieved. More
than one bus master module may have access to the shared system bus.
Extra bus control logic must be provided to resolve the bus arbitration problem.
The extra logic is called bus access logic and it is its responsibility to make sure that
only one bus master at a time has control of the bus. Simultaneous bus requests are
resolved on a priority basis: There are three schemes for establishing priority:
1. Daisy chaining.
2. Polling.
3. Independent requesting.
7. In what ways are the standard microprocessor and coprocessor differ from
each other?[Nov/Dec 2012]
The processor takes care of all the major processing and the co-processor or the
auxiliary processor unit takes care of some other things like arithmetic calculations or
graphics to allow the main processor to work on more difficult tasks.
A co-processor is a unique set of circuit. It is used in enhancing the functions of
the primary processor. It is intended to direct the performance and the functions of
the microprocessor. It has a quick performance than the primary processor.
8. How does the main processor distinguish its instructions from the co-
processor instructions when it fetches the instructions from memory?
[Nov/Dec 2012][Nov/Dec 2015]
ESC instruction is used to differentiate the processor and co-processor
instruction when it fetches the instruction from memory.
66
External bus:
The external bus is made up of the electronic pathways that connect the different
external devices, such as printer to the computer. It also referred to as expansion
bus.
67
PART B
The 8086 signals can be categorized in three groups. The first are the signals
having common functions in minimum as well as maximum mode, the second are
the signals which have special functions in minimum mode and third are the signals
having special functions for maximum mode
AD15-AD0: These are the time multiplexed memory I/O address and data lines.
When ALE = 1 :AD15-AD0 contains the address
ALE = 0 :AD15-AD0 contains the data
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 or memory operations.
The address bits are separated from the status bits using latches controlled by the
ALE signal.
S4 S3 Function
0 0 Extra segment
access
0 1 Stack segment
access
1 0 Code segment
access
1 1 Data segment
access
68
BHE/S7-Bus High Enable/Status: The bus high enable signal is used to indicate the
transfer of data over the higher order (D15-D8) data bus. It goes low for the data
transfers over D15-D8 and is used to derive chip selects of odd address memory bank
or peripherals.
One bank is connected to the lower half of the 16-bit data bus (D0 – D7) and
contains even address bytes. i.e., when A0 bit is low, the bank is selected. The other
bank is connected to the upper half of the data bus (D8 - D15) and contains odd
address bytes. i.e., when A0 is high and BHE (Bus High Enable) is low, the odd bank
is selected. A specific byte within each bank is selected by address lines A1-A19.
RD-Read: Read signal, when low, indicates the peripherals that the processor is
performing a memory or I/O read operation.
READY: This is the acknowledgement from the slow devices 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. The
signal is active high.
BHE A0 Indication
0 0 Whole Word
Upper byte from or to odd
0 1
address
Upper byte from or to even
1 0
address
1 1 No Operation
INTR : Interrupt Request: If any interrupt request is pending, the processor enters
the interrupt acknowledge cycle. This can be internally masked by resetting the
interrupt enable flag. This signal is active high and internally synchronized.
TEST: This input is examined by a 'WAIT' instruction. If the TEST input goes low,
69
RESET: This input causes the processor to terminate the current activity and start
execution from FFFF0H. The signal is active high and must be active for at least four
clock cycles. It restarts execution when the RESET returns low. RESET is also
internally synchronized.
CLK : The clock input provides the basic timing for processor operation and bus
control activity. The range of frequency for different 8086 versions is from 5MHz to
10MHz.
VCC :+5V power supply for the operation of the internal circuit. GND ground for the
internal circuit.
MN/MX: The logic level at this pin decides whether the processor is to operate in
either minimum (single processor) or maximum (multiprocessor) mode.
The following pin functions are for the minimum mode operation of 8086.
M/IO: Memory/IO: When it is low, it indicates the CPU is having an I/O operation,
and when it is high, it indicates that the CPU is having a memory operation.
INTA: Interrupt Acknowledge:. It means that the processor has accepted the
interrupt.
ALE: Address latch Enable: This output signal indicates the availability of the valid
address on the address/data lines, and is connected to latch enable input of latches.
DT/R Data Transmit/Receive: This output is used to decide the direction of data
flow through the transceivers (bidirectional buffers). When the processor sends out
data, this signal is high and when the processor is receiving data, this signal is low.
DEN: Data Enable This signal indicates the availability of valid data over the
address/data lines. It is used to enable the transceivers (bidirectional buffers) to
separate the data from the multiplexed address/data signal.
70
The following pin functions are applicable for maximum mode operation of
8086.
LOCK: This output pin indicates that other system bus masters will be prevented
from gaining the system bus, while the LOCK signal is low. When 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. The 8086, while executing the prefixed instruction, asserts the bus
lock signal output, which may be connected to an external bus controller.
QS1, QS0-Queue Status: These lines give information about the status of the
code-prefetch queue.
0 0 No operation
S2,S1,S0: Status Lines: These are the status lines which reflect the type of
operation, being carried out by the processor. These status lines are encoded in
table.
S2 S1 S0 Characteristics
Interrupt
0 0 0
acknowledge
0 1 1 Halt
1 0 0 Code access
1 0 1 Read memory
1 1 0 Write memory
1 1 1 Passive State
71
RQ/GT0, RQ/GT1: Request/Grant: These pins are used by other local bus masters,
in maximum mode, to force the processor to release the local bus at the end of the
processor's current bus cycle. Each of the pins is bidirectional with RQ/GT 0 having
higher priority than RQ/ GT1; RQ/GT pins have internal pull-up resistors and may be
left unconnected.
72
The above figure shows the timing diagram of read cycle. The read cycle begins in
73
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 T l 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 .The read (RD) signal causes the addressed
device to enable its data bus drivers. After RD* goes low, the valid data is available
on the data bus. The addressed device will drive the READY line high, when the
processor returns the read signal to high level, the addressed device will again
tristate its bus drivers.
Figure shows the timing diagram of write cycle. A write cycle also begins with the
assertion of ALE and the emission of the address. The M/IO* signal is again
asserted to indicate a memory or I/O operation. In T 2 after sending the address in Tl
the processor sends the data to be written to the addressed location. The data
remains on the bus until middle of T 4 state. The WR* becomes active at the
beginning ofT2 (unlike RD* is somewhat delayed in T2 to provide time for floating).
The BHE* and A0 signals are used to select the proper byte or bytes of memory or
I/O word to be read or written. The M/IO*, RD* and WR* signals indicate the types of
data transfer as specified in Table.
M/IO RD WR Transfer Type
0 0 1 I/O read
0 1 0 I/O write
1 0 1 Memory read
1 1 0 Memory write
74
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 in the
figure
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*. 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
75
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 T 1, just
like minimum mode. The only difference lies in the status signals used and the
available control and advanced command signals.
76
MULTIPROCESSOR SYSTEMS
A multiprocessor system will have two or more processors that can execute
instructions or perform operations simultaneously.
Advantages:
l. Several low cost processors may be combined to fit the needs of an application
while avoiding the expense of the unneeded capabilities of a centralized system.
2. It is easy to add more processor for expansion as per requirement.
3. When a failure occurs, it is easier to replace the faulty processor.
4. In a multiprocessor system implementation of modular processing of task can be
achieved
Coprocessor Configuration
In coprocessor configuration both the CPU (8086) and external processor (Math
Coprocessor8087) share entire memory and I/O sub system. They also share same
bus control logic and clock generator.8086 is the master and 8087 is the slave.
An instruction to be executed by the coprocessor is indicated by an escape (ESC)
prefix or instruction.
77
78
The main difference between coprocessor and closely coupled configuration is, no
special instruction WAIT or ESC is used. The communication between 8086 and
independent processor is done through memory space. As shown in Figure the 8086
sets up a message in memory and wakes up independent processor by sending
command to one of its ports. The independent processor then accesses the memory
to execute the task in parallel with the 8086. When task is completed the external
processor informs the 8086 about the completion of task by using either a status bit
or an interrupt request
79
Advantages
High system throughput can be achieved by having more than one CPU.
The system can be expanded in modular form. Each bus master module is an
independent unit and normally resides on a separate PC board. One can be
added or removed without affecting the others in the system.
A failure in one module normally does not affect the breakdown of the entire
system and the faulty module can be easily detected and replaced
Each bus master has its own local bus to access dedicated memory or IO
devices so a greater degree of parallel processing can be achieved
80
5. BUS ARBITRATION
Multiple devices may need to use the bus at the same time so it must have a way to
arbitrate multiple requests. Bus arbitration schemes usually try to balance:
Bus priority – the highest priority device should be serviced first
Fairness – even the lowest priority device should never be completely locked out
from the bus
Bus arbitration schemes can be divided into three classes
1.Daisy chaining.
2.Polling.
3.Independent requesting
Daisy Chaining
In Daisy Chaining method all masters make use of the same line for bus
request. In response to a bus request, the controller sends a bus grant if the bus is
free. The bus grant signal serially propagates through each master until it encounters
the first one that is requesting access to the bus. This master blocks the propagation
of the bus grant signal, activates the busy line and gains control of the bus.
Therefore any other requesting module will not receive the grant signal and hence
cannot get the bus access. This bus allocation scheme is simple and cheaper But
failure of any one master causes the whole system to fail and arbitration is slow due
to the propagation delay of bus grant signal is proportional to the number of masters
Polling
In polling method, the controller sends address of device to grant bus access.
The number of address lines required is depend on the number of masters
connected in the system.
81
For example, if 3 Masters are connected in the system, one address line is required.
In response to a bus request, controller generates a sequence of master addresses
when the requesting master recognizes the address; it activates the busy line and
begins to use the bus. The priority can be changed by altering the polling sequence
stored in the controller Another one advantage of this method is, if one module fails
entire system does not fail.
Independent Priority
In the independent priority scheme each master has a separate pair of bus
request (BRQ) and bus grant (BGR) lines and each pair has a priority assigned to it.
The built in priority decoder within the controller selects the highest priority request
and asserts the corresponding bus grant signal. Synchronization of clocks must be
performed once a master is recognized; Master will receive a common clock from
one side and pass it to the controller which will derive a clock for transfer. Due to
separate pairs of bus request and bus grant signals, arbitration is fast.
82
PART-C
1. Explain general bus operation of 8086 and explain bus request and bus
grant timings of 8086.
The 8086 has a combined address and data bus commonly referred as a
time multiplexed address and data bus.
The main reason behind multiplexing address and data over the same pins
is the maximum utilization of processor pins and it facilitates the use of 40
pin standard DIP package.
The bus can be demultiplexed using a few latches and transceivers,
whenever required.
Basically, all the processor bus cycles consist of at least four clock cycles.
These are referred to as T1, T2, T3, T4. The address is transmitted by the
processor during T1. It is present on the bus only for one cycle.
The negative edge of this ALE pulse is used to separate the address and
the data or status information. In maximum mode, the status lines S0, S1
and S2 are used to indicate the type of operation.
Status bits S3 to S7 are multiplexed with higher order address bits and the
BHE signal.
Address is valid during T1 while status bits S3 to S7 are valid during T2
through T4.
General Bus cycle for 8086:
Hold Response sequence:
The HOLD pin is checked at leading edge of each clock pulse. If it is
received active by the processor before T4 of the previous cycle or during
T1 state of the current cycle, the CPU activates HLDA in the next clock
cycle and for succeeding bus cycles, the bus will be given to another
requesting master.
The control of the bus is not regained by the processor until the requesting
master does not drop the HOLD pin low.
83
84
85
Pentium Processor:
86
Pin Diagram
Parity check (PCHK#)
Indicates the parity check result on data read
Parity is checked only for valid bytes
Parity enable (PEN#) - Determines whether parity check should be used
Address parity (AP) - Bad address parity during inquire cycles
Memory/IO (M/IO#) - Defines bus cycle: memory or I/O
Write/Read (W/R#) - Distinguishes between write and read cycles
Data/Code (D/C#) - Distinguishes between data and code
Cache ability (CACHE#)
Read cycle: indicates internal cache ability
Write cycle: burst write-back
Bus lock (LOCK#)
Used in read-modify-write cycle
Useful in implementing semaphores
Interrupt (INTR) - External interrupt signal
Nonmaskable interrupt (NMI) - External NMI signal
Clock (CLK) - System clock signal
Bus ready (BRDY#)
Used to extend the bus cycle
» Introduces wait states
Bus request (BREQ) - Used in bus arbitration
Back off (BOFF#)
Aborts all pending bus cycles and floats the bus
Useful to resolve deadlock between two bus masters
Bus hold (HOLD)
Completes outstanding bus cycles and floats bus
87
Control registers
(E)IP
Program counter
88
(E) FLAGS
Status flags
– Record status information about the result of the last arithmetic/logical
instruction
Direction flag
– Forward/backward direction for data copy
System flags
– IF : interrupt enable
– TF : Trap flag (useful in single-stepping)
Segment register
Six 16-bit registers
Support segmented memory architecture
At any time, only six segments are accessible
Segments contain distinct contents
Code
Data
Stack
89
PART A
1. List the Four Display Modes of 8279 Keyboard / Display Controller. [Nov /
Dec 2012]
Eight 8 bit Character Left Entry
Sixteen 8 bit Character Left Entry
Eight 8 bit Character Right Entry
Sixteen 8 bit Character Right Entry
4. What is the need for de-bouncing the key board? [Nov/Dec 2012, Nov/Dec
2013, Nov/Dec 2014]
Denouncing the key board is used to identify the valid key. When key is depressed
and released, the contact is not broken permanently. Infact the key makes and
breaks the contacts several times for a few milliseconds before the contact is
broken permanently
90
BSR functions. If bit D7 = 1, bits D6 –D0 determine I/O functions in various modes.
If Bit D7 = 0 port C operates in BSR mode.
10. Give the various modes and applications of 8254 timer? [Apr/May 2015]
Mode 0 Interrupt on Terminal Count - to control parking lot Signs around electronic
factory.
Accurate time delay under software control
Mode 1 Programmable One Shot –To produce an interrupt signal if the ac power
fails.
Mode 2 Rate Generator – to produce a 1 KHz signal for a real time clock from an 8
MHz processor clock signal. Real time Clock interrupt
Mode 3 Square Wave Generator - Programmable audio tone generator
Mode 4 Software Triggered Strobe - Parallel Data Transfer and send out a strobe
signal to let the receiving system know that the data is available
Mode 5 Hardware Triggered Strobe - Parallel Data Transfer.
91
12. What frequency transmit clock is required by and 8251 in order for it to
transmit data at 4800 baud with a baud rate factor of 16? [Nov/Dec 2015]
Txc frequency=Baud rate*16
=4800*16=76,800Hz
13. List the advantages and disadvantages of parallel communication over
serial communication.[May/Jun 2016]
PART B
92
The 8255 chip is also called as Programmable Peripheral Interface. The Intel 8255A
is a general purpose programmable I/O device which is designed for use with all Intel
and most other microprocessors. It has 3 I/O ports, Port A, Port B and Port C each of
8 bits. The eight bits of Port C is divided into two 4 bit ports. Cupper (CU) and C lower
(CL).
8255 contains two modes of operation Bit Set/Reset Mode (BSR) and I/O Mode
BSR Mode is used to set or reset the bits in port C which is used for hand shake
signals.
Port A
Port C
8255
Port B
]Mode 0 Operation (Simple input/output) it does not use any handshake signals. All
the ports are used for simple data transfer.
Mode 1 Operation (Handshake mode) Port A and B are used for data transfer and
Port C is used for hand shake signals.
Mode 2 (Bidirectional Data Transfer) Port A is used for Bidirectional data transfer.
Port B in either in mode 0 or 1. Port C is used for Handshake signals
93
CS Chip Select. A "low" on this input pin enables the communication between the
8255 and the CPU.
RD Read: This control signal enables the read operation. A "low" on this input pin
enables 8255 to read data from the selected I/O.
WR Write: This control signal enables the write operation. A "low" on this input pin
enables 8255 to write a data into the selected I/O or control register.
94
A0 and A1: These input signals, in conjunction with the RD and WR inputs, control
the selection of one of the three ports or the control word register. They are normally
connected to the least significant bits of the address bus (A0 and A1).
RESET: A "high" on this input clears the control register and all ports (A, B, C) are
set to the input mode.
A1 A0 SELECTION
0 0 PORT A
0 1 PORT B
1 0 PORT C
1 1 CONTROL
95
information such as "mode", "bit set", "bit reset", etc., that initializes the functional
configuration of the 8255. Each of the Control blocks (Group A and Group B) accepts
"commands" from the Read/Write Control logic, receives "control words" from the
internal data bus and issues the proper commands to its associated ports.
PORTS A, B, AND C
The 8255 contains three 8-bit ports (A, B, and C).
Port A: This has an 8 bit latched/buffered O/P and 8 bit input latch. It can be
programmed in 3 modes – mode 0, mode 1, and mode 2
Port B: This has an 8 bit latched / buffered O/P and 8 bit input latch. It can be
programmed in mode 0, mode1.
Port C: This has an 8 bit latched input buffer and 8 bit output latched/buffer. This
port can be divided into two 4 bit ports and can be used as control signals for port A
and port B. it can be programmed in mode 0.
Control Word Register
The content of the control register specify an I/O function for each port. This register
can be accessed to write word when A0 and A1 are at logic 1. This register is not
accessible for read operation. Bit D7 specifies either the I/O function or the BSR
functions. If bit D7 = 1, bits D6 –D0 determine I/O functions in various modes. If Bit D7
= 0 port C operates in BSR mode.
Modes of Operation
These are two basic modes of operation of 8255. Bit Set/Reset Mode (BSR) and
I/O Mode
96
IBF:
INTR:
INTEB
PC2 STBB Interrupt request is an output signal
that requests an interrupts.
INTE:
PC1 IBFB
The interrupt enable signal is an
internal flip flop used to enable or
disable the generation of INTR
INTRB signal.
PC3
PC7, PC6:
PORT B I/P PB7 – PB0
The port C pins 7 and 6 are general
PC 6,7
purpose I/O pins that are available for
I/O
any purpose.
In I/O mode, the 8255 ports work as programmable I/O ports, while in BSR mode
only port C can be used to set or reset its individual port bits.It is used to set or reset
the bits in port C which is used for hand shake signals.
The I/O mode is divided into three modes: Mode 0 (Simple input/output), Mode 1
(Handshake mode) , Mode 2 (Bidirectional Data Transfer)
Mode 0 Operation (Simple input/output) it does not use any handshake signals. All
the ports are used for simple data transfer. It is used for interfacing an i/p device or
an o/p device. It is used when timing characteristics of I/O devices is well known.
Mode 1 Operation (Handshake mode) Port A and B are used for data transfer and
Port C is used for hand shake signals. 3 lines are used for handshaking. It is used for
97
interfacing an input device or an output device. Handshake signals of the port inform
the processor that the data is available, data transfer complete etc.
INTRA
PC3 ACK:
An input from a peripheral device
that must output a low when the
peripheral receives a data.
INTEB
OBFB INTR:
PC2
Interrupt request is an output signal
that can be used to interrupt the MPU
to request the next data byte for
PC1 ACKB
output.
INTE:
INTRB The interrupt enable signal is an
PC3
internal flip flop used to enable or
disable the generation of INTR
PORTB BO/P
PORT I/P PB7 – PB0 signal.
PC 4,5 I/O
PC5, PC4:
The port C pins 5 and 4 are general-
purpose I/O pins that are available for
any purpose.
Port A is used for Bidirectional data transfer. Port B in either in mode 0 or 1. Port C is
used for Handshake signals .This functional configuration provides a means for
communicating with a peripheral device or structure on a single 8-bit bus for both
transmitting and receiving data (bidirectional bus I/O). “Handshaking” signals are
provided to maintain proper bus flow.
INTR: Interrupt request is an output signal that can be used to interrupt the MPU
to request the next data byte for output.
98
OBF: Output Buffer Full is an output indicating that that output buffer contains
data for the bi-directional bus.
ACK: An input from a peripheral device that must output a low when the
peripheral receives a data.
STB: The strobe input loads data into the port A latch.
PA0-PA7 PORT A
PC4 STB
PC5 IBF
PC3 INTR
PC7 OBF
PC6 ACK
I/O
PC0 – PC2
PORT B
IBF: Input buffer full is an output signal indicating that the input latch contains
information for the external bi-directional bus.
INTE: The interrupt enable signal is an internal flip flop used to enable or disable
the generation of INTR signal.
PC2, PC1, and PC0: These port C pins are general-purpose I/O pins that are
available for any purpose.
Explain the 8251 USART with neat block diagram. Also explain its mode
word, command word and status word. (16) [Nov/Dec 2011]
Draw the block diagram and explain the operations of 8251 serial
communication interface[Nov/Dec 2015]
99
a) Simplex Mode: Data is transmitted only in one direction from the transmitter to
the receiver over a single communication channel.
b) Half Duplex Mode: Data transmission may take place in either direction, but at a
time data may be transmitted only in one direction.
c) Full Duplex Mode: Data transmission may take place in both directions
simultaneously.
100
Transmission Rate:
Bits per second: Number of bits transmitted per second.
Baud rate: It is a measurement of transmission speed in asynchronous
communication, it represents the number of bits/sec that are actually being sent over
the serial link.
ARCHITECTURE OF 8251A
Data Bus Buffer: This tri-state, bi-directional, 8-bit buffer is used to interface 8251
to the system data bus. Along with the data, control word, command words and
status information are also transferred through the Data Bus Buffer.
Read/Write Control Logic: This functional block accepts inputs from the system
control bus and generates control signals for overall device operation. It decodes
control signals on the control bus into signals which controls the internal and external
I/O bus. It contains the control word register and command word register that stores
the various controls formats for the device functional definition.
Transmit Buffer: The transmit buffer accepts parallel data from the CPU, adds the
appropriate framing information, serializes it, and transmits it on the TxD pin on the
falling edge of TxC. It has two registers: A buffer register to hold eight bits and an
output register to convert eight bits into a stream of serial bits. The CPU writes a
byte in the buffer register, which is transferred to the output register when it is empty.
The output register then transmits serial data on the TxD pin.
In the asynchronous mode the transmitter always adds START bit; depending
on how the unit is programmed, it also adds an optional even or odd parity bit, and
either 1,11/2, or 2 STOP bits. In synchronous mode no extra bits (other than parity, if
enable) are generated by the transmitter.
Transmit Control
TxRDY (Transmit Ready): This output signal indicates CPU that buffer register is
empty and the USART is ready to accept a data character. It can be used as an
interrupt to the system or, for polled operation, the CPU can check TxRDY using the
status read operation. This signal is reset when a data byte is loaded into the buffer
register.
TxE (Transmitter Empty): This is an output signal. A high on this line indicates that
the output buffer is empty. In the synchronous mode, if the CPU has failed to load a
new character in time, TxE will go high momentarily as SYN characters are loaded
into the transmitter to fill the gap in transmission.
TxC (Transmitter Clock): This clock controls the rate at which characters are
transmitted by USART. In the synchronous mode TxC is equivalent to the baud rate,
101
and is supplied by the modem. In asynchronous mode TxC is 1, 16, or 64 times the
baud rate. The clock division is programmable. It can be programmed by writing
proper mode word in the mode set register.
Receive Buffer: The receiver accepts serial data on the RxD line converts this serial
data to parallel format, checks for bits or characters that are unique to the
communication technique and sends an “assembled” character to the CPU.
When 8251A is in the asynchronous mode and it is ready to accept a
character, it looks for a low level on the RxD line. When it receives the low level, it
assumes that it is a START bit and enables an internal counter. At a count
equivalent to one-half of a bit time, the RxD line is sampled again. If the line is still
low, a valid START bit is detected and the 8251A proceeds to assemble the
character. After successful reception of a START bit the 8251A receives data, parity
and STOP bits, and then transfers the data on the receiver input register. The data is
then transferred into the receiver buffer register.
In the synchronous mode the receiver simply receives the specified number of
data bits and transfers them to the receiver input register and then to the receiver
buffer register.
Receive Control
It manages all receiver-related activities. Along with data reception, it does
false start bit detection, parity error detection, framing error detection, sync detection
and break detection.
RxRDY (Receiver Ready):This is an output signal. It goes high (active), when the
USART has a character in the buffer register and is ready to transfer it to the CPU.
This line can be used either to indicate the status in the status register or to interrupt
the CPU. This signal is reset when a data byte from receiver buffer is read by the
CPU.
RxC (Receiver Clock):This clock controls the rate at which the character is to be
received by USART in the synchronous mode. RxC is equivalent to the baud rate,
and is supplied by the modem. In asynchronous mod RxC is 1, 16, or 64 times the
baud rate. The clock division is programmable. It can be programmed by writing
proper mode word in the mode set register.
Modem Control
The 8251 has a set of control inputs and outputs that can be used to simplify the
interface to almost any modem. It provides control circuitry for the generation of RTS
and DTR and the reception of CTS and DSR. In addition, a general purpose inverted
output and a general purpose input are provided. The output is labelled DTR and the
input is labelled DSR
102
DTR can be asserted by setting bit 2 of the command instruction; DSR can be
sensed as bit 7 of the status register. When used as a modem control signal DTR
indicates that the terminal is ready to communicate and DSR indicates that it is ready
for communication.
The receive control unit decides the receiver frequency as controlled by
theRXC input frequency. The receive control unit generates a receiver ready
(RXRDY) signal that may be used by the CPU for handshaking. This unit also
detects a break in the data string while the 8251 is in asynchronous mode. In
synchronous mode, the 8251 detects SYNC characters using SYNDET/BD pin.
Programming 8251
Prior to starting data transmission or reception the 8251 must be sent a set of control
words. This must be done after an external or internal reset. The control words are
split into two formats.
Mode Instruction Format and Command Word Format
103
The mode instruction format fixes up the baud rate, number of characters and stop
bits for transmission.
D1-D0 determines whether the USART is to operate in the synchronous (00) or
asynchronous mode. In the asynchronous mode, this field determines the division
factor for clock to decide the baud rate.
D3-D2 determines number of data bits in one character. With this 2 bit field we can
set character length from 5 bits to 8 bits.
D5-D4 controls the parity generation. The parity bit is added to the data bits only if
parity is enabled.
D7-D6 has two meanings depending on whether operation is to be in synchronous
mode or asynchronous mode. In asynchronous mode it controls the number of
STOP bits to be transmitted. In synchronous mode it decides whether to operate with
external synchronization or internal synchronization.
Status Word
The status word enables us to read the status of the device during its operation.
104
SYNDET
DSR FE OE PE TxE RxRDY TxRDY
BRKDET
TxRDY Transmitter Ready : This output signal indicates to the CPU that the internal
circuit of the transmitter is ready to accept a new character for transmission from the
CPU.
RxRDY Receiver Ready Output : This output indicates that the 8251A contains a
character to be read by the CPU.
TXE Transmitter Empty : The TXE signal can be used to indicate the end of a
transmission mode.
PE - Parity Error : At the time of transmission of data an even parity or odd parity is
inserted in the data stream. At the receiver end, if parity of the character does not
match with the predefined parity, parity error occurs.
FE - Framing Error: If valid stop bit is not detected at the end of each character
framing error occurs.
DSR - Data Set Ready : This is normally used to check if data set is ready when
communicating with a modem.
D0 – D7 : This is an 8-bit data bus used to read or write status, command word or
data from or to the 8251A.
105
C / D : (Control Word/Data): This input pin, together with RD and WR inputs, informs
the 8251A that the word on the data bus is either a data or control word/status
information. If this pin is 1, control / status is on the bus, otherwise data is on the
bus.
RD : This active-low input to 8251A is used to inform it that the CPU is reading either
data or status information from its internal registers.
WR :This is the "active low" input terminal which receives a signal for writing transmit
data and control words from the CPU into the 8251.
CLK : This input is used to generate internal device timings and is normally
connected to clock generator output. This input frequency should be at least 30
times greater than the receiver or transmitter data bit transfer rate.
RESET : A high on this input forces the 8251A into an idle state. The device will
remain idle till this input signal again goes low and a new set of control word is
written into it.
TXC (Transmitter Clock Input) : This transmitter clock input controls the rate at which
the character is to be transmitted.
TXD (Transmitted Data Output) : This output pin carries serial stream of the
transmitted data bits along with other information like start bit, stop bits and parity bit,
etc.
RXC (Receiver Clock Input) : This receiver clock input pin controls the rate at which
the character is to be received.
RXD (Receive Data Input) : This input pin of 8251A receives a composite stream of
the data to be received by 8251 A.
RxRDY (Receiver Ready Output) : This output indicates that the 8251A contains a
character to be read by the CPU.
TxRDY - Transmitter Ready : This output signal indicates to the CPU that the
internal circuit of the transmitter is ready to accept a new character for transmission
from the CPU.
DSR - Data Set Ready : This is normally used to check if data set is ready when
communicating with a modem.
106
DTR - Data Terminal Ready : This is used to indicate that the device is ready to
accept data when the 8251 is communicating with a modem.
RTS - Request to Send Data : This signal is used to communicate with a modem.
TXE- Transmitter Empty : The TXE signal can be used to indicate the end of a
transmission mode.
107
A DAC inputs a binary number and outputs an analog voltage or current signal. The
digital to analog converters converts binary numbers into their analog equivalent
voltages or currents. Several techniques are employed for digital to analog
conversion.
Binary Analog
input DAC Output
Basic Concepts
For a 3 bit D/A Converter it has 3 digital input D2, D1 and Do and one output analog
signal. The three input lines can assume eight (23 = 8) input combinations from 000
to 111. D2 is MSB and D0 is LSB. If the input ranges from 0 to 1V it can be divided
into eight equal parts(1/8 V) each successive input is 1/8 V higher than the previous
combinations as shown in the graph below.
The 3 bit D/A converter has eight possible combinations. If a converter has n input
lines it can have 2n input combinations.
Characteristics:
Resolution: It is a change in analog output for one LSB change in digital input.
It is given by(1/2n )*Vref. If n=8 (i.e.8-bit DAC)1/256*5V=39.06mV
Settling Time: It is the time required for the DAC to settle for a full scale code
change.
If the full scale analog voltage is 1 V, the smallest unit or the LSB 001 is equivalent
to 1/2n of 1V. This is defined as resolution.
The DAC find applications in areas like digitally controlled gains, motor speed
108
control, programmable gain amplifiers, digital voltmeters, panel meters, etc. D/A
converter have many applications besides those where they are used with a
microcomputer. In a compact disk audio player for example a 14or16bit D/A
converter is used to convert the binary data read off the disk by a laser to an analog
audio signal. Most speech synthesizer integrated circuits contain a D/A converter to
convert stored binary data words into analog audio signals.
IT
R1 = 2K IT
D2
I1
R2 = 4K Io
D1
I2
R3 = 8K
D0
I3
Io = IT =I1 + I2 + I3
= Vin /R1 +Vin /R2 + Vin /R3
= Vin /1 K(½ + ¼ + 1/8)
= 0.875 mA.
109
Vo = - Rf IT
= - (1 K ) (0.875)
= - 0.875 V
= |7/8 V|
It shows that for the input 111, the output is equal to either 7/8 mA or 7/7 V
representing the D/A conversion process. The diagram is redrawn as shown below,
where the input voltage Vin is replaced by Vref, which can be turned On or OFF by the
switches.
Rf
4k 8k
2K
Vref A1 A2 A3 A4 A5 A6 A7 A
Io 8
R 2 4 8 16 32 64 128 256
where A1 to A8 can be 0 or 1
The R-2R ladder DAC, which is a binary weighted DAC that uses a repeating
cascaded structure of resistor values R and 2R. This improves the precision due to
the relative ease of producing equal valued matched resistors (or current sources).
However, wide converters perform slowly due to increasingly large RC-constants for
each added R-2R link.
110
DAC0800
The digital inputs are converted to current Iout, and by connecting a resistor to the Iout
pin, the output is converted to voltage. The total current Iout is a function of the binary
numbers at the B0-B7
inputs of the DAC0808 and the reference current Iref , and it is given by:
D D D D D D D D
I ref 7 6 5 4 3 2 1 0
2 4 8 16 32 64 128 256
Usually reference current is 2mA. Ideally we connect the output pin to a resistor,
convert this current to voltage, and monitor the output on the scope. But this can
111
When chip select of DAC is enabled then DAC will convert digital input value given
through portliness PA0-PA7 to analog value. The analog output from DAC is a
current quantity. This current is converted to voltage using OPAMP based current-to-
voltage converter. The Output of DAC-0800 is fed to the operational amplifier to get
the final output.
Analog Binary
Input Output
ADC
An ADC inputs an analog electrical signal such as voltage or current and outputs a
binary number. The function of an A/D converter is to produce a digital word which
represents the magnitude of some analog voltage or current. The specifications for
an A/D converter are very similar to those for D/A converter. The resolution of an A/D
converter refers to the number of bits in the output binary word. An 8-bit converter for
112
example has a resolution of 1 part in 256. Accuracy and linearity specifications have
the same meaning for an A/D converter as they do for a D/A converter. Another
important specification for an ADC is its conversion time. This is defined as total
time required to convert analog signal into its digital output and is determined by the
conversion technique used and by the propagation delay in various circuits.
0 1 1 1
Test
Test
Test
Test
OFF
ON
ON
ON
D3 D2 D1 D0
The analog to digital converter chips 0808 and 0809 are 8-bit CMOS,
successive approximation converters. Successive approximation technique isone of
the fast techniques for analog to digital conversion.
113
Data
CLK Ready
Output
Register
Analog
Reference
D3 D2 D1 D0
114
Port C upper acts as the input port to receive the EOC signal while port C lower
acts as the output port to send SOC to the ADC.
115
A dual-slope ADC (DS-ADC) integrates an unknown input voltage (VIN) for a fixed
amount of time (TINT), then "de-integrates" (TDE- INT) using a known reference voltage
(VREF) for a variable amount of time.
At t<0, S1 is set to ground, S2 is closed, and counter=0.
At t=0 a conversion begins and S2is open, and S1is set so the input to the
integrator is Vin.
S1is held for TINT which is a constant predetermined time interval.
When S1is set the counter begins to count clock pulses, the counter resets to
zero after TINT
Vout of integrator at t = TINT is VIN TINT/RC is linearly proportional to VIN
At t = TINT S1is set so Vref is the input to the integrator which has the voltage VIN
TINT /RC stored in it.
The integrator voltage then drops linearly with a slope -Vref/RC.
A comparator is used to determine when the output voltage of the integrator
crosses zero
When it is zero the digitized output value is the state of the counter.
116
The data bus buffer is bidirectional, 8-bit buffer and is used to interface the 8253 to
the system data bus. Data is transmitted or received by the buffer. The data bus
buffer has three basic functions, (i) Programming the modes of 8253. (ii) Loading the
count value in times (iii) Reading the count value from timers. The data bus buffer is
connected to µΡ which are also bidirectional. The data transfer is through these
pins.
It accepts inputs for the system control bus and in turn generate the control signals
for overall device operation.
CS : The chip select input is used to enable the communication between 8253 and
the microprocessor by means of data bus. A low on CS enables the data bus
buffers, while a high disables the buffer
117
RD &WR: The read (RD ) and write (WR) pins control the direction of data transfer
on the 8-bit bus. When the RD input pin is low. The CPU is inputting data from 8253
in the form of counter value. When WR pins is low, and then CPU is sending data to
8253 in the form of mode information or loading counters. The RD &WR should not
both be low simultaneously. When RD & WR pins are HIGH, the data bus buffer is
disabled.
A0 & A1: These two input lines are used for counter selection along with the CS pin.
A0 A1 Selected
0 0 Counter 0
0 1 Counter 1
1 0 Counter 2
1 1 Control Register
Counters: Each counter has three pins associated with it. They are CLK (CLK) the
gate (GATE) and the output (OUT).
CLK: Counters operate at the negative edge (1 to 0) of this clock input. If the signal
on this pin is generated by a fixed frequency oscillator then the user has
implemented a standard timer. If the input signal is a string of randomly occurring
pulses, then it is an implementation of a counter.
GATE: The gate input pin is used to initiate or enable counting. The exact effect of
the gate signal depends on which of the six modes of operation is chosen.
OUTPUT: The output pin provides an output from the timer. It actual use depends on
the mode of operation of the timer. The counter can be read “in the fly” without
inhibiting gate pulse or clock input.
118
M2 M1 M0
Mode
0 0 0
0
Mode
0 0 1
1
Mode
x 1 0
2
Mode
x 1 1
3
Mode
1 0 0
4
Mode
1 0 1
5
8253 OPERATING MODES
Mode 0 Interrupt on Terminal Count
Mode 1 Programmable One Shot
Mode 2 Rate Generator
Mode 3 Square Wave Generator
Mode 4 Software Triggered Strobe
Mode 5 Hardware Triggered Strobe
119
In this mode it operates as a rate generator. The output goes high for a period that
equals the time of countdown of the count register (3 in this case). The output goes
low exactly for one clock period before it becomes high again. This is a periodic
operation.
120
countdown period of the counter register. The output subsequently goes low for an
equal period and hence generates a symmetrical square wave unlike Mode 2. The
GATE has no role here.
In this mode after the count is loaded by the processor the countdown starts. The
output goes low for one clock period after the countdown is complete. The
countdown can be suspended by making the GATE low This is also called a
software triggered strobe as the countdown is initiated by a program.
Watchdog timer
A Watchdog Timer is a circuit that automatically invokes a reset unless the system
being watched sends regular hold-off signals to the Watchdog.
121
Draw the block diagram of 8279 keyboard/ Display controller and explain
hoe to interface the Hex Key pad and 7- segment LEDs using 8279. (16
Marks) [April/May 2010]
Draw the block diagram of a keyboard display controller and explain(8)
[Nov/Dec 2014].
122
If the data read from columns is D3 – D0 =1111, no key has been pressed and
the process continues till key press is detected
If one of the column bits has a zero, this means that a key press has occurred
For example, if D3 – D0 = 1101, this means that a key in the D1 column has
been pressed After detecting a key press, microprocessor will go through the
process of identifying the key
Starting with the top row, the microprocessor grounds it by providing a low to
row D0 only. It reads the columns, if the data read is all 1s, no key in that row is
activated and the process is moved to the next row
It grounds the next row, reads the columns, and checks for any zero. This
process continues until the row is identified.
After the key press detection, it waits 20ms for the key debounce and then
scans the columns again
(a) It ensures that the first key press detection was not an erroneous one due
a spike noise
(b) The key press. If after the 20-ms delay the key is still pressed, it goes back
into the loop to detect a real key press
Upon finding the zero, it pulls out the ASCII code for that key from the look-up
table otherwise, it increments the pointer to point to the next element of the
look-up table
With the interrupt method the microcomputer doesn‟t have to pay any attention to the
keyboard until it receives an interrupt signal.
Modes of Operation
Two-Key Rollover. This means that if two keys are pressed at nearly the
same time, each key will be detected, debounced and converted to ASCII.
The ASCII code for the first key and a strobe signal for it will be sent out then
the ASCII code for the second key and a strobe signal for it will be sent out
and compare this with two-key lockout.
2-Key Lockout Mechanism, one key must be released before the other key
is detected.
N-Key Rollover Mode, if two keys are pressed almost simultaneously, both
key presses are detected and are placed in a queue
ARCHITECTURE OF 8279
123
enabled only if CS is low. The pins A0, RD and WR select the command, status or
data read/write operations carried out by the CPU with 8279.
Scan Counter :
The scan counter has two modes to scan the key matrix and refresh the display. In
the encoded mode, the counter provides binary count that is to be externally
decoded to provide the scan lines for keyboard and display (Four externally decoded
scan lines may drive upto 16 displays). In the decode scan mode, the counter
internally decodes the least significant 2 bits and provides a decoded 1 out of 4 scan
124
on SL 0-SL 3( Four internally decoded scan lines may drive upto 4 displays). The
keyboard and display both are in the same mode at a time.
3. Strobed Input :
In this mode, if the control line goes low, the data on return lines, is stored in the
FIFO byte by byte.
125
DISPLAY MODES
There are various options of data display The first one is known as left entry mode or
type writer mode. Since in a type writer the first character typed appears at the left-
most position, while the subsequent characters appears successively to the right of
the first one. The other display format is known as right entry mode, or calculator
mode, since the calculator the first character entered appears at the right-most
position and this character is shifted one position left when the next character is
entered.
1. Left Entry Mode
In the Left entry mode, the data is entered from the left side of the display unit.
Address0 of the display RAM contains the leftmost display character and address 15
of the RAM contains the rightmost display character.
126
All the command words or status words are written or read with A0 = 1 and CS = 0 to
or from 8279. This section describes the various command available in 8279.
a) Keyboard Display Mode Set – The format of the command word to select
different modes of operation of 8279 is given below with its bit definitions.
D7 D6 D5 D4 D3 D2 D1 D0
0 0 0 D D K K K
D D Display Modes K K K Keyboard Modes
Eight 8 bit Character Left Encoded Scan 2 Key
0 0 0 0 0
Entry Lockout
Sixteen 8 bit Character Left Decoded Scan 2 Key
0 1 0 1 0
Entry Lockout
Eight 8 bit Character Right Encoded Scan N Key Roll
1 0 0 1 0
Entry Over
Sixteen 8 bit Character Right Decoded Scan N Key Roll
1 1 0 1 1
Entry Over
Encoded Scan Sensor
1 0 0
Matrix
Decoded Scan Sensor
1 1 0
Matrix
Strobed input Encoded
1 1 0
Scan
Strobed input Decoded
1 1 1
Scan
D7 D6 D5 D4 D3 D2 D1 D0
0 1 0 AI X A A A
AI – Auto increment
AAA – Address pointer to 8 bit FIFO RAM
127
D7 D6 D5 D4 D3 D2 D1 D0
0 1 1 AI A A A A
D7 D6 D5 D4 D3 D2 D1 D0
1 0 0 AI A A A A
SIGNALS OF 8279
DB0-DB7 : These are bidirectional data bus lines. The data and command words to
and from the CPU are transferred on these lines.
128
CLK : This is a clock input used to generate internal timing required by 8279.
RESET : This pin is used to reset 8279. A high on this line reset 8279. After resetting
8279, its in sixteen 8-bit display, left entry encoded scan, 2-key lock out mode. The
clock prescaler is set to 31.
CS : Chip Select – A low on this line enables 8279 for normal read or write
operations.
RD, WR(Input/Output ) READ/WRITE – These input pins enable the data buffers to
receive or send data over the data bus.
IRQ : This interrupt output lines goes high when there is a data in the FIFO sensor
RAM. The interrupt lines goes low with each FIFO RAM read operation but if the
FIFO RAM further contains any key-code entry to be read by the CPU, this pin again
goes high to generate an interrupt to the CPU.
Vss, Vcc : These are the ground and power supply lines for the circuit.
SL0-SL3-Scan Lines : These lines are used to scan the key board matrix and
display digits. These lines can be programmed as encoded or decoded, using the
mode control register.
RL0 - RL7 - Return Lines : These are the input lines which are connected to one
terminal of keys, while the other terminal of the keys are connected to the decoded
scan lines. These are normally high, but pulled low when a key is pressed.
SHIFT : The status of the shift input lines is stored along with each key code in FIFO,
in scanned keyboard mode. It is pulled up internally to keep it high, till it is pulled low
with a key closure.
BD – Blank Display : This output pin is used to blank the display during digit
switching or by a blanking closure.
OUT A0 – OUT A3 and OUT B0 – OUT B3 – These are the output ports for two
16*4 or 16*8 internal display refresh registers. The data from these lines is
synchronized with the scan lines to scan the display and keyboard. The two 4-bit
ports may also as one 8-bit port.
129
Draw the block diagram of 8259A and explain how to program 8259A. (8
Marks) [April/May 2010]
Describe the block diagram of 8259 Programmable Interrupt Controller and
its priority modes. (16) [Nov/Dec 2011]
Draw the block diagram of Programmable Interrupt Controller & explain in
its operation. [Nov/Dec 2015]
Programmable interrupt controller 8259A which is able to handle a number of
interrupts at a time. This controller takes care of a number of simultaneously
appearing interrupt requests along with their types and priorities. This will reduce the
processor burden of handling interrupts. The 8259 A interrupt controller can
ARCHITECTURE OF 8259
Data Bus Buffer
This tristate bidirectional buffer interfaces internal 8259A bus to the microprocessor
system data bus. Control words, status and vector information pass through buffer
during read or write operations.
130
Priority Resolver
This unit determines the priorities of the interrupt requests appearing simultaneously.
The highest priority is selected and stored into the corresponding bit of ISR during
INTA pulse. The IR0 has the highest priority while the IR7 has the lowest one
Control Logic
This block manages the interrupt and interrupt acknowledge signals to be sent to the
CPU for serving one of the eight interrupt requests. This also accepts interrupt
acknowledge (INTA) signal from CPU that causes the 8259A to release vector
address on to the data bus.
Cascade Buffer/Comparator
This block stores and compares the ID's of all the 8259As used in the system. The
three I/O pins CAS0-2 are outputs when the 8259A is used as a master. The same
pins acts as input when 8259 is in slave mode.
131
CS: This is an active low chip select signal for enabling RD and WR operations of
8259A.
WR: This pin is an active low write enable input to 8259A. This enables it to accept
command words from CPU.
RD: This is an active low read enable input to 8259A. A low on this line enables
8259A to release status onto the data bus of CPU.
D7-D0: These pins form a bidirectional data bus that carries 8-bit data either to
control word or from status word registers. This also carries interrupt vector
information.
PS*/EN*: This pin is a dual purpose pin. When the chip is used in buffered mode, it
can be used as buffer enable to control buffer transceivers. If this is not used in
buffered mode then the pin is used as input.
INT This pin goes high whenever a valid interrupt request is asserted. This is used to
interrupt the CPU and is connected to the interrupt input of CPU.
132
The SNGL bit in ICW1 indicates whether the 8259A in the cascade mode or not. ADI
refers the interval of call address. LTIM refers whether it is edge triggered or level
triggered.
133
In 8086 based system A15-A11 of the interrupt vector address are inserted in place of
T7 – T3 respectively and the remaining three bits A8, A9, A10 are selected depending
upon the interrupt level, i.e. from 000 to 111 for IR0 to IR7.
A0 D7 D6 D5 D4 D3 D2 D1 D0
1 0 0 0 SFNM BUF M/S AEOI µPM
SFNM: If BUF = 1, the buffered mode is selected. In the buffered mode, SP/EN acts
as enable output and the master/slave is determined using the M/S bit of ICW 4.
M/S: If M/S = 1, 8259A is a master. If M/S =0, 8259A is slave. If BUF = 0, M/S is to
be neglected.
AEOI: If AEOI = 1, the automatic end of interrupt mode is selected.
µPM : If the µPM bit is 0, the Mcs-85 system operation is selected and if µPM=1,
8086/88 operation is selected.
134
A0 D7 D6 D5 D4 D3 D2 D1 D0
1 M7 M6 M5 M4 M3 M2 M1 M0
R SL EOI
End of 0 0 1 Non Specific EOI Command
Interrupt 0 1 1 Specific EOI Command
Rotate on Non Specific EOI
1 0 1
Command
Automatic
1 0 0 Rotate in Automatic EOI mode(Set)
Rotation
Rotate in Automatic EOI
0 0 0
mode(Clear)
1 1 1 Rotate on Specific EOI Command
Specific
1 1 0 Set priority Command
Rotation
0 1 0 No operation
135
A0 D7 D6 D5 D4 D3 D2 D1 D0
0 0 ESMM SMM 0 1 P RR RIS
In operation command word 3 (OCW 3), if the ESMM bit, i.e. enable special mask
mode bit is set to 1, the SMM bit is enabled to select or mask the special mask
mode. When ESMM bit is 0 the SMM bit is neglected. If the SMM bit .i.e. special
mask mode bit is 1, the 8259A will enter special mask mode provided ESMM=1. If
ESMM=1 and SMM=0, the 8259A will return to the normal mask mode.
Fully Nested Mode : This is the default mode of operation of 8259A. IR 0 has the
highest priority and IR7 has the lowest one. When interrupt request are noticed, the
highest priority request among them is determined and the vector is placed on the
data bus. The corresponding bit of ISR is set and remains set till the microprocessor
issues an EOI command just before returning from the service routine or the AEOI
bit is set. If the ISR ( in service ) bit is set, all the same or lower priority interrupts are
inhibited but higher levels will generate an interrupt, that will be acknowledge only if
the microprocessor interrupt enable flag IF is set. The priorities can afterwards be
changed by programming the rotating priority modes.
End of Interrupt (EOI) : The ISR bit can be reset either with AEOI bit of ICW1 or by
EOI command, issued before returning from the interrupt service routine. There are
two types of EOI commands specific and non-specific. When 8259A is operated in
the modes that preserve fully nested structure, it can determine which ISR bit is to be
reset on EOI. When non-specific EOI command is issued to 8259A it will be
automatically reset the highest ISR bit out of those already set.
Automatic Rotation : This is used in the applications where all the interrupting
devices are of equal priority. In this mode, an interrupt request IR level receives
136
priority after it is served while the next device to be served gets the highest priority in
sequence. Once all the devices are served like this, the first device again receives
highest priority.
Automatic EOI Mode : Till AEOI=1 in ICW 4, the 8259A operates in AEOI mode. In
this mode, the 8259A performs a non-specific EOI operation at the trailing edge of
the last INTA pulse automatically. This mode should be used only when a nested
multilevel interrupt structure is not required with a single 8259A.
Specific Rotation : In this mode a bottom priority level can be selected, using L2, L1
and L0 in OCW 2 and R=1, SL=1, EOI=0. The selected bottom priority fixes other
priorities. If IR 5 is selected as a bottom priority, then IR 5 will have least priority and
IR4 will have a next higher priority. Thus IR 6 will have the highest priority. These
priorities can be changed during an EOI command by programming the rotate on
specific EOI command in OCW2.
Specific Mask Mode: In specific mask mode, when a mask bit is set in OCW1, it
inhibits further interrupts at that level and enables interrupt from other levels, which
are not masked.
Edge and Level Triggered Mode : This mode decides whether the interrupt should
be edge triggered or level triggered. If bit LTIM of ICW1 =0 they are edge triggered,
otherwise the interrupts are level triggered.
The status of the internal registers of 8259A can be read using this mode. The OCW
3 is used to read IRR and ISR while OCW1 is used to read IMR. Reading is possible
only in no polled mode.
Poll Command : In polled mode of operation, the INT output of 8259A is neglected,
though it functions normally, by not connecting INT output or by masking INT input of
the microprocessor. The poll mode is entered by setting P=1 in OCW3. The 8259A is
polled by using software execution by microprocessor instead of the requests on INT
input. The 8259A treats the next RD pulse to the 8259A as an interrupt
acknowledge. An appropriate ISR bit is set, if there is a request. The priority level is
read and a data word is placed on to data bus, after RD is activated. A poll command
may give more than 64 priority levels.
Special Fully Nested Mode : This mode is used in more complicated system, where
cascading is used and the priority has to be programmed in the master using ICW 4.
this is somewhat similar to the normal nested mode. • In this mode, when an
interrupt request from a certain slave is in service, this slave can further send
request to the master, if the requesting device connected to the slave has higher
137
priority than the one being currently served. In this mode, the master interrupt the
CPU only when the interrupting device has a higher or the same priority than the one
current being served. In normal mode, other requests than the one being served are
masked out. When entering the interrupt service routine the software has to check
whether this is the only request from the slave. This is done by sending a non-
specific EOI can be sent to the master, otherwise no EOI should be sent. This mode
is important, since in the absence of this mode, the slave would interrupt the master
only once and hence the priorities of the slave inputs would have been disturbed.
Buffered Mode: When the 83259A is used in the systems where bus driving buffers
are used on data buses. The problem of enabling the buffers exists. The 8259A
sends buffer enable signal on SP/ EN pin, whenever data is placed on the bus.
Cascade Mode : The 8259A can be connected in a system containing one master
and eight slaves (maximum) to handle upto 64 priority levels. The master controls
the slaves using CAS 0-CAS 2 which act as chip select inputs (encoded) for slaves.
In this mode, the slave INT outputs are connected with master IR inputs. When a
slave request line is activated and acknowledged, the master will enable the slave to
release the vector address during second pulse of INTA sequence.
The Direct Memory Access or DMA mode of data transfer is the fastest among all
the modes of data transfer. In this mode, the device may transfer data directly
to/from memory without any interference from the CPU. The device requests the
CPU (through a DMA controller) to hold its data, address and control bus, so that the
device may transfer data directly to/from memory. The DMA data transfer is initiated
only after receiving HLDA signal from the CPU.
Intel‟s 8257 is a four channel DMA controller designed to be interfaced with their
family of microprocessors. The 8257, on behalf of the devices, requests the CPU for
bus access using local bus request input i.e. HOLD in minimum mode. In maximum
138
mode of the microprocessor RQ/GT pin is used as bus request input. On receiving
the HLDA signal (in minimum mode) or RQ/GT signal (in maximum mode) from the
CPU, the requesting devices gets the access of the bus, and it completes the
required number of DMA cycles for the data transfer and then hands over the control
of the bus back to the CPU.
The chip support four DMA channels, i.e. four peripheral devices can independently
request for DMA data transfer through these channels at a time. The DMA controller
has 8-bit internal data buffer, a read/write unit, a control unit, a priority resolving unit
along with a set of registers. The chip support four DMA channels, i.e. four peripheral
devices can independently request for DMA data transfer through these channels at
a time. The DMA controller has 8-bit internal data buffer, a read/write unit, a control
unit, a priority resolving unit along with a set of registers.
139
140
memory data. The bits B0- B3 enable one of the four DMA channels of 8257. for
example, if B0 is „1‟, channel 0 is enabled.
Bit Bit
Types of DMA Operation
15 14
0 0 Verify DMA Cycle
0 1 Write DMA Cycle
1 0 Read DMA Cycle
1 1 Illegal
If B4 is set, rotating priority is enabled, otherwise, the normal, i.e. fixed priority is
enabled If the TC STOP bit is set, the selected channel is disabled after the terminal
count condition is reached, and it further prevents any DMA cycle on the channel. To
enable the channel again, this bit must be reprogrammed. If the TC STOP bit is
programmed to be zero, the channel is not disabled, even after the count reaches
zero and further request are allowed on the same channel. The auto load bit, if set,
enables channel 2 for the repeat block chaining operations, without immediate
software intervention between the two successive blocks. The channel 2 registers
are used as usual, while the channel 3 registers are used to store the block
reinitialisation parameters, i.e. the DMA starting address and terminal count. After
the first block is transferred using DMA, the channel 2 registers are reloaded with the
corresponding channel 3 registers for the next block transfer, if the update flag is set.
The extended write bit, if set to „1‟, extends the duration of MEMW and IOW signals
by activating them earlier, this is useful in interfacing the peripherals with
Status Register
The status register of 8257 is shown in figure. The lower order 4-bits of this register
contain the terminal count status for the four individual channels. If any of these bits
141
is set, it indicates that the specific channel has reached the terminal count condition.
If the update flag is set, the contents of the channel 3 registers are reloaded to the
corresponding registers of channel 2 whenever the channel 2 reaches a terminal
count condition, after transferring one block and the next block is to be transferred
using the autoload feature of 8257.
D7 D6 D5 D4 D3 D2 D1 D0
Data Bus Buffer, Read/Write Logic, Control Unit and Priority Resolver
The 8-bit. Tristate, bidirectional buffer interfaces the internal bus of 8257 with the
external system bus under the control of various control signals. In the slave mode,
the read/write logic accepts the I/O Read or I/O Write signals, decodes the Ao-A3
lines and either writes the contents of the data bus to the addressed internal register
or reads the contents of the selected register depending upon whether IOW or IOR
signal is activated. In master mode, the read/write logic generates the IOR and IOW
signals to control the data flow to or from the selected peripheral. The control logic
controls the sequences of operations and generates the required control signals like
AEN, ADSTB, MEMR, MEMW, TC and MARK along with the address lines A4-A7, in
master mode. The priority resolver resolves the priority of the four DMA channels
depending upon whether normal priority or rotating priority is programmed.
MODES OF OPERATION
Single mode
In single mode only one byte is transferred per request. For every transfer, the
counting register is decremented and address is incremented or decremented
depending on programming.
142
DRQo-DRQ3 : These are the four individual channel DMA request inputs, used by
the peripheral devices for requesting the DMA services. The DRQ o has the highest
priority while DRQ3 has the lowest one, if the fixed priority mode is selected.
DACKo-DACK3 : These are the active-low DMA acknowledge output lines which
inform the requesting peripheral that the request has been honoured and the bus is
relinquished by the CPU. These lines may act as strobe lines for the requesting
devices.
Do-D7: These are bidirectional, data lines used to interface the system bus with the
internal data bus of 8257. These lines carry command words to 8257 and status
word from 8257, in slave mode, i.e. under the control of CPU. The data over these
lines may be transferred in both the directions. When the 8257 is the bus master
(master mode, i.e. not under CPU control), it uses Do-D7 lines to send higher byte of
the generated address to the latch. This address is further latched using ADSTB
signal. the address is transferred over Do-D7 during the first clock cycle of the DMA
cycle. During the rest of the period, data is available on the data bus.
IOR: This is an active-low bidirectional tristate input line that acts as an input in the
slave mode. In slave mode, this input signal is used by the CPU to read internal
registers of 8257.this line acts output in master mode. In master mode, this signal is
used to read data from a peripheral during a memory write cycle.
IOW : This is an active low bidirection tristate line that acts as input in slave mode to
load the contents of the data bus to the 8-bit mode register or upper/lower byte of a
16-bitDMA address register or terminal count register. In the master mode, it is a
143
control output that loads the data to a peripheral during DMA memory read cycle
(write to peripheral).
CLK: This is a clock frequency input required to derive basic system timings for the
internal operation of 8257.
RESET : This active-high asynchronous input disables all the DMA channels by
clearing the mode register and tristates all the control lines.
Ao-A3: These are the four least significant address lines. In slave mode, they act as
input which select one of the registers to be read or written. In the master mode, they
are the four least significant memory address output lines generated by 8257.
CS: This is an active-low chip select line that enables the read/write operations
from/to 8257, in slave mode. In the master mode, it is automatically disabled to
prevent the chip from getting selected (by CPU) while performing the DMA operation.
A4-A7 : This is the higher nibble of the lower byte address generated by 8257 during
the master mode of DMA operation.
READY: This is an active-high asynchronous input used to stretch memory read and
write cycles of 8257 by inserting wait states. This is used while interfacing slower
peripherals..
HRQ: The hold request output requests the access of the system bus. In the
noncascaded 8257 systems, this is connected with HOLD pin of CPU. In the
cascade mode, this pin of a slave is connected with a DRQ input line of the master
8257, while that of the master is connected with HOLD input of the CPU.
HLDA : The CPU drives this input to the DMA controller high, while granting the bus
to the device. This pin is connected to the HLDA output of the CPU. This input, if
high, indicates to the DMA controller that the bus has been granted to the requesting
peripheral by the CPU.
MEMR: This active –low memory read output is used to read data from the
addressed memory locations during DMA read cycles.
MEMW : This active-low three state output is used to write data This active-low
three state output is used to write data to the addressed memory location during
DMA write operation. ADST : This output from 8257 strobes the higher byte of the
memory address generated by the DMA controller into the latches.
AEN: This output is used to disable the system data bus and the control the bus
driven by the CPU, this may be used to disable the system address and data bus by
using the enable input of the bus drivers to inhibit the non-DMA devices from
responding during DMA operations. If the 8257 is I/O mapped, this should be used to
disable the other I/O devices, when the DMA controller addresses is on the address
bus.
144
TC: Terminal count output indicates to the currently selected peripherals that the
present DMA cycle is the last for the previously programmed data block. If the TC
STOP bit in the mode set register is set, the selected channel will be disabled at the
end of the DMA cycle. The TC pin is activated when the 14-bit content of the terminal
count register of the selected channel becomes equal to zero. The lower order 14
bits of the terminal count register are to be programmed with a 14-bit equivalent of
(n-1), if n is the desired number of DMA cycles.
MARK : The modulo 128 mark output indicates to the selected peripheral that the
current DMA cycle is the 128th cycle since the previous MARK output. The mark will
be activated after each 128 cycles or integral multiples of it from the beginning if the
data block (the first DMA cycle), if the total number of the required DMA cycles (n) is
completely divisible by 128.
Vcc : This is a +5v supply pin required for operation of the circuit. GND : This is a
return line for the supply (ground pin of the IC).
Write the algorithm and assembly language program for traffic light control
system.(8) [Apr/May 2014]
Draw the block diagram of traffic light control system using 8086.(8)
[Apr/May 2015]
145
from proceeding. Usually, the red light contains some orange in its hue, and the
green light contains some blue, for the benefit of people with red-green color
blindness, and "green" lights in many areas are in fact blue lenses on a yellow light
(which together appear green).
The Traffic light controller section consists of 12 Nos. of LED‟s arranged by 4Lanes
in Traffic light interface card. Each lane has Go(Green), Listen(Yellow) and
Stop(Red) LED is being placed.
LAN 8086
MODULES
Direction LINES
PA.0 GO
SOUTH PA.1 LISTEN
PA.2 STOP
PA.3 GO
EAST PA.4 LISTEN
PA.5 STOP
PA.6 GO
NORTH PA.7 LISTEN
PB.0 STOP
PB.1 GO
WEST PB.2 LISTEN
PB.3 STOP
13-16 NC
PWR 17,19 Vcc
18,20 Gnd
146
147
MOV CX,0005H
REPEAT: MOV DX,0FFFFH
LOOP2: DEC DX
JNZ LOOP2
LOOP REPEAT
POP CX
RET
LOOKUP TABLE
1200 80H
PART – C
148
(2) Now one must connect the available memory address lines of memory
chips with those of the 8086 microprocessor and connect the memory RD and
WR inputs to the corresponding processor control signals.
(3) Connection of the 16-bit data bus of the memory bank with that of the
microprocessor 8086must be done.
149
(4) BHE, A0 and the rest of the address lines left are used for decoding the
required chip select signals forthe odd and even memory banks.
Solution:
After reset the IP and CS are initialized to for address FFFF 0H.We must first
calculate the total number of address lines required for 8K bytes of EPROM which
is 13, as we have seen earlier that we have N= 2n hence we get, 2 13 = 8K.
Decoded Map:
Address lines A13-A19 are used for decoding to generate the chip select. The BHE
signal goes low when a transfer is at odd address or higher byte of data is to be
accessed.
The memory system here contains in total four 4K X 8memory chips. The two
4K X 8 chips of RAM and ROM are arranged in parallel to obtain 16-bit data
bus width. If A0 is 0 i.e. the address is even and is in RAM, then the lower
RAM chip is selected indicating 8-bit transfer at an even address.
If A0 is 1, i.e. the address is odd and is in RAM the BHE goes low, the upper
RAM chip is\ selected, further indicating that the 8-bit transfer is at an odd
address. If the selected addresses are in ROM, the respective ROM chips are
selected. If at a time A0 and BHE both are 0, both the RAM or ROM chips
are selected i.e. the data transfer is of 16-bits.
150
2. Explain with neat diagram to interface and control the speed and
direction of a stepper motor using 8086.
Stepper Motor:
i. Instrumentation
ii. ii. Computer peripherals
iii. iii. Machine drives.
They are used in floppy drives, dot-matrix printers, X-Y plotters, digital watches
etc to rotate things in steps of small angles. The step size in typical stepper motor
varies from0.9 o to 30o.
151
After the rotation of the shaft through angle x the rotor locks itself with the next
tooth in the sequence on the internal surface of stator. The internal schematic of a
typical stepper motor with four windings is shown in Fig.
The sequence of the pulses can be decided, depending upon the required motion
of the shaft. By suitable sequence of the pulses the motor can be used in three
modes of operation.
152
153
We now want to control a stepper motor in 8086 trainer kit. It works by turning ON
& OFF a four I/O port lines generating at a particular frequency.
The 8086 trainer kit has three numbers of I/O port connectors, connected with I/O
Port lines (PA.0 – PA.7),(PB.0 – PB.7) to rotate the stepper motor. Ls293d is used
as a driver for port I/O lines, drivers output connected to stepper motor, connector
provided for external power supply if needed.
Assembly Language Program to run the Stepper Motor:
MOV AL, 80
OUT DX, AL
MOV AL, 33
ROR AL, 01
CALL DELAY
JMP LOOP
M:DEC CX
JNE M
RET
154
UNIT IV MICROCONTROLLER
Architecture of 8051– Special Function Registers (SFRs) - I/O Pins Ports and
Circuits - Instruction set-Addressing modes - Assembly language programming.
PART A
4. Give the alternate functions for the port pins of port3? [Apr/May 2011]
P3.7 P3.6 P3.5 P3.4 P3.3 P3.2 P3.1 P3.0
RD WR T1 T0 INT1 INT0 TxD RxD
155
7. Mention the number of register banks and their addresses in 8051. [Nov/Dec
15],[Nov/Dec 2011]
80 P0 90 P1
81 SP 98 SCON
82 DPL 99 SBUF
83 DPH A0 P2
87 PCON A8 IE
88 TCON B0 P3
89 TMOD B8 IP
156
8A TL0 D8 PSW
8B TL1 E0 ACC
8C TH0 F0 B
8D TH1
9.Why a latch is used for an O/P port, but a tri-state buffer can be used for an
input port? [May/June 2012]
Output port is to source large currents the port lines must be buffered. Hence
the latch acts as a good output port. So, 74LS373 contains eight buffered latches
and can be used as an 8 bit output port. An input device one must take care that
much current should not be sourced or sink from the data lines to avoid loading.
So, tristate buffer is used as input device.
Microprocessor Microcontroller
Access times for memory and I/O Less access time for built-in
devices are more. memory and I/O devices.
The difference in bytes, of the new address from the address, in the program counter
is called jump range.
157
PART B
1. ARCITECTURE OF 8051
8051 is 8-bit microcontroller; it can Read, Write and Process 8 bit data. This is
mostly used microcontroller in the robotics, home appliances likemp3 player,
washing machines, electronic iron and industries.
ALU
It is 8 bit unit. It performs arithmetic operation as addition, subtraction, multiplication,
division, increment and decrement. It performs logical operations like AND, OR and
EX-OR. It manipulates 8 bit and 16 bit data.
Accumulator
It is 8 bit register. It's address is E0H and it is bit and byte accessible. Result of
arithmetic & logic operations performed by ALU is accumulated by this register.
B-register
It is used to store one of the operands for multiply and divide instructions. It is special
8 bit maths register. It is bit and byte accessible. It is used in conjunction with A
register as I/P operand for ALU. It is used as general purpose register to store 8 bit
data.
158
PSW
It is 8 bit register. It's address is D0H and it is bit and byte accessible. It has 4
conditional flags and 3 control flags
CY AC F0 RS1 RS0 OV - P
159
Bank
RS1 RS0
Selection
0 0 Bank 0
0 1 Bank 1
1 0 Bank 2
1 0 Bank 3
Program Counter(PC):
The Program Counter (PC) is a 2-byte address which tells the 8051 where the next
instruction to execute is found in memory. When the 8051 is initialized PC always
starts at 0000 H and is incremented each time an instruction is executed.
Stack Pointer(SP):
It is 8bit register. It is byte addressable. When the data is to be placed on stack by
push instruction, the content of stack pointer is incremented by 1, and when data is
retrieved from stack, content of stack of stack pointer is decremented by 1.
P0, P1, P2, P3 (Port): This is input/output port0, port1, port2, port3. Each bit of this
SFR corresponds to one of the pins on the microcontroller. For example, bit0 of
port0 is pin P0.0, bit 7 is in P0.7.Writing a value of 1 to a bit of this SFR will send a
high level on the corresponding I/O pin where as a value of 0 will bring it to a low
level.
Serial Data Buffer: The serial data buffer internally contains two independent
registers. One of them is a transmit buffer which is necessarily a parallel in serial out
register. The other is called receive buffer which is a serial in parallel out register.
Loading a byte to the transmit buffer initiates serial transmission of that byte. The
serial buffer is identified as SBUF. If a byte is written into SBUF it initiates a serial
transmission and if the SBUF is read, it reads received serial data.
160
Timer Registers: These two 16 bit registers can be accessed as their lower and
upper bytes. It contains two timers. TL0 represents the lower byte of the timing
register, TH0 represents the higher bytes of the timer register 0. Similarly TL1 and
TH1 represent lower and higher bytes of timing register 1.
Control Registers: The special function registers IP, OE, TMOD, TCON, SCON,
and PCON contain control and status information for interrupts, timers/counters and
serial port.
Timing and Control Unit: This unit derives all the necessary timing and control
signals required for the internal operation of the circuit. It also derives the basic
timing control signals required for controlling the external system bus.
Oscillator: This circuit generates the basic timing clock signal for the operation of
the circuit using crystal oscillator.
EPROM and Program Address Register: These blocks provide on chip EPROM
and a mechanism to internally address it.
RAM and RAM Address Register: These blocks provides internal 128 bytes of
Ram and a mechanism to address it internally.
Idle Mode
A hardware reset exits the idle mode. The CPU starts from the instruction following
the instruction that invoked the 'Idle' mode.
161
The 8051 has a separate memory space for code and data. It is called as Program
memory and Data memory
Program Memory
The executable program code is stored in this code memory. The code memory size
is limited to 64Kbytes. The code memory is read only in normal operation and is
programmed under special conditions. e.g. it is a PROM or a Flash RAM type of
memory. When EA = 0, 64 K bytes is divided as 4K bytes of Internal Memory and
60 K bytes of external Memory. When EA = 1, 64 K bytes considered as external
Memory. 8051 memory is organized so that data memory and program code
memory can be two entirely different physical memory entities. Each has the same
address ranges.
EA = 0 EA = 1
162
The internal program ROM occupies code address space 0000H to 0FFFH. The PC
is normally used to address program code bytes from address 0000H to FFFFH.
Program addresses higher than OFFFH which exceed the internal ROM capacity will
cause the 8051 to automatically fetch code bytes from external memory, addresses
1000H to FFFFH by connecting the external access pin (EA) to ground
.
Data Memory
This is read write memory and is available for storage of data. Up to 64KBytes of
external
RAM data memory is supported in a standard 8051.
Internal Data Memory (00H to FFH)
Four register banks (Bank0, Bank1, Bank2 and Bank3) each of 8-bits (total 32 bytes)
are available. The default bank register is Bank0. The remaining Banks are selected
with the help of RS0 and RS1 bits of PSW Register. Each bank consists of 8
general-purpose registers R0 through R7. (R0,R1,R2,R3,R4,R5,R6, and R7)
163
The special function registers (SFRs)are mapped in the upper 128bytes of internal
data memory address. The SFR registers are located within the Internal Memory in
the address range 80H to FFH Each SFR has a very specific function. Each SFR
has an address (within the range 80H to FFH) and a name which reflects the
purpose of the SFR. The SFRs are accessed by direct addressing only. Some SFRs
are also bit addressable as is the case for the bit area of RAM. This feature allows
the programmer to change only what needs to be altered leaving the remaining bits
in that SFR unchanged. Not all of the addresses from 80H to FFH are used for
SFRs. Only the addressed ones can be used in programming SFRs and equivalent
internal RAM addresses
80 P0 90 P1
81 SP 98 SCON
82 DPL 99 SBUF
83 DPH A0 P2
87 PCON A8 IE
88 TCON B0 P3
164
89 TMOD B8 IP
8A TL0 D8 PSW
8B TL1 E0 ACC
8C TH0 F0 B
8D TH1
Draw the pin diagram of 8051 Microcontroller and explain the Input/Output
lines in detail.(16) [May/Jun 2014]
8051 microcontrollers have 4 I/O ports each comprising of 8 bits which can be
configured as inputs or outputs. Accordingly, total of 32 input/output pins enabling
the microcontroller to be connected to peripheral devices that are available for use.
Each port of 8051 has bidirectional capability. Port1, 2, 3 are called 'quasi
bidirectional port'.
Port 0 has 8 pins (P0.0-P0.7). Port 0 is called bidirectional port as it floats (tristated)
when configured as input. It can be used for address/data interfacing for accessing
external memory. When control is '1', the port is used for address/data interfacing.
When the control is '0', the port can be used as a normal bidirectional I/O port. If
external memory is used then the lower address byte (addresses A0-A7) is applied
on it. Otherwise, all bits of this port are configured as inputs/outputs.
Let us assume that control is '0'. When the port is used as an input port, '1' is written
to the latch. In this situation both the output MOSFETs are 'off'. Hence the output pin
floats. This high impedance pin can be pulled up or low by an external source. When
the port is used as an output port, a '1' written to the latch again turns 'off' both the
165
output MOSFETs and causes the output pin to float. An external pull-up is required
to output a '1'. But when '0' is written to the latch, the pin is pulled down by the lower
MOSFET. Hence the output becomes zero. When the control is '1', address/data bus
controls the output driver MOSFETs. If the address/data bus (internal) is '0', the
upper MOSFET is 'off' and the lower MOSFET is 'on'. The output becomes '0'. If the
address/data bus is '1', the upper transistor is 'on' and the lower transistor is 'off'.
Hence the output is '1'. Hence for normal address/data interfacing (for external
memory access) no pull-up resistors are required. Port-0 latch is written to with 1's
when used for external memory access.
Port 2 is used for higher external address byte or a normal input/output port. The I/O
operation is similar to Port 1. Port 2 latch remains stable when Port-2 pin are used
for external memory access. Here again due to internal pull-up there is limited
current driving capability. Port2 has 8-pins (P2.0-P2.7) Port 2 is used for higher
external address byte or a normal input/output port. The I/O operation is similar to
Port-1. Port-2 latch remains stable when Port 2 pin are used for external memory
access. Here again due to internal pull-up there is limited current driving capability.
P2 acts similarly to P0 when external memory is used. Pins of this port occupy
addresses intended for external memory chip. This time it is about the higher
address byte with addresses A8-A15.When no memory is added, this port can be
166
Port 3 has 8 pin (P3.0-P3.7). Port3 pins have alternate functions. All the port pins
can be used as general I/O, but they also have an alternative function. In order to
use these alternative functions, a logic one (1) must be applied to appropriate bit of
the P3 register. In terms of hardware, this port is similar to P0, with the difference
that its pins have a pull-up resistor built-in. Each pin of Port-3 can be individually
programmed for I/O operation or for alternate function. The alternate function can be
activated only if the corresponding latch has been written to '1'.To use the port as
input port, '1' should be written to the latch. This port also has internal pull-up and
limited current driving capability.
167
3. SIGNALS OF 8051
Draw the pin diagram of 8051 microcontroller and explain the functions of
each pin. (10) [Nov/Dec 2011]
Draw the pin diagram of 8051 Microcontroller and explain the Input/Output
lines in detail.(16) [May/Jun 2014]
Describe the functions of the following signals in 8051. RST, EA, PSEN,
ALE. (8) [Nov/Dec 15]
The 8051 microcontroller is available as a 40 pin DIP chip and it works at +5 volts
DC
168
XTAL1,XTAL2: These two pins are connected to Quartz crystal oscillator which runs
the on- chip oscillator
RST: The RESET pin is an input pin and it is an active high pin. When a high pulse is
applied to this pin the microcontroller will reset and terminate all activities.
EA: This pin is an active low pin. This pin is connected to ground when
microcontroller is accessing the program code stored in the external memory and
connected to Vcc when it is accessing the program code in the on chip memory
PSEN(Program store enable)This is an output pin which is active low. When the
microcontroller is accessing the program code stored in the external ROM ,this pin is
connected to the OE (Output Enable) pin of the ROM.
ALE (Address latch enable): This is an output pin, which is active high. When
connected to external memory , port 0 provides both address and data i.e address
and data are multiplexed through port 0 .This ALE pin will demultiplex the address
and data bus .When the pin is High , the AD bus will act as address bus otherwise
the AD bus will act as Data bus.
P0.0- P0.7(AD0-AD7) : The port 0 pins multiplexed with Address/data pins .If the
microcontroller is accessing external memory these pins will act as address/data
pins otherwise they are used for Port 0 pins.
P2.0- P2.7(A8-A15) : The port2 pins are multiplexed with the higher order address
pins .When the microcontroller is accessing external memory these pins provide the
higher order address byte otherwise they act as Port 2 pins.
P1.0- P1.7 :These 8-pins are dedicated for Port1 to perform input or output port
operations.
P3.0- P3.7 :These 8-pins are meant for Port3 operations and also for some control
operations like Read,Write,Timer0,Timer1, INT0,INT1,RxD and TxD
169
4. Branch Instructions
5. Boolean Variable Instruction
MOVA, Rn A = Rn
MOVA, direct A = (direct)
MOVA, @Ri A = @Ri
MOVA, #data A = data
MOV Rn, A Rn = A
MOV Rn, direct Rn = (direct)
MOV Rn, #data Rn = data
MOV direct, A (direct) = A
MOV direct, Rn (direct) = Rn
MOV direct1, direct2 (direct1) = (direct2)
MOV direct, @Ri (direct) = @Ri
MOV direct, #data (direct) = #data
MOV @Ri, A @Ri = A
MOV @Ri, direct @Ri = (direct)
MOV @Ri, #data @Ri = data
MOVDPTR,#data16 DPTR = data16
MOVCA,@A+DPTR A = Code byte pointed by A+DPTR
MOVCA,@A+PC A = Code byte pointed by A+PC
MOVCA, @Ri A = Code byte pointed by Ri
MOVX A, @DPTR A = External data pointed by DPTR
MOVX @Ri,A @Ri = A (Externaldata-8bitaddress)
MOVX @DPTR,A DPTR = A
PUSH direct Push (direct) to the stack
POP direct Pop (direct) from stack
XCH Rn Exchange A with Rn
Arithmetic Instructions
ADD A, Rn A = A+Rn
ADD A, direct A = A +(direct)
ADD A, @Ri A = A +@Ri
170
171
Branch Instructions
ACALL addr11 Absolute subroutine call
LCALL addr16 Long subroutine call
RET Return from subroutine
RETI Return from interrupt
AJMP addr11 Absolute jump
LJMP addr16 Long jump
SJMP Relative Address Short jump
JMP @A+DPTR Jump indirect
JZ Relative Address Jump if Zero
JNZ Relative Address Jump if Not Zero
JC Relative Address Jump if C set
JNC Relative Address Jump if C not set
JB bit,Relative Address Jump if specified bit set
JNB bit,Relative Address Jump if specified bit not set
JBC bit,Relative Address if specified bit set, clear it and jump
CJNE A,direct,rel Compare and Jump if Not Equal
CJNE A,#data,rel Compare and Jump if Not Equal
172
Write a program to bring in data in serial form and send it out in parallel form
using 8051 [April/May 2015]
5. ADDRESSING MODES
1. Register 5. Relative
2. Direct 6. Absolute
3. Indirect 7. Long
4. Immediate 8. Indexed
173
1. Register Addressing
Data is available in the register specified in the instruction.
For example, MOV A, R0
2. Direct Addressing
The address of the data is available in the instruction format.
For example MOV A, 088H; Moves content of the address 88H to Accumulator.
3. Indirect Addressing
The address of data is available in the R0 or R1 registers as specified in the
instruction.
For example- MOV A, @R0 moves content of address pointed by R0 to A.
4. Immediate Addressing
Data is immediately available in the instruction
6. Absolute Addressing
There are only two instructions that use this addressing: ACALL (absolute call)
and AJMP (absolute jump). These instructions perform branching within the
current 2K page of program memory.
7. Long Addressing
Only two instructions use this addressing mode. These instructions are
LCALLaddr16 and LJMPaddr16. These instructions enable the program to
branch to anywhere within the full 64 K-bytes of program memory address space.
8. Indexed Addressing
In this mode the 16-bit address in a base register is added to a positive offset to
form an effective address for the jump indirect instruction JMP @A+DPTR, and
the two move code byte instructions MOVC A,@A+DPTR and MOVC A,@A+PC.
The base register in the jump instruction is the data pointer and the positive offset
is held in the accumulator. For the move instructions the base register can either
be the data pointer or the program counter, and again the positive offset is in the
accumulator.
6.Write an 8051 ALP to create a square wave of 50% duty cycle on bit 3 of
port1[May/Jun 2016]
MOV TMOD,#01
HERE:MOV TLO,#0F2H
MOV TH0,#0FFH
CPL P1.3
ACALL DELAY
SJMP HERE
174
7. Write an ALP using 8051 instructions to receive bytes of data serially and
put them in P1. Set the baud rate at 4800, 8-bit data, 1 stop bit. [Nov/Dec
2016]
MOV TMOD,#20H
MOV TH1,#-6
MOV SCON,#50H
SETB TR1
HERE: JNB RI,HERE
MOV A, SBUF
MOV P1, A
CLR RI
SJMP HERE
END
PART – C
1. Generate a square wave with an ON time of 3ms and an OFF time of 10ms
on all pins of port 0. Assume an XTAL of 22MHz.
Program:
XTAL frequency = 22MHz
=22MHz/12
= 1.833MHz
Time period =1/1.833MHz = 0.546µs
175
CLR TR0
CLR TF0
RET
END
2. Assume that the 8051 serial port is connected to the COM port of the IBM
PC, and on the PC we are using the hyper terminal Program to send and
receive data serially. P1 and P2 of the 8051 are connected to LEDs and
switches, respectively. Write an 8051 program to (a) send to the PC the
message “ We Are Ready” , (b) receive any data sent by the PC and put it
on LEDs connected to P1, and (c) get data on switches connected to P2 and
send it to the PC serially. Use the 4800 baud rate.
Solution:
ORG 0
MOV P2, #0FFH
MOV TMOD, #20H
MOV TH1, #0FAH
MOV SCON, #50H
SETB TR1
MOV DPTR, #MYDATA
H1: CLR A
MOVC A, @A+DPTR
JZ B1
ACALL SEND
INC DPTR
SJMP H1
B1: MOV A,P2
ACALL SEND
ACALL RECV
MOV P1, A
SJMP B1
SEND: MOV SBUF, A
JNB TI, H2
CLR TI
RET
RECV: JNB RI, RECV
MOV A, SBUF
CLR RI
RET
MYDATA: DB “We Are Ready”,0
END
176
PART A
The Baud Rate is determined based on the oscillator‟s frequency when in mode 0
and 2. In mode 0, the baud rate is always the oscillator frequency divided by 12. This
means if you‟re crystal is 11.059Mhz, mode 0 baud rate will always be 921,583
baud. In mode 2 the baud rate is always the oscillator frequency divided by 64, so a
11.059Mhz crystal speed will yield a baud rate of 172,797.
6. Mention any two applications that use ADC and DAC. [Apr/May 2011]
a. Temperature controller b. Stepper motor
177
TF1: Timer1 overflow flag. It is set when timer rolls from all 1s to 0s
TR1 : Timer1 run control bit. Set to 1 to start the timer / counter
TF0 : Timer0 overflow flag.
TR0 : Timer0 run control bit
IE1 : Interrupt1 edge flag. Set by hardware when an external interrupt edge
is detected.
IE0 : Interrupt0 edge flag.
IT1 : Interrupt1 type control bit. Set/ cleared by software to specify falling
edge / low level triggered external interrupt
IT0 : Interrupt0 type control bit.
Vref pin in the ADC is used to compare the input signal with the reference signal.
178
The digital to analog converter is a device used to convert digital pulses to analog
signals. DAC is interfaced with microcontroller for many application such as
generating sine waveform.
In this mode, serial data enter and exists through RXD and TXD ouput. Eight bits are
transmitted and received. The baud rate is fixed at ½ th of crystal frequency.
Polling:
In the polling method, the microcontroller must „access by himself‟ the device and
„ask‟ for the information it needs for processing. The main drawback of this method
when writing program is waste of time of microcontroller, which needs to wait and
check whether the new information has arrived.
Interrupt:
In this method „requesting‟ the processor to stop to perform the current program and
to „ make time‟ to execute the special code. Whenever any device needs its service,
the device notifies the microcontroller by sending it an interrupt.
179
PART B
The 8051 has two timers Timer0 and Timer1. They can be used either as timer or
event counter. Timer0 and Timer1 are 16 bit registers each can be accessed as two
separate registers of low byte and high byte. The timer content is available in four 8-
bit special function registers, viz, TL0,TH0, TL1 and TH1.respectively.
TH0 TL0
TH1 TL1
TCON
TMOD
The timer can act in "timer" function mode and "counter" function mode
Timer0 Registers :
16 bit register of timer 0 is accessed as low byte and high byte. The low byte is
called TL0 and high byte is called TH0. Minimum value is 0000 and maximum value
is FFFF can be loaded in the Timer 0 Register depending on the modes of operation
180
Timer1 Registers :
16 bit register of timer 1 is accessed as low byte and high byte. The low byte is
called TL1 and high byte is called TH1. Minimum value is 0000 and maximum value
is FFFF can be loaded in the Timer 0 Register depending on the modes of operation
Both timers use the same register called TMOD to set the various timer operation
modes. TMOD is a 8 bit register in which the lower 4 bits are set aside for Timer 0
and the upper 4 bits for Timer 1. In each case the lower 2 bits are used to set the
Timer mode and upper 2 bits to specify the operation.
7 6 5 4 3 2 1 0
Gate C/T M1 M0 Gate C/T M1 M0
Timer 1 Timer 0
Pulse
THX TLX
Input TFX Interrupt
5 Bits 8 Bits
In this mode, the timer is used as a 13-bit UP counter. The lower 5 bits of THX and 8
bits of TLX are used for the 13 bit count. Upper 3 bits of THX are ignored. When the
counter rolls over from all 0's to all 1's, TFX flag is set and an interrupt is generated.
The input pulse is obtained from the previous stage. If TR bit is 1 and Gate bit is 0,
the counter continues counting up. If TR bit is 1 and Gate bit is 1, then the
operation of the counter is controlled by INTX input. This mode is useful to measure
the width of a given pulse fed to INTX input. The range of values are 0000 H to
1FFF H. When the timer reaches the maximum value it rolls over to 0000H.
181
Mode1 is similar to mode0 except TLX is configured as a full 8-bit counter. When the
mode bits are set to 01 in TMOD. The Timer operates in 16-bit mode. The range of
values are 0000 H to FFFF H. When the timer reaches the maximum value it rolls
over to 0000H.
Pulse
THX TLX TFX Interrupt
Input
8 Bits 8 Bits
Pulse
TLX TFX Interrupt
Input 8 Bits
THX
8 Bits
Timer Mode 3
Timer 1 in mode-3 simply holds its count. Timer 0 is used in mode 3. The effect is
same as setting TR1=0. Timer0 in mode-3 establishes TL0 and TH0 as two separate
counters
Pulse
TL0 TF0 Interrupt
Input 8 Bits
Pulse TH0
Input TF1 Interrupt
8 Bits
182
TCON is 8 bit register. Upper 4 bits are used to store TF and TR bits of both timer0
and timer1. The lower four bits are set aside for controlling the interrupt bits.
TF1: Timer1 overflow flag. It is set when timer rolls from all 1s to 0s
TR1 : Timer1 run control bit. Set to 1 to start the timer / counter
TF0 : Timer0 overflow flag.
TR0 : Timer0 run control bit
IE1 : Interrupt1 edge flag. Set by hardware when an external interrupt edge
is detected.
IE0 : Interrupt0 edge flag.
IT1 : Interrupt1 type control bit. Set/ cleared by software to specify falling
edge / low level triggered external interrupt
IT0 : Interrupt0 type control bit.
Write briefly about the operating modes for serial port of 8051
microcontroller. [Marks 4] [April/May 2011]
Explain The operation of Serial Port With Associated Register. (8) [Nov / Dec
2012]
Write a program to bring in data in serial form and send it out in parallel
form using 8051.(6) [Apr/May 2015]
Explain 8051 serial port programming with example.[May/Jun 2016]
Serial Communication is used for transferring data between two system. One of the
8051s many powerful features is its integrated UART, otherwise known as a serial
port.
For serial data transmission, 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 must be a serial in parallel-out shift register to receive the serial data and pack
them into byte. Pins TxD (P3.1) and RxD (P3.0) are used for transmitting and
receiving the data serially
183
a) Simplex Mode: Data is transmitted only in one direction from the transmitter to
the receiver over a single communication channel.
b) Half Duplex Mode: Data transmission may take place in either direction, but at a
time data may be transmitted only in one direction.
c) Full Duplex Mode: Data transmission may take place in both directions
simultaneously.
184
Start bit is always one bit and it will be low signal. Stop bit is represented by 1 or 2
bits and the stop bit must be high. Data can be 7 bits or 8 bits wide. The data is
nothing but the ASCII value of the character.
8051 contains two reisters SCON and SBUF for serial transmission.
SCON Register
SBUF Register
(Transmit & Receive)
Serial Interface
The serial port of 8051 is full duplex, i.e., it can transmit and receive simultaneously.
The register SBUF is used to hold the data. The special function register SBUF is
physically two registers. One is, write-only and is used to hold data to be transmitted
out of the 8051 via TXD. The other is, read-only and holds the received data from
external sources via RXD.
Data Transmission
Transmission of serial data begins at any time when data is written to SBUF. Pin
P3.1 (Alternate function bit TXD) is used to transmit data to the serial data network.
TI is set to 1 when data has been transmitted. This signifies that SBUF is empty so
that another byte can be sent.
Data Reception
Reception of serial data begins if the receive enable bit is set to 1 for all modes. Pin
P3.0 (Alternate function bit RXD) is used to receive data from the serial data
network. Receive interrupt flag, RI, is set after the data has been received in all
modes. The data gets stored in SBUF register from where it can be read.
185
seventh bit (b7)(SMOD) is used to generate the baud rate of serial communication.
program to bring in data in serial form and send it out in parallel form using 8051
3. INTERRUPTS
1. Timers overflowing
2. Receiving character via the serial port
3. Transmitting character via the serial port
4. Two “external events
187
Serial port interrupts (RI and TI): Whenever a data byte is received, an interrupt
bit, RI is set to 1 in SCON register. When a data byte is transmitted an interrupt bit
TI, is set in SCON. They are ORed together to provide a single interrupt to the
processor. These flags must be reset by software instruction to enable the next data
communication operation.
External signal at pin INTO (P3.2): When a high-to-low edge signal is received
onP3.2, the external interrupt 0 edge flag IE0 (TCON.1) is set. This flag is cleared
when the processor branches to the subroutine. When the external interrupt signal
control bit IT0 (TCON.0) is set to 1 (by program) then interrupt is triggered by falling
edge signal. If IT0 is 0, a low-level signal in INTO triggers the interrupt.
External signal at pin INT1 (P3.3): Flags IE1 (TCON.3) and IT1 (TCON.2) are
similar to IE0 and IT0 in function.
IE Register
IP Register
When an interrupt occurs, the updated PC is pushed on the stack and is loaded with
the vector address corresponding to the interrupt.
188
Vector
Interrupt
Address
IE0 0003
TF0 000B
IE1 0013
TF1 001B
Serial 0023
Each interrupt source can also be individually programmed to one of two priority
levels by setting or clearing a bit in the SFR named IP (Interrupt Priority). A low-
priority interrupt can be interrupted by a high-priority interrupt, but not by another
low-priority interrupt. A high-priority interrupt can‟t be interrupted by any other
interrupt source. If two interrupt requests of different priority levels are received
simultaneously, the request of higher priority is serviced. If interrupt requests of the
same priority level are received simultaneously, an internal polling sequence
determines which request is serviced. Thus within each priority level there is a
second priority structure determined by the polling sequence. If the flag for an
enabled interrupt is found to be set (1), the interrupt system generates a CALL to the
189
appropriate location in Program Memory, unless some other condition blocks the
interrupt. Several conditions can block an interrupt, among them that an interrupt of
equal or higher priority level is already in progress. The hardware-generated CALL
causes the contents of the Program Counter to be pushed into the stack, and
reloads the PC with the beginning address of the service routine.
LCD is finding widespread use replacing LEDs for the following reasons:
190
PIN DESCRIPTION
1. VSS - Ground
2. VEE- Supply Voltage
3. VCC - Contrast Setting
4. RS - Register Select
5. R/W - Read/Write Select
6. E - Chip Enable Signal
7-14 DB0-DB7 - Data Lines
The LCD requires 3 control lines (RS, R/W & E) & 8 (or 4) data lines. The
number on data lines depends on the mode of operation. If operated in 8-bit mode
then 8 data lines + 3 control lines i.e. total 11 lines are required. And if operated in 4-
bit mode then 4 data lines + 3 control lines i.e. 7 lines are required. When RS is low
(0), the data is to be treated as a command. When RS is high (1), the data being
sent is considered as text data which should be displayed on the screen.
When R/W is low (0), the information on the data bus is being written to the
LCD. When R/W is high (1), the program is effectively reading from the LCD. Most of
the times there is no need to read from the LCD so this line can directly be
connected to GND thus saving one controller line. The ENABLE (E) pin is used to
latch the data present on the data pins. A HIGH - LOW signal is required to latch the
data. The LCD interprets and executes our command at the instant the E line is
brought low. If you never bring E low, your instruction will never be executed.
LCD module has a set of preset command instructions. Each command will
make the module to do a particular task. The commonly used commands and their
function are given in the table below.
191
The steps that has to be done for initializing the LCD display is given below and
these steps are common for almost all applications.
To send any of the commands to the LCD, make pin RS=0. For data, make RS=1.
Then send a high-to-low pulse to the E pin to enable the internal latch of the LCD.
This is shown in the code below.
KEYBOARD INTERAFCING
Matrix keyboards are connected in a series of rows and columns. The important
tasks in interfacing a keyboard are 1) detecting a key press, 2) debounce the key
press and 3) encode the key to some standard code. Three tasks can be done with
hardware, software, or a combination of two, depending on the application.
Keyboards are organized in a matrix of rows and columns. The CPU accesses both
rows and columns through ports. Therefore, with two 8-bit ports, an 8 x 8 matrix of
keys can be connected to a microprocessor. When a key is pressed, a row and a
column make a contact. Otherwise, there is no connection between rows and
columns. A 4x4 matrix connected to two ports. The rows are connected to an output
port and the columns are connected to an input port.
192
193
5. SENSOR INTERACING
Transducer converts physical data such as temperature, light intensity, flow and
speed to electrical signals. Depending on the transducer the output produced is in
the form of voltage, current, resistance or capacitance. For example temperature is
converted to electrical signals using a transducer called a thermistor. A thermistor
responds to temperature change by changing resistance, but its response is not
linear. The complexity associated with writing software for such nonlinear devices
has led many manufacturers to market the linear temperature sensor.
Signal conditioning is a widely used term in the world of data acquisition. It is the
conversion of the signals (voltage, current, charge, capacitance, and resistance)
produced by transducers to voltage, which is sent to the input of an A to-D
converter.‰ Signal conditioning can be a current to voltage conversion or a signal
amplification. The thermistor changes resistance with temperature, while the change
of resistance must be translated into voltage in order to be of any use to an ADC
Look at the case of connecting an LM35 to an ADC804. Since the ADC804 has 8-bit
resolution with a maximum of 256 steps and the LM35 (or LM34) produces 10 mV for
every degree of temperature change, we can condition V in of the ADC804 to produce
a Vout of 2.56 V for full-scale output. Therefore, in order to produce the full scale Vout
of 2.56 V for the ADC804, We need to set Vref/2 = 1.28. This makes Vout of the
ADC804 correspond directly to the temperature as monitored by the LM35.
194
Draw the diagram to interface a stepper motor with 8051 microcontroller and
explain. Also write an 8051 ALP to run the stepper motor in both forward
and reverse direction with delay. [16] [April/May 2011][May/Jun 2016]
Draw the diagram to interface a stepper motor with a 8051 microcontroller
and explain. Also write an 8051 ALP to run the stepper motor in both
forward and reverse direction with delay.(16) [Nov /Dec 2013, 2015,2016]
Draw the diagram to interface a stepper motor with 8051 microcontroller and
explain. Write a 8051 assembly language program to run the stepper motor
in both forward and reverse direction with delay. (16) [Apr/May 2015]
Stepper motor is a widely used device that translates electrical pulses into
mechanical movement. Stepper motor is used in applications such as; disk drives,
dot matrix printer, robotics etc,
195
Step angle:
Step angle is defined as the minimum degree of rotation with a single step.
No of steps per revolution = 360° / step angle
Steps per second = (rpm x steps per revolution) / 60
Two Phase ON
One Phase ON
196
PROGRAM
To rotate the stepper motor clockwise / anticlockwise continuously with full step
sequence.
MOV A,#66H
BACK: MOV P1,A
RR A
ACALL DELAY
SJMP BACK
197
PART – C
1. Explain the hardware required to control the speed of the fan according
to temperature using 8051.
Required Components:
Temperature Sensor
The temperature sensor used in the proposed system is LM35. The o/p of this
temperature sensor is linearly proportional to the Celsius scale. This IC doesn‟t need
any external calibration to give accuracies. The main function of the temperature
sensor in the proposed system is to detect the temperature of external environment
of fan.
198
The 8-bit microcontroller AT89C51 belongs to 8051 family. It consists of 128 bytes of
RAM, 16-bits of addresses, 16 bit timer/ counter-2, 6 interrupts, ROM- 4k bytes. The
main function of the microcontroller in the proposed system is to analyze the
temperature which is sensed by the temperature sensor. Based on the temperature,
the microcontroller should change the speed of fan.
ADC (0808)
An ADC (analog to digital converter) needs to be interfaced with 8051 microcontroller
to allow analog i/p for processing of data. Here serial I/O port is used to make the
flow of data between controllers and also other devices. Here, an 8 bit parallel
ADC0808 IC has been used. It works with +5V and has an 8-bit resolution. This ADC
converts the input analog signal into equivalent digital signal by using the reference
voltage.
199
Interfacing diagram:
Working:
Temperature sensor LM35 is interfaced with the 8051 microcontroller‟s analog pin
because, temperature sensor changes temperature into voltage. Here temperature
sensor should be interfaced correctly to the microcontroller in order to get correct
reading. The speed of the fan can be decided by the temperature examine by the
microcontroller.
Microcontroller controls the DC fan using the IC L293D motor control. This IC L293D
is a dual H-bridge motor driver used to control the speed and direction of DC motor.
It also offers isolation between microcontroller and motor. Motor speed can be
controlled by using the pulse width modulation (PWM) technique.
The proposed system is also provided with auto or manual switch which gives the
option to user to control the speed of fan. When the button is pressed, the speed can
controlled by manually that means user can control the fan speed manually. An LED
can also be connected at RC1 to demonstrate the status of auto or manual switch. If
light emitting diode is blinking, it means the fan control is manual.
So finally we can conclude that, when the power supply is given to the entire circuit
then the microcontroller reads the surrounding temperature of fan. The analog value
of the temperature is given by the sensor and applied to the ADC pin of
microcontroller. The value of analog is changed to the digital by the microcontroller
internally. If the temperature is superior to the threshold value, then microcontroller
sends a signal to the controller to turn ON the motor. Thus fan starts rotating.
200
2. With neat diagram explain the operation of washing machine and write
the program to control the washing machine.
201
Operations:-
Fill:- water will be filled by the pump as per the load knob selected.
Agitate:- The wash basket will rotate in a clockwise direction for 10 revolutions, After
that basket will stop for 2 seconds, then rotate 10 revolutions in anticlockwise
direction. The process will be continued for specified minutes in cycle table.
Spin:- During spin, agitator will be stationary, only the basket will rotate at high
speed. Then the moisture of clothes are removed through holes in the inner metallic
basket.
Fill water Set by load Set by load Set by load Set by load
202
Fill water Set by load Set by load Set by load Set by load
203
Calculators
Accounting system
Games machine
Complex Industrial Controllers
Traffic light Control
Data acquisition systems
Multi user, multi-function environments
Military applications
Communication systems
204
205
206
207
13. (a) Explain in detail about DMA controller with its diagram. [P.No 138] (16)
OR
(b) Draw and explain the block diagram of alarm controller.
(16)
14. (a) Explain the architecture of 8051 with its diagram. [P.No 168]
(16)
OR
(b) Write an 8051ALP to create a square wave of 66 % duty cycle on bit 3 of port
1. (16) [P.No 174]
15. (a) Draw the diagram to interface a stepper motor with 8051 microcontroller and
Writ its ALP to run the stepper motor in both forward and reverse direction with
delay. (16) [P.No 195]
OR
(b) Explain 8051 serial port programming with examples. [P.No 183] (16)
208
209
210
11. (a)(i) Explain briefly about the internal hardware architecture of 8086
microprocessor with a neat diagram. (10)
(ii) Write an 8086 Assembly Language Program to Convert BCD data- Binary
data. (6)
Or
(b) (i) Explain about the Assume, EQU, DD assembler directives (8)
12. (a) Discuss the maximum mode configuration of 8086 by with a neat diagram.
Mention the functions of the various signals. ]
(16)
Or
(b) (i) Compare closely coupled configuration with loosely coupled
configuration.(8)
ii) Write a 8086 Assembly Language program to check whether the input
string is palindrome or not. (8)
211
13. (a) (i) Explain how D/A and A/D interfacing done with 8086 with an
application.
(10)
ii) What is DMA? Explain the DMA based data transfer using DMA controller.
(6)
Or
b) (i) Draw the block diagram of traffic light control system using 8086. (8)
ii) Write the algorithm and assembly language program for traffic light control
system
(8)
14. (a)(i) Explain the architecture of 8051 microcontroller with neat diagram. (8)
(ii) Explain the TMOD function register and its timer modes of operations.(8)
Or
(b)(i) Explain about Arithmetic and control instruction set in 8051. (10)
(ii) Write a program to bring in data in serial form and send it out in parallel
form using 8051. (6)
15.(a)(i) Describe the different modes of operation of timers/counters in 8051
with its associated register. (10)
(ii) How does one interface a 16 x 2 LCD display using 8051
Microcontroller? (6)
Or
b) Draw the diagram to interface a stepper motor with 8051 microcontroller
and explain. Write a 8051 assembly language program to run the stepper motor in
both forward and reverse direction with delay.
(16)
212
11. (a) (i) Write an 8085 assembly language program to find the
largest number in the given array
(8)
Explain the different addressing modes of 8086 microprocessor
(ii) with examples.
(8)
Or
(b) (i) Write an 8085 assembly language program to divide two
8-bit numbers and store the corresponding quotient and
remainder in the suitable memory locations.
. (8)
Draw the functional block diagram of 8085 microprocessor
213
13 (a) (i) Draw the control word and status word format of 8087 processor
(10)
Explain how the communication between CPU and IOP processor
(ii) takes place. (6)
Or
(b) (i) Draw the architecture of 8089 I/O processor and explain it. (8)
(ii) Explain the different data formats of 8087 coprocessor. (8)
14. (a) (i) In how many modes we can use 8253/54 timer? Explain the
different modes of operation of 8253/54 timer. (8)
15 (a) (i) How to interface an LCD display with microcontroller? Explain how
to display a character using LCD display. (8)
214
12. (a) Draw and discuss the interrupt structure of 8086 (16)
Or
(b) (i) Write an 8086 Assembly language program to get an input from
the keyboard for 2 digits and convert that input into a hexa
decimal number using BIOS interrupt. (8)
(ii) Write an 8086 Assembly language program to multiply 2 digits
numbers by getting an input from the keyboard wing BIOS
interrupt\call. (8)
15. (a) Draw the pin diagram of 8051 Microcontroller. And explain the
Input/Output lines in detail. (16)
Or
(b) (i) Vin=2.25v. Vref=5v Number of data lines are 5. Convert the
given analog quantity into its equivalent output digital quantity.
(8)
(ii) Explain the different techniques to convert a digital quantity into
its equivalent analog quantity. (8)
216
217
218