Unit -III
The 8255 Programmable Peripheral Interface
Syllabus
8255 PPI various modes of operation and interfacing to 8086. Interfacing keyboard Display Stepper motor interfacing D/A and A/D converter.
8255 Block diagram
8255 programming & operation
Bit D7 of the control register specifies either I/O function or the Bit Set/Reset function. 8255 has three operation modes: mode 0, mode 1, and mode2.
8255 programming & operation
Mode 0: ( I/O mode)
Ports A, B, and C can be individually programmed as -Input: Port Ainput or output ports. PC3 PC4 PC5 control Port C is dividedinto two 4-bit ports which are PC6 PC7 from independent I/O each other. Port A -output: Mode 1:( Strobed I/O) PC3 PC6 PC7 control Ports PC4 PC5 I/O A and B are programmed as input or output ports. Port B input /output: Port C is used for handshaking. PC0 PC1 PC2 control
mode1/mode2
8255 programming & operation
Mode2:(Strobed Bidirectional bus I/O)
Port A is programmed to be bi-directional. Port C is for handshaking. Port B can be either input or output in mode 0 or mode 1.
D7 1 D6 1 D5 X D4 X D3 X D2 1/0 D1 1/0 D0 1/0
I/O mode
Mode2 for PortA mode for portB
PortB I/O
PC0-PC2 I/O
ADC INTERFACING
ADC interfacing
ADC interfacing
Algorithm: Configure the ports. Select the analog input. Give start of conversion pulse to the ADC. Wait till the EOC goes high. If EOC=1, read digital data.
MOV AL, 98h OUT CWR, AL MOV AL, 02h OUT Port B, AL MOV AL, 01h OUT Port C, AL MOV AL, 00h OUT Port C, AL
;initialise 8255 as ;Select I/P2 as analog ;input. ;Give start of conversion ; pulse to the ADC
WAIT: IN AL, Port C RCL AL,01H JNC WAIT IN AL, Port A HLT
;Check for EOC by ; reading port C upper and ;If EOC, read digital equivalent ;Stop.
Instruction timing and delay loops
MOV CX, N delay : NOP NOP LOOP delay
Clock cycles 4 = C0 3 3 = CL 17 or 5
Instruction timing and delay loops
C0 : No. of cycles for the instructions that execute only once. CL : total no. of cycles for the instructions inside the loop. CT: no. of clock cycles to produce the desired delay. ex: for 1ms delay CT = 1ms = 5000 (assuming 5Mhz freq.) 1/5Mhz
Instruction timing and delay loops
CT = C0 + N(CL)-12 N = (CT - C0 + 12)/CL N = (5000 4 + 12)/(3+3+17) = 0DAH
Instruction timing and delay loops
Calculate the value of N for the following sequence with a delay value of 50ms.(assuming operating freq of 10Mhz)
MOV CX, N delay : DEC CX
Clock cycles 4 2 16 or 4
JNZ delay
DAC interfacing
DAC interfacing
Interfacing DAC 0800 with an 8086 CPU running at 8MHZ and write an assembly language program to generate a saw tooth waveform of period 1ms with Vmax 5V.
MOV AL,80h ;make all ports output OUT CWR, AL again: MOV AL,00h ;start voltage for ramp back : OUT PA, AL CALL delay INC AL CMP AL, 0FFh JB back JMP again Delay PROC NEAR MOV CX,03H ;delay for 1 ms LOOP $ Delay ENDP
Keyboard interfacing
Types of switches:
Mechanical switches Membrane switches Capacitive switches Hall effect switches
Keyboard interfacing
Three major tasks:
Detect a key press. Debounce the key press. Encode the key press.
Key debounce
Stepper motor interfacing
Stepper motor interfacing
Stepper motor interfacing
Motion Clock wise Step 1 2 3 4 5 Anti clockwise 1 2 3 A 1 0 0 0 1 1 0 0 B 0 1 0 0 0 0 0 0 C 0 0 1 0 0 0 0 1 D 0 0 0 1 0 0 1 0
4 5
0 1
1 0
0 0
0 0
Stepper motor interfacing
Design a stepper motor and write an ALP to rotate shaft of 4-phase stepper motor.
In clock wise 5 rotations In anti clock wise 5 rotations The port A address is 0740h. The stepper motor has 200 rotor teeth. PA0 drives winding Wa(winding a), winding Wb, and so on. It has an internal delay of 10ms.
Stepper motor interfacing