Module 2 Good Notes
Module 2 Good Notes
PRAKASH
Asst. Professor(Sr.), SENSE,
VIT Chennai
Decode
Execute
Operand register:
It is a 16-bit temporary register used by the processor to hold the temporary
values at the time of operation.
It is not available to the programmer.
38 0011 1000
+ 2F 0010 1111
67 0110 0111
• CF = 0 since there is no carry beyond d7
• PF = 0 since there is odd number of 1`s in the result
• AF = 1 since there is a carry from d3 to d4
• ZF = 0 since the result is not zero
• SF = 0 since d7 of the result is zero
MODULE-2 BECE204L – MICROPROCESSORS AND MICROCONTROLLERS 16
FLAG REGISTER EXAMPLE-2
Show how the flag register is affected by the addition of 38H and 2FH.
MOV AX,34F5H
ADD AX,95EBH
Intel 8086 has 20 lines address bus and it can address to a memory location of 220 bytes,
220=1048576 bytes (1MB)
In 8086, 20-bit address is expressed as 5 hex digits ranging from 00000h to FFFFFH
Physical address is 20 bits long and corresponds to the actual binary code output by the
BIU on the address bus lines.
Problem: 20-bit addresses are TOO BIG to fit in 16-bit registers of 8086;
Solution: Memory Segment
Segmentation is the process in which the main memory of the computer is logically divided
into different segments and each segment has its own base address
MODULE-2 BECE204L – MICROPROCESSORS AND MICROCONTROLLERS 19
SEGMENT REGISTERS
Memory segmentation is the methods where whole memory is divided into small parts
called segments of various sizes.
Why Memory segmentation? It is used to enhance the speed of execution, so that the
processor is able to fetch and execute the data from the memory easily and fast.
The 1MB memory interfaced with 8086 is divided into 16 logical segments, each with a
memory of 64KB
The starting address of the segment should be such that it can be evenly divided by 16.
A logical address gives the displacement from the base address of the segment to the
desired location within it.
A logical address, as opposed to its “real” address, which maps directly anywhere into
1MB of memory space. The “real” address is called physical address.
Adder
Address: 0001000000000010 1001
4 8 7 2
+ 4872
0100 1000 0111 0010
A 9 8 2 2
A9822
1010 1001 1000 0010 0010
The offset is the distance in bytes from the start of the segment.
The offset is given by the IP for the Code Segment.
Instructions are always fetched with using the CS register.
0A000H
SS: 0A00
0A100H
SP 0100 SS:SP
Segment Register
Memory
0A00 0
Offset
+ 0100
Physical Address
0FFFFFH
0A100H
The offset is given by the SP register.
The stack is always referenced with respect to the stack segment register.
The stack grows toward decreasing memory locations.
The SP points to the last or top item on the stack.
Vss (Pin 1 & 20): These two pins acts as the ground.
TEST (Pin 23): This pin basically shows the wait instruction. (0
means the processing inside the processor continues, 1 means the
processor has to wait for the disabling of this pin)
INTR (Pin 18) – Interrupt request: The processor after each clock
cycle samples the INTR and if the signal at this pin is found to be
high then the processor controls that interrupt internally.
HOLD (Pin 31): When an external device enables this pin then
the processor stops accessing the buses immediately after the
recent task gets over.
HLDA (Pin 30): This pin is used as a response pin for the hold
request. Once request for accessing the buses is produced by an
external entity. Then the microprocessor acknowledges the device
that its request will be considered once it gets over by the current
operation.
WR’ (Pin 29) Write: An active low signal at this pin indicates that
the processor is performing write operation from either memory
or I/O devices.
DEN’ (Pin 26) – Data ENable: This is an active low pin that
means whenever 0 is present at this pin then the transceiver gets
enabled and it separates the data from the multiplexed address
and data bus.
MODULE-2 BECE204L – MICROPROCESSORS AND MICROCONTROLLERS 35
MINIMUM MODE PINS
RQ’/ GT0‘ and RQ’/ GT1‘ (Pin 30 and 31) Request/Grant: Due
to the involvement of multiple processors, these pins indicate the
request and grant permission signals used by the other
processors requesting the CPU to access the buses, memory and
peripherals. When the signal is received by CPU, then it sends
acknowledgment. RQ/GT0 has a higher priority than RQ/GT1.
S0‘, S1‘ and S2‘ (Pin 26 to 28) Status Pins: These are used by
the 8288 bus controller for generating all the memory and I/O
operation access control signals.
S2 S1 S0 Status
0 0 0 Interrupt acknowledgement
0 0 1 I/O Read
0 1 0 I/O Write
0 1 1 Halt
1 0 0 Opcode fetch
1 0 1 Memory read
1 1 0 Memory write
1 1 1 Passive state
Example: MOV AX, 4000H – Here MOV is operation, AX and 4000H are operands
There are different types of addressing modes depending upon the location of data in
the 8086 processor.
MODULE-2 BECE204L – MICROPROCESSORS AND MICROCONTROLLERS 42
MODULE-2 BECE204L – MICROPROCESSORS AND MICROCONTROLLERS 43
IMMEDIATE ADDRESSING MODE
In this mode, the source operand is an 8-bit or 16-bit data is specified as part of the
instruction.
You cannot use this addressing mode to load immediate value into segment registers.
To move any value into segment registers, first load that value into a general-purpose
register then load the value into segment register.
Example:
MOV DL, 08H ; The immediate 8-bit data (08H) given in the instruction is moved to DL
MOV AX, 0A9FH ; The immediate 16-bit data (0A9FH) given in the instruction is moved to AX
Destination Source
When processor wants to access memory, it uses contents of segment and offset register to
compute the Physical Address (PA) using below formula.
Physical Address = Segment Address x 10H + Offset Address
The offset of a memory operand is called the operand’s effective address (EA).
EA is an unsigned 16 bit no., that expresses the operands distance in byte from the
beginning of the segment.
So by combining these registers inside [ ] symbols, we can get different memory locations
(Effective Address, EA)
Physical address
MODULE-2 48
DIRECT ADDRESSING MODE
In this mode, a 16-bit memory address (offset) where the operand is present is directly
given in the instruction.
Here only the offset address is specified, the segment being indicated by the instruction.
Example: MOV BX, [5221H] ; Moves data from location 5221H in the DS into CL
MOV CX, [4320H] ; Moves data from 4320H and 4321H; in the DS into CL and CH
Note : Register/memory enclosed
in [ ] brackets refer to content of
register/ memory
Example: MOV CL, [BX+DI+10] ; Moves a byte from the address pointed by BX+SI+10H in DS to CL.
MOV [BP+SI+4000], CL ; Moves a byte from CL into the location pointed by BP+SI+4000H in
SS. Physical Address: SS * 10H + BP+SI+4000H
In direct I/O port addressing, the I/O address is specified in the instruction.
Example: IN AL, [09H] ; Content of port with address 09H is moved to AL register
Operations: PORTaddr = 09H, (AL) (PORT)
In indirect I/O port addressing, the instruction will specify the name of the register which
holds the port address. In 8086, the 16-bit port address is stored in the DX register.
The instruction itself will specify the data to be operated by the instruction.
The entire group of instructions that a microprocessor supports is called Instruction Set.
General Purpose Data Special Address Input / Output Port Flag Transfer
Transfer Instructions Transfer Instructions Transfer Instructions Instructions
MOV LEA IN LAHF
XCHG LDS OUT SAHF
XLAT LES PUSHF
PUSH POPF
POP
Example:
MOV CX, 037AH ; Move 037AH into the CX; 037A → CX
MOV AX, BX ;Copy the contents of register BX to AX ; BX → AX
MOV DL, [BX] ;Copy byte from memory at BX to DL ; DS*10+BX →DL
MODULE-2 BECE204L – MICROPROCESSORS AND MICROCONTROLLERS 61
DATA TRANSFER INSTRUCTIONS
GENERAL PURPOSE DATA TRANSFER INSTRUCTIONS
XCHG Instruction
Exchanges the contents of the register with the contents of another register (or) the
contents of the register with the contents of the memory location.
Direct memory to memory exchanges are not supported.
The both operands must be the same size and one of the operand must always be a register.
Example:
XCHG CX, [037AH] ;[ (DS* 10)+ 037A]↔ CX
XCHG AX, [BX] ;[(DS* 10)+ BX]↔ AX
XCHG DL,[BP+200H] ; [(SS* 10)+ BP+200]↔DL
For the figure below. What is the result of executing the following instruction?
XCHG AX, [0002]
For the figure below, what is the result of executing the following instruction?
XLAT
Let AX=1234H,SS=0105H and SP=0006H. Figure below shows the state of stack prior
and after the execution of next program instructions?
PUSH AX
POP BX
POP AX
Assuming that (BX)=100H, DI=200H, DS=1200H, SI= F002H, AX= 0105H, and the following
memory content. what is the result of executing the following instructions?
a. LEA SI , [ DI + BX +2H]
b. MOV SI , [DI+BX+2H]
c. LDS CX, [300]
d. LES BX , [DI+AX]
Example:
IN AL,0C8H ;Input a byte from port 0C8H to AL
IN AX, 34H ;Input a word from port 34H to AX
OUT 3BH, AL ;Copy the contents of the AL to port 3Bh
OUT 2CH, AX ;Copy the contents of the AX to port 2Ch
MOV DX, 0FF78H ;Initialize DX point to port MOV DX, 0FFF8H ;Load desired port address in DX
IN AL, DX ;Input a byte from a 8 bit port 0FF78H to AL OUT DX, AL ; Copy the contents of AL to FFF8h
IN AX, DX ;Input a word from 16 bit port to 0FF78H to AX. OUT DX, AX ;Copy content of AX to port FFF8H
SAHF instruction - Store AH Register into FLAGS: It transfers the bits 0-7 of
AH of SF, ZF, AF, PF, and CF, into the Flag register.
POPF Instruction - Pop word from top of stack to flag register: It copies a
word from the two memory location at the top of the stack to flag register
and increments the stack pointer by 2.
MODULE-2 BECE204L – MICROPROCESSORS AND MICROCONTROLLERS 73
ARITHMETIC INSTRUCTIONS
ARITHMETIC INSTRUCTIONS
These instructions are those which are useful to perform Arithmetic calculations, such as
addition, subtraction, multiplication and division.
In Binary all the Signed Numbers have a '1' in the Most Significant Bit (MSB) position which
represents a negative number and a '0' in the Most Significant Bit (MSB) position which
represents a positive number.
Also, in Binary, the 2's Complement of a number is the negative equivalent of the positive
number. So, +2 = 0000 0010 and the 2's Complement is 1111 1110 which is - 2.
A 16 bit number system can be used to create 65536 combinations (from 0 to 65535),
and the first 32768 combinations (0 to 32767) represent positive numbers and next
32768 combinations (32768 to 65536) represent negative numbers.
Example:
ADC CL, BL
Assume that CL = 01110011 =115 decimal, BL = 01001111 = 79 decimal and CF=1
Example:
INC AX
Assume AX = 7FFFh. After this instruction AX = 7FFFh + 1 = 8000h
Example:
Example:
SUBB CL, BL
Assume that CL = 01110011 =115 decimal, BL = 01001111 = 79 decimal and CF=1
Example:
DEC AX
Assume AX = 7FFFh. After this instruction AX = 7FFFh - 1 = 7FFEh
Example:
Example:
MOV AX , 2CBh
NEG AX ;after executing NEG result AX =FD35h.
Example:
CMP CX, BX
Example:
MOV AX, 0206H ; AX=0206H
MOV BL, 05H ; BL=09
AAD ; AL = (AL + (10 * AH)) = (06+(10*02))=1AH (26 in decimal), AH=00H
DIV BL ; DIV BL =AX/BL =001AH/05H = 01H (Reminder) →AH, 05H (Quotient) → AL.
Example:
CBW
Example:
CWD
Logical instructions to perform bit by bit logic operation on the specified source and
destination operands.
Shift instructions can perform two basic types of shift operations; the logical shift and the
arithmetic shift. Also, each of these operations can be performed to the right or to the left.
Rotate instructions, rotate the contents from 1 to 255 bit positions to the left or to the right.
MODULE-2 BECE204L – MICROPROCESSORS AND MICROCONTROLLERS 100
BIT MANIPULATION INSTRUCTIONS
LOGICAL INSTRUCTIONS
NOT Instruction
Inverts each bit (forms the 1’s complement) of a byte or word in the specified destination.
The destination can be a register or a memory location.
Example:
NOT AL
TEST Instruction
Similar to AND instruction but result is not stored anywhere, affects only flag bits.
MODULE-2 BECE204L – MICROPROCESSORS AND MICROCONTROLLERS 102
BIT MANIPULATION INSTRUCTIONS
LOGICAL INSTRUCTIONS
OR Instruction
Performs bit-wise OR operation on Destination and Source operand.
Used to set certain bits. Ex.: Set the lower three bits of BL register
OR BL, 07H ; (xxxx xxxx OR 0000 0111 = xxxx x111)
Mnemonic Meaning Format Operation Flags Effected
OR Logical OR OR D, S (S) + (D) → (D) O, S, Z, P, C
Note that the amount of shift specified in the source operand can be defined explicitly if it
is one bit or should be stored in CL if more than 1.
MODULE-2 BECE204L – MICROPROCESSORS AND MICROCONTROLLERS 105
BIT MANIPULATION INSTRUCTIONS
SHIFT INSTRUCTIONS
Along with above string instructions 8086 uses auto-indexing and prefix instructions in
order to perform effective block transfer of memory content from DS to ES.
The decision to increment or decrement is made based on the status of the direction flag.
The direction Flag: Selects the auto increment (D=0) or the auto decrement (D=1)
operation for the DI and SI registers during string operations.
For example, REP, caused the basic string operation to be repeated until the contents of
register CX become equal to 0.
Each time the instruction is executed, it causes CX to be tested for 0.
If CX is found not to be 0, it is decremented by 1 and the basic string operation is repeated.
If it is 0, the repeat string operation is done and the next instruction in the program is executed.
The repeat count must be loaded into CX prior to executing the repeat string instruction.
MODULE-2 BECE204L – MICROPROCESSORS AND MICROCONTROLLERS 116
STRING INSTRUCTIONS
Type
Iteration Control
Mnemonics
JMP Instruction Operation Example
Instructions
Short Jump Jump to address location specified as 8-bit constant
JMP 8-bit JMP 45H
[8-bit] value (8-bit) → (IP)
Jump to address location specified as 16-bit constant
JMP 16-bit JMP 1234H
Intersegment value (16-bit) → (IP)
Jump Near Jump Jump to the address location given in the register
JMP Reg. JMP SI
[16-bit] (Reg.) → (IP)
Jump to the address location pointed by the content
JMP [Reg.] JMP [SI]
present in the register [(Reg.)] → (IP)
Jump to address location specified as 16-bit constant JMP
JMP 16-bit:16-bit
value (First 16-bit) → (IP), (Second 16-bit) → (CS) 2000:1234
Intersegment
Far Jump Jump to the address location given in the registers
Jump
[32-bit] [(Reg.1)] → (IP), [(Reg.2)] → (CS)
JMP [Reg.1][Reg.2] JMP [BX][SI]
Subroutine A
First Instruction
Call subroutine A Example for CALL:
Next instruction CALL 1234h
CALL BX
CALL [BX]
CALL DWORD PTR [DI]
Return
Call subroutine A
Next instruction
If the condition under test is true, a branch to the label associated with jump instruction
occurs.
If the condition is false, the next sequential step in the program executes.
I/O ports or input/output ports are the devices through which the microprocessor
communicates with other devices or external devices
8255 is a programmable I/O device that acts as interface between peripheral devices
and the microprocessor for parallel data transfer.
Intel 8255 is a widely used general purpose parallel I/O interface which provides three
I/O port (Port A, Port B and Port C).
MODULE-2 BECE204L – MICROPROCESSORS AND MICROCONTROLLERS 141
INTRODUCTION
Features of 8255:
It is available in 40 pin DIP.
It contains 24 programmable I/O pins arranged as two 8-bit ports and two 4-bit ports.
It has 3, 8-bit ports: Port A, Port B and Port C, which are arranged in two group of 12
pins.
Fully compatible with Intel microprocessor families.
Direct bit set/reset capability is available for port C.
It can operate in 3 Modes: Mode 0 : Simple I/O, Mode 1 : Strobed I/O, Mode 2 :
Strobed bi-directional I/O.
To program the function to all three i/O ports it contains a register called as control word
registers (CWR).
CWR defines the function of each I/O port and in which mode they should operate.
8-Bit Port-A
Step-2: PPI permits Input devices to send data, only when
there is no left data in 8255 which should be sent to the 8086 Data Bus 8255 I/O
Port-B
8086. Once 8255 permits input device, data is received μP PPI Devices
Port-C
and stored in temporary registers in 8255.
Grant Permission
Transfer Data
Step-3: Once 8255 holds some data, then it send signal Port-A
8-Bit
to 8086. Whenever 8086 is free to receive the data, Data Bus
then 8086 sends back a signal , after that data 8086 8255 Port-B I/O
transmission happens between 8255 and 8086. μP PPI Devices
Port-C
All the signal in the above diagrams represented using dotted curved arrow are known as handshake signals.
MODULE-2 BECE204L – MICROPROCESSORS AND MICROCONTROLLERS 144
Pin Name Function
D0-D7 Data Bus Carry data or control word to/from the microprocessor.
A “low” on this input pin enables communication between 8255
CS’ Chip Select
and μP
A “low” on this input pin enables 8255 to send the data or status
RD’ Read
information to the μP on the data bus.
A “low” on this input pin enables the μP to write data or control
WR’ Write
words into the 8255
Decide which 8255 Port (A,B,C)/Control word register will be
A0-A1 Address Pins
selected for transferring the data
When 8255 is reset, it clears the control word register and all
RESET Reset
ports are set to input mode.
These are 8-bit bidirectional I/O pins used to send data to the
PA0-PA7 Port A pins
peripheral or to read data from the peripheral.
PB0-PB7 Port B pins These are 8-bit bidirectional I/O pins used the same as PA0-PA7
These are 8-bit bidirectional I/O pins. These lines are divided
PC0-PC7 Port C pins
into 2 sections i.e. PC0-PC3 and PC4-PC7.
Whenever there exists a need for data fetch then it accepts the address provided by the
processor through the bus and immediately generates command to the two control groups.
Group A send the control signal to port A and Port C (Upper) PC7-PC4.
Group B send the control signal to port B and Port C (Lower) PC3-PC0.
The port C divided into 2 sections, port C upper (PCU) and port C lower (PCL). These two
sections can be programmed and used separately as a 4-bit I/O port.
Port C can be used as (i)Simple I/O (ii) handshake signals (iii) status signal inputs.
For handshake signals and status signals, it is used in coordination with port A and port B.
Problems:
(a) Write a control word to reset PC5. (Ans: 0AH)
(b) Write a Control Word to Set PC2. (Ans: 05H)
MODULE-2 BECE204L – MICROPROCESSORS AND MICROCONTROLLERS 153
8255 – I/O MODE
2. I/O mode:
Mode-0: (Simple I/O)
In this mode, the ports can be used for simple input/output operations without
handshaking.
If both port A and B are initialized in mode 0, port C can be either used together as
an additional 8-bit port, or they can be used as two individual 4-bit ports.
Output ports are latched but Input ports are not latched (buffered).
If port A is initialized in mode 1 as handshake input port, then pins PC3, PC4 and
PC5 function as handshake signals. (PC6 and PC7 are available)
If port A is initialized as handshake output port, then PC3, PC6 and PC7 function as
handshake signals. (PC4 and PC5 are available)
Port B is initialized in mode 1 for either input or output, Pins PC0, PC1 and PC2
function as handshake signals.
In mode 2, port A can be used for “bi-directional handshake” data transfer i.e. data
can be input or output on the same eight lines. Pins PC3, PC4, PC5, PC6, PC7 used as
handshake lines for port A.
Port B is operating in either mode 0 or mode 1. If port B is in mode 0, then PC0, PC1
and PC2 used for I/O, If port B is in mode 1, then PC0, PC1 and PC2 used as
handshake lines.
Problem-2: A I/O mode control word is given CW=CDH. Explain the conditions of ports of
8255A.
I/O Mode: Port-A is output port in Mode-2, Port-B is output port in Mode-1, Port-
C(Upper) and Port-C (Lower) are input Port.
Exercise: Configure Port A in Mode 2, Port B as o/p in mode 1. (Ans: C4H / C5H)
MODULE-2 BECE204L – MICROPROCESSORS AND MICROCONTROLLERS 159
8255 - PROBLEMS
Problem-3: Write an 8086 assembly language procedure to read an ASCII character
from a keyboard via PORT A of an 8255 PPI when PORT C bit PC4 is strobed low.
Assume a base address of 20H.
Solution:
PORTA EQU 20H
PORTC EQU 24H
CONTROL EQU 26H
MOV AL, 98H ; 1001 1000
OUT CONTROL, AL ; Initialize PORTS
READ1: IN AL, PORTC ; Is Strobe PC4 Low?
TEST AL, 10H ; 0001 0000
JNZ READ1
IN AL, PORTA ; Read ASCII Character
RET
MODULE-2 BECE204L – MICROPROCESSORS AND MICROCONTROLLERS 160
8255 - PROBLEMS
Problem-4: Write an 8086 assembly language procedure to read 12 switches and display switch
condition on 12 LEDs with 8255 as shown in below figure. Assume base address is 00H.
Solution:
PORTA EQU 00H
PORTB EQU 02H
PORTC EQU 04H
CREG EQU 06H
MOV AL, 98H ; 1001 1000
OUT CREG, AL ; Initialize PORTS
REPEAT: IN AL, PORTA
OUT PORTB, AL
IN AL, PORTC
AND AL, 0F0H
MOV CL, 04H
ROR AL,CL
OUT PORTC, AL
JMP REPEAT
HLT
MODULE-2 BECE204L – MICROPROCESSORS AND MICROCONTROLLERS 161
162
Applications of Timer:
Real time clock
Event-counter
Programmable rate generator
Complex waveform/ Square wave generator
It is internally connected to internal data bus and its outer pins D0-D7 are connected to
system data bus.
The direction of data buffer is decided by read and write control signals.
MODULE-2 BECE204L – MICROPROCESSORS AND MICROCONTROLLERS 168
8254 – INTERNAL ARCHITECTURE
2. Read/Write control logic:
This block accepts inputs from system control bus and address bus.
8254 operation is enables/disabled by CS’ signal. CS’ is connected to address decoder.
The control word registers and the counters are selected according to the signals on line A0
and A1. A0 and A1 are directly connected to address lines A1 and A2 lines of μp.
In I/O mapped I/O, the signals RD’ and WR’ are connected to IOR’ and IOW’. In
memory mapped I/O, RD’ and WR’, are connected to MEMR’ and MEMW’.
A1 A0 Selection
0 0 Counter 0
0 1 Counter 1
1 0 Counter 2
1 1 Control word register
MODULE-2 BECE204L – MICROPROCESSORS AND MICROCONTROLLERS 169
8254 – INTERNAL ARCHITECTURE
3. Control Word Register:
This register of 8254 programmable interval timer gets selected when A0=1 and A1=1.
It is used to specify the BCD or binary counter to be used, its mode of operation and the
data transfer to be used i.e read or write the data bytes.
If the CPU performs a write operation, the data is stored in the control word register and
is offered to as control word. It is used to define counter operation.
The data can only be written into control word register, no read operation is allowed.
They can be programmed through control word register to decide mode of counter.
The loaded count value in counter will be decremented by counter at each clock pulse.
2. Compose individual Control Word (CW) for every counter planned to use in step-1
4. Calculate the count value to be loaded into individual counter as per the requirement
The selected Counter's output latch latches the count Example: Read the Counter 1 count value
at the time the Counter Latch Command is received. using counter latch command
This count is held in the latch until it is read by the ; Latching counter1
CPU (or until the Counter is reprogrammed). MOV DX, C_REG
MOV AL, 40H ; To latch counter 1
The count is then unlatched automatically and OUT DX, AL
Counter Latch Commands do not affect the
programmed Mode of the Counter in any way. ;Reading counter1
MOV DX, CNTR0
IN AL, DX
MODULE-2 BECE204L – MICROPROCESSORS AND MICROCONTROLLERS 177
8254 – READ OPERATION
3. Read-Back Command:
This command is used to read several counters at a time hence it eliminates the need
of writing separate counter-latch commands for different counters.
It allows the user to check the count value, programmed Mode, and current states of
the OUT pin and Null Count flag of the selected counter/ counters.
The read back command is written to the Control Word Register as per the format
shown in Figure.
The read-back command may be used to latch multiple counter output latches (OL) by
setting the COUNT bit D5 =0 and selecting the desired counter(s).
Each counter's latched count is held in the OL until it is read (or the counter is
reprogrammed). The counter is automatically unlatched when read, but other counters
remain latched until they are read.
MODULE-2 BECE204L – MICROPROCESSORS AND MICROCONTROLLERS 178
8254 – READ-BACK COMMAND CONTROL WORD FORMAT
Status must be latched to be read; status of a counter is accessed by a read from that
counter.
Bits D5 through D0 contain the counter's programmed Mode exactly as written in the last
Mode Control Word.
This allows the user to monitor the counter's output via software, possibly eliminating some
hardware from a system.
After the Control Word is written, OUT is initially low. Once count is loaded, the counter
is decremented after every cycle and when count reaches zero, the OUT goes high.
The OUT remains high until a new count or command word is loaded. High output used to
interrupt the processor, by setting terminal count.
GATE has no effect on OUT. If G becomes a logic 0 in the middle of the count, the
counter will remain stop until G again becomes a logic 1.
If a new count is written to the Counter, it will be loaded on the next CLK pulse and
counting will continue from the new count.
MODULE-2 BECE204L – MICROPROCESSORS AND MICROCONTROLLERS 184
8254 – MODES OF OPERATION (Mode 0: Interrupt on terminal count)
OUT is initially (after loading CW) high. Also remain high when count is written.
When GATE is triggered, the OUT goes low and at the end of count it goes high again,
thus generating a one shot pulse.
If the GATE input occurs within the duration of counting, the counter is again reloaded
with the count and start counting from the beginning.
At the first falling edge of clock after first rising edge of GATE counter starts counting.
When a count N is loaded, the OUT stays high until count reaches N-1 and then OUT
goes low for 1 clock period then gets reloaded automatically and this is how pulse gets
generated continuously.
For example, for a count of 10, the output is a logic 1 for nine clock period and low for 1
clock period. This cycle is repeated until the counter is programmed with a new count or
until G pin is placed at a logic 0 level.
At the first falling edge of clock after first rising edge of WR(LSB), counter starts
counting.
MODULE-2 BECE204L – MICROPROCESSORS AND MICROCONTROLLERS 188
8254 – MODES OF OPERATION (Mode 2: Rate Generator)
If count of N is loaded, then OUT will be high for N clock cycles and low for one clock
cycle at the end of count.
The cycle does not begin until the counter is loaded again.
At first falling edge of clock after first rising edge of WR(LSB), counter starts counting.
MODULE-2 BECE204L – MICROPROCESSORS AND MICROCONTROLLERS 192
8254 – MODES OF OPERATION (Mode 4: Software Triggered Mode)
When the GATE pulse is triggered from low to high the count begins.
At the end of the count OUT goes low for one clock period.
At the first falling edge of clock after first rising edge of GATE , counter starts counting.
2. Read only Memory (ROM) – Non-Volatile (Retain all data even when power is off)
Programmable ROM (PROM) – One-time programmable memory
Erasable PROM (EPROM) – Rewrite option is allowed upto 1000 times, time consuming
Electrically EPROM (EEPROM) – Erasing can be done in byte using electrical method
Flash Memory – Entire content can be erased in one second
MODULE-2 BECE204L – MICROPROCESSORS AND MICROCONTROLLERS 202
MEMORY STRUCTURE
A general form of memory device consist of an array of registers, in which each register
has unique address. The size of the memory is N x M, where N is the number of registers
and M is the word length, in number of bits. For example: 2K X 8 means, it has 2048
memory locations which can store 8 bits in each memory location.
SRAM ICs 8Kx8 SRAM IC 6264 8Kx8 SRAM IC 6264 Pin Function Table
2. Data Pins – Used to transfer data in both direction, referred as D0 to DN. Size of the memory
locations is dependent upon the number of data bits.
3. Control Pins – Used to activate Read/Write operation. For ROM – OE’. For RAM – RD’, WR’
4. Selection Pins - Used to select the memory device or enable, usually it is called chip
select(CS), chip enable (CE) or simply select (S) input.
MODULE-2 BECE204L – MICROPROCESSORS AND MICROCONTROLLERS 206
MEMORY INTERFACING STEPS
In memory interfacing, 16-bit data line, 20 bit address line , control signals are connected
to corresponding lines of memory IC.
8086 Microprocessor
Programmable peripheral
interface (8255)
Universal Synchronous
EEPROM (ODD & EVEN Asynchronous Receiver
Memory locations) Transmitter (USART) (8251)
USB interface
RAM (ODD & EVEN
Memory locations)
To distinguish between odd and even bytes, the CPU provides a signal called BHE’ (bus
high enable). BHE’ and A0 are used to select the odd and even byte.
Memory IC A19 A18 A17 A16 A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0 Address
4KB EPROM-1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 FFFFFH
(Higher Byte)
1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 FE001H
4KB EPROM-2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 FFFFEH
(Lower Byte)
1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 FE000H
4KB RAM-1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 FDFFFH
(Higher Byte)
1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 FC001H
4KB RAM-2 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 0 FD00EH
(Lower Byte)
1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 FC000H
The memory system in this example contains in total four 4K x 8 memory chips. The two 4K x 8
chips of RAM and ROM are arranged in parallel to obtain 16-bit data bus width.
The BHE’ signal goes low when a transfer is at odd address or higher byte of data is to be
accessed.
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 A, 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.
MODULE-2 BECE204L – MICROPROCESSORS AND MICROCONTROLLERS 214
EXAMPLE - 1