Microprocessor
8255- Programming
Dr.V.Jeyalakshmi.,
Professor/ECE
CEG, Anna University, Chennai
content
• Program to interface keys and display devices
• Program to initialize the BSR word
8255
CS
A1
A0
RD
WR
A7
A6
A5
A4
A3
A2 A1
A0
IOR
IOW Reset
Reset
Port A=80H
Control Register=83H
Port B=81H
Port C=82H
Do-D7
Do-D7
A7 A6 A5 A4 A3 A2 A1 A0
1 0 0 0 0 0 0 0 = 80H = Port A
0 1 = 81H = Port B
1 0 = 82H = Port C
1 1 = 83H = Control Register
Program 1
• Write a program to set Port A as input port
and set Port B as output port in mode1 of
8255
• Steps:
• Initialize the control word for Port A as input and
Port B as output in Mode1
• Calculate the port address for Port A, Port B and
Control register
• Select the instruction for Read and write operation
• Control Word
• D7 D6D5D4 D3 D2D1D0
1 0 1 1 0 1 0 0
B 4 = 84H
• Port address
Port A – 80H
Port B – 81H
Port C – 82H
Control register – 83H
I/O Mode
I/O Mode
• Program
MVI A, B4H -- Control Word
OUT 83H -- Control Register port Address
IN 80H -- Port A address
OUT 81H -- Port B address
HLT
Program 2
• Write a program to read DIP switches from
Group B and display the value in Group A in
mode0
Steps
• Calculate the port address
• Initialize the Control word
• Do the read and write operation
8255
CS
A1
A0
RD
WR
A7
A6
A5
A4
A3
A2
A1
A0
IOR
IOW
Reset
Reset
Buffer
Buffer
+5V
+5V
PA7
PA0
PC7
PC4
PC3
PC0
PB7
PB0
80H
82H
82H
81H
Do-D7
Do-D7
• Control Word
• D7 D6D5D4D3 D2D1D0
1 0 0 0 0 0 1 1
8 3 = 83H
• Program
MVI A, 83H -- Control Word
OUT 83H -- Control Register port Address
IN 81H -- Port B address
OUT 80H -- Port A address
IN 82H -- Port C address
ANI OFH – Mask the upper four bits
RLC
RLC convert upper 4 bits to lower 4 bits (nibbles)
RLC PCU PCL
RLC
OUT 82H -- Port C address
HLT
Program 3
• Write the program to clear the PC3 and set
PC6 of 8255.
Steps:
• Calculate the port address
• Write BSR control word to set PC3 and to
clear PC6
• Select the write operation
• BSR Control Word to clear PC3
D7 D6D5D4 D3D2D1 D0
0 0 0 0 0 1 1 0
0 6 = 06H
• BSR Control Word to set PC6
D7 D6D5D4 D3D2D1 D0
0 0 0 0 1 1 0 1
0 D = 0DH
• Program
MVI A, 06H -- Control Word to clear PC3
OUT 83H -- Control Register port Address
MVI A, ODH -- Control Word to set PC6
OUT 83H -- Control Register port Address
HLT
Review of Importance
• The main function of Control word and the
BSR were implemented with the simple
programming. How to get the value from the
Keys or switches and how to store and
display in LEDs were discussed with simple
example programs. The calculation of port
addresses from the interfacing and the bit set
or reset of PortC illustrated with simple
program
Questions
• Write the control word to set all ports as
input port in mode0
• Write the program to read the data from
portC upper to lower
• Write the BSR to set the 4,5,6 bit position of
portC
Synopsis
• The initialization of Control word and the BSR
control word were implemented with the
simple programming. The processor
interfaced with peripherals like the input
devices (switch or key) were read and the
some data were written into the output
device (LEDs) executed with programming.
The calculation of port addresses from the
interfacing and how to use in the program
were discussed.
Keywords
• Control word
• BSR control word
• Port address
• Program
Program 4
• Write a program to set PC4 for 4 ms and then
reset the bit in 8255
Steps:
• Calculate the port address
• Write the BSR word
• Do the write operation
• Set count value for 4ms
• BSR Control Word to set PC4
D7 D6D5D4 D3D2D1 D0
0 0 0 0 1 0 0 1
0 9 = 09H
• Program
MVI A, 09H -- BSR Word to set PC4
OUT 83H -- Control Register port Address
CALL Delay – delay for 2ms
MVI A, O8H -- BSR Word to clear PC4
OUT 83H -- Control Register port Address
HLT
Delay program
MVI C,
L1 DCR C
JNZ L1
RET
PROGRAM 5
Design a counter with 2 ms delay and set port B
to display the value.
Steps:
• Calculate the port address
• Write the control word
• Do the write operation
• Set count value for 2ms
• Program
MVI A, 80H -- Control Word
OUT 83H -- Control Register port Address
MVI B, OAH -- initialize the counter value
L1 MOV A,B
OUT 81H -- Port B address
CALL DELAY -- Delay for 2 ms
DCR B -- for next counter value
JNZ L1
HLT -- stop the program
DELAY
LXI B, 011EH -- initialize the delay/ counter value
L2 DCX B
MOV A,C -- decrement till zero
ORA B
JNZ L2
RET
Time delay
• Delay program for 8 bit
MVI C, FFH 7T TO
LOOP DCR C 4T
JNZ LOOP 10T TL = 14T
• Time Delay (Td) = [To +(TL *N10)-3]T
= [ 7 +(14 *255)-3] 0.5 *10-6
= 1792µsec
Time delay
• Delay program for 16 bit
LXI B,FFFFH 10 T TO
LOOP DCX B 6T TL = 24T
MOV A,C 4T
ORA B 4T
JNZ LOOP 10T
• Time Delay (Td) = [To +(TL *N10)-3]T
= [ 10 +(24 *65535)-3] 0.5 *10-6
= 78642µsec
• Time delay for 2ms
Time Delay (Td) = [To +(TL *N10)-3]T
2ms = [ 10+(24 *N10) -3]*0.5* 10-6
N10 = 2 * 10-3 -20 +3
0.5* 10-6 24
= 165 = A5H
• Time delay for 3ms
Time Delay (Td) = [To +(TL *N10)-3]T
3ms = [ 10+(24 *N10) -3]*0.5* 10-6
N10 = 3 * 10-3 -10 +3
0.5* 10-6 24
= 249 = F9H
• Time delay for 2ms
Time Delay (Td) = [To +(TL *N10)-3]T
2ms = [ 7+(14 *N10) -3]*0.5* 10-6
N10 = 2 * 10-3 -7 +3
0.5* 10-6 14
= 165 = A5H

