Professional Documents
Culture Documents
• The address inputs, A0 and A1, allow you to selectively access one
of the three ports or the control register.
• The internal address for the device are: Port-A 00; Port-B 01; Port-C
10; control register 11.
• The RESET input of the 8255 is connected to the system reset line
so that, when the system is reset, all the port lines are initialized as
input lines.
Modes of Operation of 8255
• There are 2 basic modes of operation of 8255
–I/O Mode
–BSR Mode (Bit Set-Reset Mode)
In the I/O mode, the 8255 ports work as programmable I/O ports,
while BSR mode only Port C (PC0-PC7) can be used to set or reset
its individual port bits.
• BSR Mode
In this mode, any of the 8-bits of Port-C can be reset depending on
D0 of the control word. The bit to be set or reset is selected by bit
selected flags D3,D2 & D1 of the CWR (Control Word Register).
• I/O Mode
–Mode 0
–Mode 1
–Mode 2
–Mode 0 (Basic I/O Mode)
• Key Debounce:
Whenever a mechanical push-bottom is pressed or released once,
the mechanical components of the key do not change the position
smoothly, rather it generates a transient response. These may be
interpreted as the multiple pressures and responded accordingly.
• The rows of the matrix are connected to four output Port lines, &
columns are connected to four input Port lines.
• When no keys are pressed, the column lines are held high by the pull-up
resistors connected to +5v.
• Pressing a key connects a row & a column.
• To detect if any key is pressed is to output 0’s to all rows & then check
columns to see it a pressed key has connected a low (zero) to a column.
• 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 i.e
indicating a key press.
• A simple 20/10 msec delay is executed to debounce task.
• After the debounce 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 & the
initial detection was caused by a noise pulse.
• To avoid this problem, two schemes are suggested:
1. Use of Bistable multivibrator at the output of the key to debounce
it.
2. The microprocessor has to wait for the transient period (at least
for 10 ms), so that the transient response settles down and
reaches a steady state.
• If any of the columns are low now, then the assumption is made that
it was a valid keypress.
• The final task is to determin the row & column of the pressed key &
convert this information to Hex-code for the pressed key.
• The 4-bit code from I/P port & the 4-bit code from O/P port (row &
column) are converted to Hex-code.
;interface a 4x4 keyboard with 8086 using 8255 and write an ALP for
detecting a key closure and return the key code in AL. The debouncing
period for a key is 10ms. Use software key debouncing techniqe.
DEBOUNCE is an available 10ms delay routine.
• Out of these 8 inputs only one can be selected for conversion by using 3
address lines A,B,C.
• The CPU may drive these lines using output port lines in case of
multichannel applications.
• This chips do not contain any internal sample & hold circuit.
Interfacing between ADC to Microprocessor
Problem:-
Interface ADC 0808 with 8086 using 8255 ports. Use Port A of 8255 for
transferring digital data output of ADC to the CPU & Port C for control
signals. Assume that an analog input is present at I/P2 of the ADC
and a clock input of suitable frequency is available for ADC. Draw the
schematic & timing diagram of different signals of ADC0808.
Solution:-
• The analog input I/P2 is used & therefore address pins A,B,C should
be 0,1,0 respectively to select I/P2.
• The OE (Out put latch Enable) & ALE pins are already kept at +5v to
select the ADC and enable the outputs.
• 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 ADC.
• Port A acts as a 8-bit input data port to receive the digital data output
from the ADC.
8255 Control Word:
D7 D6 D5 D4 D3 D2 D1 D0
1 0 0 1 1 0 0 0 = 98H
Program:
MOV AL,98H ; Initialize 8255, send AL to control word (CWR)
OUT CWR, AL
MOV AL, 02H;Select I/P2 as analog I/P
OUT Port B, AL ;Port B as output
MOV AL, 00H; Give start of conversion pulse to the ADC
OUT Port C, AL
MOV AL, 01H
OUT Port C, AL
MOV AL, 00H
OUT Port C, AL
WAIT: IN AL, Port C ; check for EOC by reading Port C upper & rotating
RCL ; through carry.
JNC WAIT
IN AL, Port A ; if EOC, read digital equivalent in AC
HLT ; stop.
Interfacing Digital to Analog Converters (DAC)
• The Digital to Analog Converters (DAC) convert binary numbers into their
analog equivalent voltages.
• The DAC find applications in areas like
– Digitally controlled gains
– Motor speed controls
– Programmable gain amplifiers etc.
Number to be displayed PA7d PA6 PA5 PA4 PA3 PA2 PA1 PA0 Code
p a b c d e f g
1 1 1 0 0 1 1 1 1 CF
2 1 0 0 1 0 0 1 0 92
3 1 0 0 0 0 1 1 0 86
4 1 1 0 0 1 1 0 0 CC
5 1 0 1 0 0 1 0 0 A4
• In dot-matrix printer one small stepper motor which is used to advance the
paper to the next line position & another small stepper motor which is used
to move the print head to the next character position.
• In floppy disk stepper motor is used to position the read/write head over the
desired track.
• The no. of pulses required for one complete rotation of the shaft of the
stepper motor are equal to its number of internal teeth on its rotor.
• The stator teeth the rotor teeth lock with each other to fix a position of the shaft .
• With a pulse applied to the winding input, the rotor rotates by one teeth position
or an angle x. The angle x may be calculated as:
• The stepper motors have been designed to work with digital circuits. Binary
level pulses of 0-5v are required at its winding inputs to obtain the rotation of
shafts.
• The sequence of pulses can be decided, depending upon the required motion
of the shaft.
• The count for rotating the shaft of the stepper motor through a specified angle
may be calculated from the no. of rotor teeth
– In this scheme, the windings Wa, Wb, Wc, Wd are applied with
the required voltage pulses, in a cyclic fashion. By reversing the
sequence of excitation, the direction of rotation of the stepper
motor shaft may be reversed.
Motion Step A B C D
Clockwise 1 1 0 0 0
2 0 1 0 0
3 0 0 1 0
4 0 0 0 1
5 1 0 0 0
Anticlockwise 1 1 0 0 0
2 0 0 0 1
3 0 0 1 0
4 0 1 0 0
5 1 0 0 0
Problem
Design a stepper motor controller and write an ALP to rotate shaft of a 4-
phase stepper motor:
i. In clockwise 5 rotations
ii. In anticlockwise 5 rotations.
The 8255 port A address is 0740h. The stepper motor has 200 rotor teeth.
The port A bit PA0 drives winding Wa, PA1 drives winding Wb and so on.
The stepper motor has an internal delay of 10msec. Assume that the routine
for this delay is already available.
Solution:
ALP:
Assume cs:Code
Code segment
Start:
MOV AL, 80H
OUT CWR, AL
MOV AL, 88H; Bit pattern 10001000
MOV CX, 1000
Again1: OUT Port A, AL
CALL DELAY
ROL AL, 01
DEC CX
JNZ Again1
MOV AL, 88H
MOV CX, 1000
Again2: OUT Port A, AL
CALL DELAY
ROR AL, 01
DEC CX
JNZ Again2
MOV AH, 4CH
INT 21H
Code ends
End start