Design of handshake mode
Design Of Handshake Mode 8255A Using 8086
Introduction:
8255 is a widely used general purpose programmable devices, can be compatible with any microprocessor. The 8255 includes three programmable ports, one of which can be used for bidirectional data transfer. This is an important additional feature in comparison with the 8155 I/O ports. The 8255 has 24 I/0 pins that can be grouped primarily in two 8 bit parallel ports. A & B, with the remaining eight bits as port c. the eight ports of port c can be used as individual bits or be grouped in two 4-bit ports. The figure shows all the functions of 8255, classified according to two modes: the BSR mode and I/P mode. The BSR mode is used to set or reset the bits in port c. the I/O mode is further divided into three modes : mode 0, mode 1 and mode 2. In mode 0, all the ports function as simple I/O ports. Mode 1, is a handshake mode where by ports A and/or B use bits from port C as handshake signals. In the handshake mode, two types of I/P data can be transferred implemented: status check and interrupt. In mode 2, port A can be set up for bidirectional data transfer using handshake signals from port C, and port B can be used to set up either in mode 0 or mode 1.
Programmable Parallel Ports And Handshake Input/Output:
We use port devices to input data and output data to the microprocessor. Most of the available port devices such as 8255A on the sdk-86 board, contain two or three ports which can be programmed to operate in one of the several different modes. The different modes allow us to see for many common types of parallel data transfer. Various methods of parallel input data transfer are
Simple Input/Output:
When we need to get the digital data from a simple switch such as thermostat into a microprocessor all we do is that we connect the switch to an input port line and read it anytime. Similarly when we need to output the data to a simple output device such as an LED, all we do is to connect the led buffer on an output port pin and output the logic level required to turn on the light. The led is always there and ready, so you can send data to it at any time.
Simple Strobe I/O:
In many applications, valid data is present on an external device only at a certain time, so it must be read in at that time. An example of this is the ascii-encoded keyboard. When key is pressed. Circuitry on the key board sends out the ascii code for the pressed key on eight parallel data lines, and then sends out a strobe signal on another line to indicate the valid data is present on the eight data lines. As shown in fig-4.9 we can connect this strobe line to an input port line and poll it to determine when we can put valid data from the keyboard. Another alternative is to connect the strobe line to an interrupt input of the processor and have an interrupt service procedure read in the data when the processor receives an interrupt. The point here is that this transfer is time dependent. We can read the data only when a strobe pulse tells us that the data is valid.
Fig 9 1b shows the timing waveforms which represent this type of operation. The sending device such as a keyboard, outputs parallel data on the data lines, and then outputs at the stb signal to let us know that the valid data is present. For low rates of data transfer such as from a keyboard to a microprocessor, a simple strobe transfer works well. However for higher data transfer speed this method does not work because there is no signal which tells the sending device when it is safe to send the next data byte. In other words, he sending system might send data bytes faster than the receiving system could read them. To prevent this problem a handshake data transfer scheme is used.
Single-Handshake I/O:
figure 9-2 shows the circuit connections and figure 91-c shows some example timing waveforms for a handshake data transfer from a peripheral device to a microprocessor. The peripheral outputs some parallel data and sends stb signal on a polled or interrupt basis and reads in the byte of data. Then the microprocessor sends a acknowledgement signal to the peripheral to indicate that the data has been read and the peripheral can send the next byte of data from the view point of the microprocessor this operation is referred to as handshake or strobe input. These same wave forms might represent a handshake output from a microprocessor to parallel printer. In this case the microprocessor outputs a character to the printer and asserts an stb signal to the printer to tell the printer , “ here is a character for you.†When the printer is ready it answers back with ack signal to tell the microprocessor, “ I got that one†send me another. The point of this handshake scheme is that the sending device or system is designed so that it does not send the next data byte until the receiving device or system indicates with an ack signal that it is ready to receive the next byte.
Double-Handshake Data Transfer:
For data transfers where even more coordination is required between the sending system and the receiving system a double handshake is used the sending device asserts its stb line low to ask “ are you ready� the receiving system raises its ack line high to say I m ready. The peripheral device then sends the byte of data and raises its stb line high to say I have the data thank you. And I wait your next request to send the next byte of data. For handshake output of this type from a microprocessor to a peripheral the waveforms are the same but the microprocessor sends the stb signal and the data the peripheral sends the ack signal. In the accompanying laboratory manual it is shown hoe to interface with a speech-synthesizer device using this type of handshake system.
Implementing Handshake Data Transfer:
For handshake data transfer a microprocessor can determine when it is time to send the next data byte on a polled or interrupt basis. The interrupt approach is usually used because it makes better use of the processors time. The stb or ack signal for these handshake transfers can be produced on a port pin by instructions in the program. However this method usually uses too much processor time, do parallel port devices such as the 8255A have been designed to automatically manage the handshake operation. The 8255A for example can be programmed to automatically receive an stb signal from a peripheral, send an interrupt signal to the processor and send the ack signal to the peripheral at the proper times.
8255A Internal Block Diagram And System Connections:
The diagram shows the internal structure of the 8255A. form the diagram it is observed that there are 24 input output lines. Port A can be used as an 8 bit input port or as an output port. Like port B can be used as an 8 bit input port or as an 8 bit output port. Port C can b used as an 8 bit input output port or as 4 bit port or to produce handshake signals for ports a nd b. the signal lines used to connect to the device to the system busses. 8 data lines allow us to write data bytes to a port or the control register and to read bytes from the port or the status register under the control of the rd wr lines. The address inputs A0 and A1 allow us to selectively access one of the three ports or the control register. The internal addresses for the device are port A 00, port B, 01; port C;10; control, 11. Asserting the cs input of the
8255A enables it for reading or writing. The cs input will be connected to the output of the address decoder circuitry to select the device when it is addressed. The reset input of the 8255A is connected to the system reset line so that, when the system is reset all the port lines are initialized as input lines.this is done to prevent destruction of circuitry connected to port lines. If port lines are initialized as outputs after a power up or reset the port might try to output to the output of the device connected to the port. The possible argument between the two outputs might destroy one or both of them. Therefore all the programmable port devices initialize their port lines as inputs when reset. The given figure shows that how a 8255 can be connected to a 8086, here one 8255 is connected to the lower half of the 8086 data bus and the other is conneceted to the upper half of the 8086. This is done so that byte can be transferred by enabling one device, or a word can be transferred by enabiling both devices at the same time. According to truth table for the input output port address decoder the A40 8255A on the lower half of the data bus will be enabled for a base address of FFF8H, and the A35 8255A will be enabled for a base address of FFF9H. another point to notice is that system address line A1 is connected to the 8255A A0 inputs, and system address line A2 is connected to the 8255A A1 inputs. With these connections the system address for the three ports and the control register in the A 40 8255A will be FFF8H, FFFAH, FFFCH, FFFEH. Likewise the system address for three ports and the control register of the A 35 8255A are FFF9H, FFFBH, FFFDH, and FFFFH.
8255a Operational Modes And Initiallization:
MODE 0:
When we want to see the port for simple input or output without handshaking we initialize the port in mode 0. If both port A and port B are initialized in mode 0, then the two halves of port c can be used together as an additional 8-bit port or they can be used individually as two 4 bit ports. When used as outputs, the port c lines can be individually set or reset by sending a special control word to the control register address. The two halves of port C are independent so one half can be initialized as input and the other half as output.
MODE 1:
When we want to use port A or port B for handshake input or output operation. We initialize that the port in MODE 1. In this mode some of the pins in port C function as handshake lines. Pins PCO, PC1 and PC2 function as handshake lines for port B if it is initialized in MODE1. If port A is initialized as handshake mode input port then pins PC3,PC4,and PC5 function as handshake signals. Pins PC6 and PC7 are avalible for use as input lines and output lines. If port A is initialized as a handshake output port, then port c pins PC3,PC6,PC7 function as handshake signals. Port c pins PC4 and PC5 are available for use as input or output lines. Since the 8255 often used in mode 1.
MODE 2:
Only port a can be initialized in mode 2 port a can be used for bidirectional handshake data transfer. This means that data can be output or input on the same eight lines. The 8255A might be used in this mode to extend the system bus to slave microprocessor or to transfer data bytes to and from a floppy disk controller board. If port A is initialized in MODE 2 then PINS PC3 through PC7 are used as handshake lines in port A. the other three pins PC0 through PC2 can be used for input output if port B is in mode 0. The three pins will be used for port B handshake lines if port b is initialized in mode 1.
Constructing And Sending 8255A Control Words:
Figure 9-5 shows the formats for the two 8255A control words. Note that the msb of the control word tells the 8255A which control word your are sending it. We use the mode definition control word format to tell the device what modes we want the ports to operate in. we use the bit set /reset control word format . we want to set or reset the output on a pin of port c or when we want to enable the interrupt output signals for the handshake data transfers. Both control words are sent to the control register address of the 8255A. as usual, initializing a device such as this consists of working our way through the steps as described already. As an example for this device suppose that we want to initialize the 8255A in figure 7-8 as follows.
Port B as mode 1 input
Port A mode 0 output
Port C upper as inputs
Port C bit 3 as output
The base address of the A40 8255A is FFF8H, and the control register address is FFFEH. The next step is to make up the control by figuring out what to put in each of the little boxes, one bit at a time. Figure 9-6a shows the control word which will program the 8255A as desired for this example. The figure alsi shows how we should document any control words to make for use in our programs using figure 9-5 a work our way through this word to make sure we see why each bit has the value it does. To send the control word we load the control word in AL with a MOV AL,10001110B instruction point DX at the
port address with the MOV DX,0FFFEH instruction and send the control word to the 8255A control register with the out DX, AL instruction. An example of how to use the bit set/reset control word suppose that we want to output a 1 to (set) bit 3 of port c, which was initialized as an output with the mode set control word above. To set or reset a port c output pin, we use the bit set/reset control word shown in figure. Make bit d7 to 0 to identify this as a bit set/reset control word and put a 1 in bit d0 to specify that we want to set a bit of port c. bits d2 d3 and d1 are used to tell the 8255A which bit we want to act on. For this example we want to set bit 3 so we put 011 in these three bits. For simplicity and compatibility with future products make the other 3 bits of the control words 0. The result 00000111B is shown with proper documentation in the figure. To send this control word to the 8255A simply load it into AL with the MOV AL,00000111B instruction, point dx at the control register address with the MOV DX ,0FFFEH instruction if DX is not already pointing there, and send the control word with the OUT DX,AL instruction.
8255A Handshake- Interfacing To A Microcomputer- Controlled Lathe:
All the machines in the machine shop of our computer controlled electronics factory operate under microcomputer. One example of these machines is a lathe which makes bolts for long rods of stainless steel. The cutting instructions of each type of bolt that we need to make are stored on ¾ in wode teletype like metal tape. Each instruction is represented by a series of holes in the tape. A tape reader pulls the through an optical or mechanical sensor to detect the hole patterns and converts these to an 8 bit parallel code. The microcomputer reads the instruction codes for the tape reader on a handshake basis and sends the appropriate control instructions to the lathe. The microcomputer must also monitor various conditions around the lathe. It must, for example make sure the lathe has cutting lubricant oil, is not out of material to work on, and is not jammed up in some way. Machines that operate in this way are often referred to as computer numerical control or CNC machines.
The figure given shows from how we might use an 8255A to interface a microcomputer to the tape reader and lathe. Our first task is to make up the control word which will initialize the 8255A In the correct modes for this application. To do this start by making a list showing how we want each port or group of pins to function. Then put in the control word bits that implement those pin functions.
Port A needs to be initialized for handshake input ( mode 1 ) because instruction codes have to be read in from the tape reader on the handshake basis.
Port B needs to be initialized for simple output (mode 0) no handshaking is needed here because this port is being used to output simple on or off control signals to the lathe.
Port C , bits pc0 pc1 and pc2 are used for simple input of sensor signals for the lathe.
Port C bits pc3 pc4 and pc5 function as the handshake signals for the data transfer from thr tape reader connected to port A.
Port C bit pc6 is used for output of the stop/go signal to the tape reader.
Port C bit pc7 is not used for this example.
Figure 9-b shows the control word to initialize the 8255A for these pin functions. We send this word to the control register address of the 8255A.In order for the handshake input data transfer from the tape reader to work correctly , the interrupt request signal from bit pc3 has to be enabled. This is done by sending a bit set/reset control word for the appropriate bit of port c. fig 9-9 shows the port c bit that must be set to enable the interrupt output signal for each of the 8255A handshake modes. For example here port A is being used for handshake input, so according to figure 9-9 port C bit pc4 must be set to enable the interrupt output for this operation. The bit set/reset control word to do this is 00001001B. we send this bit set/reset control word to the control address of the 8255A.
Handshake data transfer from the tape reader to the 8255A can be stopped by disabling the 8255A interrupt output on port C, pin c3. This is done by reseting bit pc4 with a bit set/reset control word of 00001000. As another example of 8255A interrupt output enabling suppose that we are using port B as handshake output port. According to figure 9-9 we need to set bit pc2 to enable the 8255A interrupt output signal. The bit set/reset control word to do this is 00000101. Now we see how the actual data transfer takes place in handshake mode for which the machine would operate.
After initializing everything we would probably read port C, bits pc0 pc1 and pc2 to check if the lathe was ready to operate. For any 8255A mode we read port C by simplt going an input from the port C address. Then we output a start command to the tape reader on the bit pc6.this is done with a bit set/reset command. Assuming that we want to reset bit pc6 to start the tape reader, the bit set/reset control word for this is 00001100. When the tape reader receives the go command. It will start the handshake data transfer to the 8255A.
The tape reader starts the process by sending out a byte of data by sending out a byte of data to port A on its eight data lines. The tape reader then asserts its stb line low to tell the 8255A that a new byte of data has been sent. In response the 8255A raises its input buffer full (IBF) signal on pc5 high to tell the tape reader that it is ready for the data. When the tape reader detects the IBF signal at a high level, it raises its stb signal high again. The rising edge of the stb signal has two effects on the 8255A. it first latches the data byte in the input latches of the 8255A. once the data is latched the tape reader can remove the data byte in preparation for sending the next data byte. This is shown by the dashed section on the right side of the data waveform in figure. The rising edge on the stb signal will cause the 8255A to output an interruot request signal in the microprocessor on bit pc3.
The processors response to the interrupt request will be to go to an interrupt service procedure which reads in the byte of data latched in port A. when the RD signal from the microprocessor goes low for this read of port A, the 8255A will automatically reset its interrupt request signa on pc3. This is done so that a second interrupt cannot be caused by the sane data transfer, when the processor raises its RD signal high again at the end of the read operation, the 8255A automatically drops its IBF signal on pc5 low again. IBF going low again is the signal to the tape reader that the data transfer is complete and that it can be send the next byte of data. The time between when the 8255A sends the interrupt request signal and when the processor reads the data byte from port A depends on when the processor gets around to servicing that interrupt. The point here is that this time doesn’t matter. The tape reader will not send the next byte until it detects the IBF signal has gone low again. The transfer cycle will then repeat for the next data byte. After the processor reads in the lathe control instruction byte from the tape reader, it will decode this instruction and output the appropriate control byte to the lathe on port B of the 8255A. the tape reader then sends the next instruction byte. If the instruction tape is made into a continuous loop, the lathe will keep making the specified parts until it runs out of material. The unused bit of port c , pc7 could be connected to a mechanism which loads In more material so the lathe can continue.
Parallel Printer Interface—Handshake Output Example:
This refers to the hardware connections and the software required to interface with a parallel printer in a system which does not have a BIOS procedure we can all to do the job. For most common printers such as IBM pc printers, the Epson dot matrix printers data to be printed is sent to the printers, and the Panasonic dot-matrix printers data printed is sent to the printer as ASCII characters on eight parallel lines. The printer receives the characters to be printed and stores them in an internal RAM buffer. When the printer detects a second carriage return, It prints out the second row of characters, etc. the process continues until all the desired characters have been printed.
Transfer of the ASCII codes from a microcomputer to a printer must be done on a handshake basis because the microcomputer can send characters much faster than the printer can print them. The printer must in some way let the microcomputer know that its buffer is full and that it cannot accept any more characters until ir prints some out. A common standard for interfacing with parallel printers is the centronics parallel interface standard, named for the company that developed it.
References:
Microprocessors and interfacing programming and hardware second edition by Douglas V. Hall TATA McGRAW-hill edition.
Microprocessor architecture, programming, and applications with the 8085 by Ramesh Gaonkar fifth edition, penram international publication
Fundementals of microprocessor and microcomputers byB. Ram, Dhanpat Raipublication.
Order Now