8255 programming

  • 1.
  • 2.
    content • Program tointerface keys and display devices • Program to initialize the BSR word
  • 3.
    8255 CS A1 A0 RD WR A7 A6 A5 A4 A3 A2 A1 A0 IOR IOW Reset Reset PortA=80H Control Register=83H Port B=81H Port C=82H Do-D7 Do-D7 A7 A6 A5 A4 A3 A2 A1 A0 1 0 0 0 0 0 0 0 = 80H = Port A 0 1 = 81H = Port B 1 0 = 82H = Port C 1 1 = 83H = Control Register
  • 4.
    Program 1 • Writea program to set Port A as input port and set Port B as output port in mode1 of 8255 • Steps: • Initialize the control word for Port A as input and Port B as output in Mode1 • Calculate the port address for Port A, Port B and Control register • Select the instruction for Read and write operation
  • 5.
    • Control Word •D7 D6D5D4 D3 D2D1D0 1 0 1 1 0 1 0 0 B 4 = 84H
  • 6.
    • Port address PortA – 80H Port B – 81H Port C – 82H Control register – 83H
  • 7.
  • 8.
  • 9.
    • Program MVI A,B4H -- Control Word OUT 83H -- Control Register port Address IN 80H -- Port A address OUT 81H -- Port B address HLT
  • 10.
    Program 2 • Writea program to read DIP switches from Group B and display the value in Group A in mode0 Steps • Calculate the port address • Initialize the Control word • Do the read and write operation
  • 11.
  • 12.
    • Control Word •D7 D6D5D4D3 D2D1D0 1 0 0 0 0 0 1 1 8 3 = 83H
  • 13.
    • Program MVI A,83H -- Control Word OUT 83H -- Control Register port Address IN 81H -- Port B address OUT 80H -- Port A address IN 82H -- Port C address ANI OFH – Mask the upper four bits RLC RLC convert upper 4 bits to lower 4 bits (nibbles) RLC PCU PCL RLC OUT 82H -- Port C address HLT
  • 14.
    Program 3 • Writethe program to clear the PC3 and set PC6 of 8255. Steps: • Calculate the port address • Write BSR control word to set PC3 and to clear PC6 • Select the write operation
  • 15.
    • BSR ControlWord to clear PC3 D7 D6D5D4 D3D2D1 D0 0 0 0 0 0 1 1 0 0 6 = 06H
  • 16.
    • BSR ControlWord to set PC6 D7 D6D5D4 D3D2D1 D0 0 0 0 0 1 1 0 1 0 D = 0DH
  • 17.
    • Program MVI A,06H -- Control Word to clear PC3 OUT 83H -- Control Register port Address MVI A, ODH -- Control Word to set PC6 OUT 83H -- Control Register port Address HLT
  • 18.
    Review of Importance •The main function of Control word and the BSR were implemented with the simple programming. How to get the value from the Keys or switches and how to store and display in LEDs were discussed with simple example programs. The calculation of port addresses from the interfacing and the bit set or reset of PortC illustrated with simple program
  • 19.
    Questions • Write thecontrol word to set all ports as input port in mode0 • Write the program to read the data from portC upper to lower • Write the BSR to set the 4,5,6 bit position of portC
  • 20.
    Synopsis • The initializationof Control word and the BSR control word were implemented with the simple programming. The processor interfaced with peripherals like the input devices (switch or key) were read and the some data were written into the output device (LEDs) executed with programming. The calculation of port addresses from the interfacing and how to use in the program were discussed.
  • 21.
    Keywords • Control word •BSR control word • Port address • Program
  • 22.
    Program 4 • Writea program to set PC4 for 4 ms and then reset the bit in 8255 Steps: • Calculate the port address • Write the BSR word • Do the write operation • Set count value for 4ms
  • 23.
    • BSR ControlWord to set PC4 D7 D6D5D4 D3D2D1 D0 0 0 0 0 1 0 0 1 0 9 = 09H
  • 24.
    • Program MVI A,09H -- BSR Word to set PC4 OUT 83H -- Control Register port Address CALL Delay – delay for 2ms MVI A, O8H -- BSR Word to clear PC4 OUT 83H -- Control Register port Address HLT
  • 25.
    Delay program MVI C, L1DCR C JNZ L1 RET
  • 26.
    PROGRAM 5 Design acounter with 2 ms delay and set port B to display the value. Steps: • Calculate the port address • Write the control word • Do the write operation • Set count value for 2ms
  • 27.
    • Program MVI A,80H -- Control Word OUT 83H -- Control Register port Address MVI B, OAH -- initialize the counter value L1 MOV A,B OUT 81H -- Port B address CALL DELAY -- Delay for 2 ms DCR B -- for next counter value JNZ L1 HLT -- stop the program DELAY LXI B, 011EH -- initialize the delay/ counter value L2 DCX B MOV A,C -- decrement till zero ORA B JNZ L2 RET
  • 28.
    Time delay • Delayprogram for 8 bit MVI C, FFH 7T TO LOOP DCR C 4T JNZ LOOP 10T TL = 14T
  • 29.
    • Time Delay(Td) = [To +(TL *N10)-3]T = [ 7 +(14 *255)-3] 0.5 *10-6 = 1792µsec
  • 30.
    Time delay • Delayprogram for 16 bit LXI B,FFFFH 10 T TO LOOP DCX B 6T TL = 24T MOV A,C 4T ORA B 4T JNZ LOOP 10T
  • 31.
    • Time Delay(Td) = [To +(TL *N10)-3]T = [ 10 +(24 *65535)-3] 0.5 *10-6 = 78642µsec
  • 32.
    • Time delayfor 2ms Time Delay (Td) = [To +(TL *N10)-3]T 2ms = [ 10+(24 *N10) -3]*0.5* 10-6 N10 = 2 * 10-3 -20 +3 0.5* 10-6 24 = 165 = A5H
  • 33.
    • Time delayfor 3ms Time Delay (Td) = [To +(TL *N10)-3]T 3ms = [ 10+(24 *N10) -3]*0.5* 10-6 N10 = 3 * 10-3 -10 +3 0.5* 10-6 24 = 249 = F9H
  • 34.
    • Time delayfor 2ms Time Delay (Td) = [To +(TL *N10)-3]T 2ms = [ 7+(14 *N10) -3]*0.5* 10-6 N10 = 2 * 10-3 -7 +3 0.5* 10-6 14 = 165 = A5H