Professional Documents
Culture Documents
Ports A and B can be programmed as 8-bit I/O ports with three lines of Port C in each group
used for hand shaking.
Mode 2: Strobed Bidirectional Bus I/O:
This mode allows Bidirectional data T/f over a single 8-bit data bus using handshaking
signal.
Only Port A can be used as bidirectional port. The hand shaking signals are provided on five
lines of port C (PC3 – PC7).
Port B can be used in Mode 0 or in Mode1.
Bit Set Reset future:
In addition to the above modes, individual bits of port C can be set or reset by sending out a
single OUT inst. to the control register.
MRIT
Microprocessor Unit 4
MRIT
Microprocessor Unit 4
MRIT
Microprocessor Unit 4
MRIT
Microprocessor Unit 4
The control words for both mode definition and Bit Set-reset are loaded into the same
control register with bit D7 for specifying whether it is mode definition word or Bit set-
Reset word.
Example for BSR Mode:
If bit PC2 is to be set, then control reg. would be 0XXX0101
If bit PC7 is to be Reset, then control reg. would be 0XXX1110.
8255 PROGRAMMING
Mode 0:
MRIT
Microprocessor Unit 4
The control signals for both the groups in input and output modes are explained as
follows:
Input control signal definitions (mode 1 ):
STB( Strobe input ) – If this lines falls to logic low level, the data available at 8-bit input port is
loaded into input latches.
IBF ( Input buffer full ) – If this signal rises to logic 1, it indicates that data has been loaded
into latches, i.e. it works as an acknowledgement. IBF is set by a low on STB and is reset by the
rising edge of RD input.
INTR ( Interrupt request ) – This active high output signal can be used to interrupt the CPU
whenever an input device requests the service. INTR is set by a high STB pin and a high at IBF
pin. INTE is an internal flag that can be controlled by the bit set/reset mode of either
PC4(INTEA) or PC2(INTEB) as shown in fig.
Output control signal definitions (mode 1) :
OBF (Output buffer full) – This status signal, whenever falls to low, indicates that CPU has
written data to the specified output port. The OBF flip-flop will be set by arising edge of WR
signal and reset by a low going edge at the ACK input.
ACK ( Acknowledge input ) – ACK signal acts as an acknowledgement to be given by an
output device. ACK signal, whenever low, informs the CPU that the data transferred by the CPU
to the output device through the port is received by the output device.
INTR ( Interrupt request ) – Thus an output signal that can be used to interrupt the CPU when
an output device acknowledges the data received from the CPU. INTR is set when ACK, OBF
and INTE are 1. It is reset by a falling edge on WR input. The INTEA and INTEB flags are
controlled by the bit set-reset mode of PC6 and PC2 respectively.
MRIT
Microprocessor Unit 4
MRIT
Microprocessor Unit 4
MRIT
Microprocessor Unit 4
Mode 2 ( Strobed bidirectional I/O ): This mode of operation of 8255 is also called as strobed
bidirectional I/O. This mode of operation provides 8255 with an additional features for 9
communicating with a peripheral device on an 8-bit data bus. Handshaking signals are provided
to maintain proper data flow and synchronizationbetween the data transmitter and receiver. The
interrupt generation and other functions are similar to mode 1.
INTR – (Interrupt request) As in mode 1, this control signal is active high and is used to
interrupt the microprocessor to ask for transfer of the next data byte to/from it. This signal is
used for input ( read ) as well as output ( write ) operations.
Control Signals for Output operations:
OBF ( Output buffer full ) – This signal, when falls to low level, indicates that the CPU has
written data to port A.
ACK ( Acknowledge ) This control input, when falls to logic low level, acknowledges that the
previous data byte is received by the destination and next byte may be sent by the processor. This
signal enables the internal tristate buffers to send the next data byte on port A.
INTE1 ( A flag associated with OBF ) This can be controlled by bit set/reset mode with PC6.
MRIT
Microprocessor Unit 4
Control signals for input operations :
STB (Strobe input ) A low on this line is used to strobe in the data into the input latches of 10
8255.
IBF ( Input buffer full ) When the data is loaded into input buffer, this signal rises to logic ‘1’.
This can be used as an acknowledge that the data has been received by the receiver.
• The waveforms in fig show the operation in Mode 2 for output as well as input port.
MRIT
Microprocessor Unit 4
Whatever may be the technique for conversion, a general algorithm for ADC interfacing
contains the following steps. 11
1. Ensure the stability of analog I/P.
2. Issue start of conversion (SOC) pulse to ADC
3. Read EOC (end of conversion) signal
4. Read digital data o/p of the ADC.
MRIT
Microprocessor Unit 4
Prob:
Interface ADC 0808 with 8086 using 8255 ports. Use port A of 8255 for transferring digital
data o/p of ADC to the CPU and port C for control signals. Assume that an analog I/P is
present at I/P2 of the ADC and a clock i/p of suitable frequency is available for ADC. Draw
the schematic and write required ALP.
Sol: Port A: 8-bit I/P data port (for digital data from ADC)
Port C Lower: SOC: o/p port
Port C Upper: EOC: I/P port
Port B: o/p port (for giving I/P2)
Status of ADD. A B C
0 1 0
Control Word:
MRIT
Microprocessor Unit 4
13
MRIT
Microprocessor Unit 4
14
MRIT
Microprocessor Unit 4
INTERFACING DIGITAL TO ANALOG CONVERTERS:
15
The D to A converters convert binary no. into their analog equivalent voltages.
Problem:
Write an ALP to generate a triangular wave of frequency 500 Hz using the interfacing ckt
shown in fig. below. The 8086 system operates at 8MHz. The amplitude of the
triangular wave should be +5V.
MRIT
Microprocessor Unit 4
Sol:Port A: o/p Digital data to DAC.
16
Only port A is used, so the remaining ports are configured as o/ps.
Note: The technique of interfacing 12-bit DACs is also similar. If 8-bit ports are used,
two successive 8-bit OUT instructions are required to apply i/p to DAC.
MRIT
Microprocessor Unit 4
STEPPER MOTOR INTER FACING:
17
A stepper motor is a device used to obtain an accurate position control of Rotating shafts.
It employs rotation in terms of steps, rather than continuous rotation as in case of AC or
DC motors.
To rotate the shaft, a sequence of pulses is needed to be applied to the windings.
The no. of pulses required for one complete rotation of the shaft are equal to its no. of
internal teeth on its Rotor.
The Stator teeth and Rotor teeth Lock each other to fix a position of the shaft.
With a pulse applied to the winding i/p, the rotor position rotates by an angle ‘x’.
360
x
No.of Rotor teetch
The internal schematic of a stepper motor has four windings. (wa,wb,wc,wd)
Binary level pulses of 0.5 V are required at its winding inputs to obtain the rotation of
shafts.
fig
A simple scheme for rotating the shaft of a stepper motor is called wave scheme.
In this scheme, voltage pulses are applied to windings in a cyclic fashion. By reversing
it, the direction of rotation is reversed.
MRIT
Microprocessor Unit 4
Another scheme of stepper motor applies two pulses to two successive windings at a
time. 18
Problem: Design a stepper motor and write an ALP to rotate shaft of 4-phase stepper motor.
i) in clock wise 5 rotations
ii) in Anti clock wise 5 rotations
The port A address is 0740H. The stepper motor has 200 rotor teeth. The port A0 drives
winding wa, PA1 drives winding wb and soon. It has an internal delay of 10 msec.
Sol: Data segment
CWR EQU - - -
Port A EQU 0740 H
Data Ends
Code Segment
Assume CS: code, DS: data
Start: MOV AX, data
MOV DS, AX
MOV AL, 88 H; Bit pattern 10001000 to start
MOV CX, 1000; 200 Rotor teeth.
No. of Rotation * teeth = count
Count = 200*5
=
L1: OUT Port A, AL
CALL Delay
ROR AL, 01
MRIT
Microprocessor Unit 4
DEC CX
JNZ L1 19
MOV AH, 88 H, MOV CX, 1000
Code 1 Segment
Delay PROC FAR
Assume CS: code 1, DS: Data
HERE: MOV CX, OFFF H
LOOP HERE
Delay ENDP
Code 1 ends
MRIT
Microprocessor Unit 4
20
MRIT
Microprocessor Unit 4
Once the columns are found to be all high, the program enters another loop, which waits
until a low appears on one of the columns. (Indicating a key press). 21
For this a simple 20 m.s delay is executed to de bounce task.
After the de bounce time, another check is made to see if the key is still pressed. If the
columns are now all high, then no key is pressed and the initial detection was caused by a
Noise pulse.
MRIT
Microprocessor Unit 4
If any of the columns are low now, then the assumption is made that it was a valid key
press. 22
The final task is to determine the row and column of the pressed key and convert this inf.
to hex code for the pressed key.
For this, a low is given to rows and now column is read.
If none of the columns is low, the pressed key is not in that row, so the low is rotated to
next row and repeat again.
This is repeated until a low on a row produces a low on one of the columns.
Therefore, the 4-bit code from i/p port (ROW) and the 4-bit code from o/p port (column)
are converted to Hex code.
This ENCODE portion uses a compare technique. This is done with the LOOK UP table
containing 8-bit key pressed codes for 16-keys.
MRIT
Microprocessor Unit 4
23
MRIT
Microprocessor Unit 4
Program:
Data Segment 24
Table DB 077 H , 71BH , 72DH , 73EH 4
OB 7 H
5 6 7 8
OBBH , OBDH , OBEH , OD 7 H
D E B
OEBH , OEDH , OEEH ,
Data Ends
Code Segment
Assume, CS: code, DS: Data, SS: Stack-seg
Start: MOV AX, data
MOV DS, AX
;Initialize ports pot A: output (Mode 0)
Port C, Port B: I/P
MOV AL, 8 BH
OUT CWR, AL
CALL Key Board
NOP
MRIT
Microprocessor Unit 4
25
MRIT
Microprocessor Unit 4
26
Note: The concept o detecting some error condition such as “no match found” is called
Error Trapping.
Error may result when two keys were pressed at exactly same time, the decrement cycle-
compare would continue through 65,536 memory locations.
MRIT
Microprocessor Unit 4
EXERCISE 27
1. Explain the control word format of 8255 in I/O and BSR mode.
2. Write a program to print message-‘This is a printer test routine’.to a printer using
8255 port initialised in mode1.
3. Interface a typical 12-bit DAC with 8255 and write a program to generate a triangular
waveform of period 10ms. The CPU runs at 5MHz clock frequency.
4. Write ALPs to rotate a 200 teeth, 4 phase stepper motor specified below.
a) five rotations clockwise and five rotations anticlockwise.
b) rotate through angle 1350 in 2sec.
c) rotate the shaft at a speed of 10 rotations per minute.
Multiple-choice questions
A. 3 B. 4
C. 5 D. 6
A. 3 B. 4
C. 5 D. 6
A. Mode 0 B. Mode 1
C. Mode 2 D. Mode 4
A. Port A B. Port B
C. Port C D. Port D
A. A B. B
MRIT
Microprocessor Unit 4
C. C D. None
28
6. What is the status of A1A0 during an input read or output write operation with port
B?
A 00 B. 01
C. 10 D. 11
7. In BSR (bit set reset) mode, individual bits of port C can be accessed.
A. True B. False
8. What is the purpose of B3B2B1 bits of control word in mode 0(BSR mode)?
9. What is the purpose of B6B5 bits of control word in mode 0(I/O mode)?
A0 B. 1
C. 10 D. 11
10. Give the control word address if port C lower bit is to be configured as input Port,
port A as an output port in mode 0 and port B is not used in I/O mode?
A. 80H B. 81H
C. 87H D. 07H
A. Timer
B. Monostable multivibrator
C. Bistable multivibrator
D. All
MRIT
Microprocessor Unit 4
A. Input B. output
29
C. Input/Output D. None
A. Counter type
B. Comparator type
D. All
A. Input B. output
C. Input/Output D. None
15. The time taken by the ADC from active edge of SOC pulse till the active edge of
A. 1 B. 4
C. 2 D. 3
17. Which of the following pin of ADC tells us the status of EOC to microprocessor?
A. INTA B. INTR
C. RD D. WR
18. The microprocessor reads the digital data from ADC by making RD pin to______.
A. HIGH B. LOW
C. HIGH-Z D. LOW-Z
A. INTA B. INTR
MRIT
Microprocessor Unit 4
C. RD D. WR
30
20. Trigger (0 to 1 pulse) signal is given to ____ pin of ADC.
A. INTA B. INTR
C. RD D. WR
A. Input B. output
C. Input/Output D. None
23. How many ports are needed when DAC is interfaced to microprocessor?
A. 1 B. 4
C. 2 D. 3
24. Configure the control word of 8255 by using PORT A for digital output of DAC?
A. 99H B. 80H
C. 88H D. 82H
25. How many control signals are needed for DAC interfacing?
A. 1 B. 4
C. 2 D. Nil
A. 0804 B. 0805
C. 0807 D. 0808
MRIT
Microprocessor Unit 4
28. A simple scheme for rotating the shaft of a stepper motor is called _________.
29. How many windings are present in internal schematic of a stepper motor?
A. 1 B. 4
C. 2 D. Nil
Answers:
1. A
2. A
3. C
4. C
5. D
6. B
7. A
8. D
9. B
10. B
11. C
12. A
13. C
MRIT
Microprocessor Unit 4
14. A
32
15. C
16. C
17. B
18. B
19. D
20. D
21. D
22. B
23. A
24. B
25. D
26. D
27. A
28. D
29. B
30. C
MRIT