Вы находитесь на странице: 1из 28

INTRODUCTION TO INTERFACING

UNIT 5: INTRODUCTION TO INTERFACING

INTRODUCTION:
A microprocessor is great at solving problems, but if it cant communicate with the outside world, it is a little worth. This module outlines some of basic methods of communication both serial and parallel, between human and microprocessor. The following topics are covered here :

1. Serial and parallel port 2. Application of serial and parallel ports(RS232 etc)

LEARNING OBJECTIVES:
The objectives of this topic are to:

1. Introduce the operation of the basic input output device. 2. Define handshaking and explain how to it with many I/O devices. 3. Interface and program the 8255 programmable parallel interface component.

LEARNING OUTCOMES:
After completed this module trainees should be able to :
1. Explain the operation input/output device. 2. Interface and program the 8255 programmable parallel interface component. 3. Interface and program 8251 UART 4. Know the interfacing port in microcomputer 5. Describe connectors and port in computer system

KKTMPJ

174

INTRODUCTION TO INTERFACING

5.1 SERIAL AND PARALLEL PORTS


5.1.1 Parallel Data Transfer : The 8255 PPI

Introduction
The 8255 programmable peripheral interface (PPI) is a very popular low-cost interfacing component found in many applications. The PPI has 24 pins for I/O, programmable in groups of 12 pins, that are used in three separate modes of operation. The 8255 is used for interface to the keyboard and the parallel printer port in many of these personal computers. It also controls the timer and reads data from the keyboard interface.

Basic Description of the 8255


Figure 5.0 shows a diagram of the 8255 and its I/O and control signals. Twenty-four of the 8255s 40 pins are dedicated to the three programmable ports A, B and C. These three ports, and a fourth one called a control port, are accessed via RD, WR, CS, and address lines A 0 and A 1 . A RESET input is included to initialize the 8255 when power is first applied. . Table 5.1 shows the I/O port assignments used for programming and access to the I/O ports.

Figure 5.0 : Interfacing the 8255 PPI

KKTMPJ

175

INTRODUCTION TO INTERFACING

A1 0 0 1 1

A0 0 1 0 1

Function Port A Port B Port C Command register

Table 5.1 : I/O port assignments for the 8255

The 8255 is fairly simple device to interface to the microprocessor and program. For the 8255 to be read or written, the CS input must be a logic 0 and the correct I/O address must be applied to the A1 and A0 pins. The remaining port address pins are dont cares as far as the 8255 is concerned, and are externally decoded to select the 8255.

The nicest feature of the 8255 is that different hardware circuits can be connected to ports A, B and C, with the direction (input or output) of each port configured with initial programming. This allows an 8088-based system with an 8255 in it to be used for many different purposes.

Programming the 8255


The 8255 has three modes of operation.

The first is mode 0: basic input/output.

In this mode, port A, B and C can be individually programmed as input or output ports. Port C is divided into two 4-bit halves, directionally independent from each other So, there are 16 combinations of input and output configurations available with this mode. A RESET automatically causes the 8255 to enter mode 0 with all ports programmed for input.

To program the 8255 for mode 0 operation and set the direction of each port, a mode word must be output to control port. The definition of the mode word is shown in Figure 5.2. The MSB is the mode-set flag, which must be a 1 to program the 8255. Bits 5 and 6 are used to select the 8255s mode. 00 selects mode 0, 01 selects mode 1, and mode 2 is selected when bit 6 is high. Bit 2 is also used as a select bit for modes 0 and 1. The other 4 bits set the direction of ports A and B and both halves of C. A0 indicates an output port and a 1 indicates an input port.
KKTMPJ 176

INTRODUCTION TO INTERFACING

Figure 5.2 : 8255 mode word format

To configure the 8255 for mode 0, all ports programmed for input, the mode word must be 10011011 (9BH). This byte must be output to the control port to configure the 8255. The following two instructions will initialize the 8255 after a reset:

MOV AL, 9BH OUT 0A3H,AL

Remember that the 8255 of Figure 5.0 has its control port at address A 3 . Assume that the 8255 has a DIP switch wired to port A and a set of LEDs wired to port B. The following code can be used to repeatedly read the switches and send their states to the LEDs.

READ :

MOV AL,99H OUT 0A3H, AL

; configure 8255 for A in , B out , mode 0 ; read switches ;send data to lights

GET :

IN AL,0A0H OUT 0A1H,AL JMP GET

KKTMPJ

177

INTRODUCTION TO INTERFACING

The next mode is mode 1 : strobed input/output.

In this mode, the 8255 uses port C as a handshaking port. Handshaking signals are commonly used in printers to sense the status of the paper-out sensor and the printers readiness to accept new data. Ports A and B can be programmed for input and output. Data are latched in both directions. If port A is programmed for input, a strobe signal is needed on PC 4 to write data into port A. The 8255 will acknowledge the new input data by outputting a 1 on PC 5 . These two signals on port C are defined as shown in Figure 5.3(a). PC5 is IBF a , input buffer A full. IBF is cleared when the processor reads port A. Port B operates in the same way, using PC 2 and PC1 as handshaking signals. Both ports have the capability of causing an interrupt when data are strobed into them. The INTR output will go high when IBF goes high and the internal interrupt-enable bit is set. PC4 will cause INTR a to go high when data are strobed into port A. Reading the input port will clear the interrupt request. This interrupt mechanism is a useful alternative to using software to constantly poll the input port. Polling wastes a lot of time waiting for input data that may not be there. Interrupting the processor only when new data have arrived results in more efficient program execution. This is one of the advantages of modes 1. As Figure 5.3(a) shows, PC 6 and PC 7 are available for general purpose I/O when port A is programmed for input. The mode word needed to program the 8255 for mode 1, Ain, Bin, and PC 6 and PC 7 out is B6. Figure 5.3(b) shows how the 8255 is configured for output in mode 1. It has output buffer full (OBF) and a acknowledge (ACK) signals used to handshake with the output circuitry. OBF will go low when the processor writes to port A or B. This signal will remain low until a low pulse arrives on ACK. ACK is used to indicate that the new output data were received. ACK, together with interrupt-enable, can be used to generate an interrupt with INTR. This would interrupt the processor when the new output data have been read, and avoid the need to poll the ACK signal. To program the 8255 for mode 1, Aout, and Bout, use mode word A 4 .

KKTMPJ

178

INTRODUCTION TO INTERFACING

Figure 5.3 : Mode 1 port definitions

The last mode is mode 2: strobed bidirectional I/O.

This mode allows port A to operate as an 8-bit bidirectional bus. This is needed to allow the 8255 to be interfaced with 8-bit peripherals such as UARTS, which require a bidirectional data bus. Bits in port C are again used for handshaking and general purpose I/O, as indicated by Figure 4.4. Port B can operate as an input port or output port in mode 0 or mode 1. When operating port B in mode 0 ( with port A in mode 2), PC 0 through PC 2 are available for general purpose I/O. The definitions for PC0 through PC 2 in mode 1 apply when port B is operated in mode 1 with port A in mode 2. As before, the INTR output can be used to interrupt the processor for input or output operations. When the CPU writes data to port A, OBF will go low. To enable the output buffer on port A and read the data, ACK must be pulled low. Data are written into port A by pulling STB low. This will cause IBF to go high until the data are read by the processor.

KKTMPJ

179

INTRODUCTION TO INTERFACING

5.1.2 Serial Data Transfer : The 8251 UART Introduction


Serial data transmission offers the convenience of running a small number of wires between two points (three will do the job in most cases), while at the same time being very reliable. Although we must wait longer to receive our data because it is transmitted only 1 bit at a time, we are able to place our communication devices (computers, terminals, and so on) far away from each other. Worldwide networks now exist, connected via satellites, implements serial data transmission in a variety of formats. The standard serial data transmission waveform for any UART is depicted in Figure 5.4.

Figure 5.4 : Standard TTL serial data waveform

Interfacing the 8251


The 8251 was originally designed to be used with the 8080 and 8085 microprocessors, 8 bit machines that preceded the 8088. The 8088 interfaces with the 8251 easily, requiring the usual address decoder and a few control signals. Figure 5.5 shows a complete serial data circuit for the 8088. The 8251 is connected to the processors data bus and IORC and IOWC signals. Because these signals are active only during I/O operations, the address decoder need only examine the state of the address bus. The NAND gate recognizes port addresses 78H and 79H. Address line A 0 is not used in the decoder. Instead, it is connected to the 8251s C/D input. This pin selects internal control or data registers. So, if A 0 is low (port 78H) and IORC is active, the UARTs receive register will be read. If IOWC is active with A 0 low, the UARTs transmitter register will be written to and a new transmission started.

KKTMPJ

180

INTRODUCTION TO INTERFACING

Figure 5.5 : 8251 to 8088 interface

The control functions are selected when A 0 is high (port 79H). Reading form port 79H gets 1 byte of status information; writing to it selects functions such as data size and used when the 8251 is connected to a modem. They are grounded to keep them enable. TxC and RxC are the transmitter and receiver clocks. The frequency of the TTL signal at these inputs determines the bit rate and time of the transmitter and receiver. It is common to run the UART at a clock speed 16 times greater than the baud rate. So, a 2400 baud transmission rate requires a 38.4 kHz clock (multiply 2400 by 16). This frequency and other standard baud rate frequencies are generated automatically by the 14,411 baud-rate generator. All that is needed is a 1.8432 MHz crystal. Attempting to transmit a digital (0-5 V) signal over a long length of wire causes distortion in the signal shape due to the line capacitance. It was discovered that making
KKTMPJ 181

INTRODUCTION TO INTERFACING

the signal switch form a positive voltage to a negative voltage helps to eliminate the distortion. Higher baud rates are possible using the +/-swigging signal. A standard was developed for this type for signal, called the RS232C standard. Take another look at the waveform in Figure 5.4. This is the TTL waveform that comes out of UARTs transmitter. The RS232 waveform that gets transmitted over the wires is inverted and swings plus and minus. So, a high level on the TTL waveform creates a low (negative) level on the An integrated circuit capable of performing the RS232C-to-TTL

RS232Cwaveform.

conversions is the MAX23CPE. This chips, such as the 1488 line driver and 1489 line receiver, required additional external power supplies. The MAX232 has two separate RS232C drivers/receivers for systems requiring two serial data channels.

Programming the 8251


Because the 8251 is connected to RESET, we are assured that the 8251 is functional after a power-on. It is still necessary to program the 8251 to ensure that the correct number of data bits will be used, that the parity will be generated as expected, and so on. To program the 8251, a series of bytes are output to the control port (79H from our example). The first byte is called the mode instruction. The format of this byte is shown in Figure 5.6. The 8251 can operate in asynchronous mode or synchronous mode. In asynchronous mode, the baud rate is determined by the lower 2 bits in the mode instruction. If these 2 bits are low, synchronous mode is selected.

KKTMPJ

182

INTRODUCTION TO INTERFACING

Figure 5.6 : 8251 mode instruction format The number of data bits used in a transmission is selected by bits 2 and 3. To enable generation of a parity bit, bit 4 must be set. Odd or even parity is chosen by the setting of bit 5. Finally, the number of stop bits is chosen by the upper 2 bits in the mode instruction. The waveform of Figure 5.4 contained 7 data bits, an even parity bit, and two stop bits. The required mode instruction byte is FA. To program the 8251, use:

MOV AL,0FAH OUT 79H, AL

Because an X16 clock was selected, the 8251 will operate in asynchronous mode. Synchronous mode is used for high-speed data transmission (not usually needed for communication with a serial display terminal). Synchronous mode is selected by making the lower two mode instruction bits. In this case, the upper two mode instruction bits do

KKTMPJ

183

INTRODUCTION TO INTERFACING

not set the number of stop bits, but rather the number of sync characters transmitted and the function is the SYNDET pin.

A second byte must be output to the control port to complete the initialization of the 8251. This byte is called the command instruction. The bits are assigned as shown in Figure 5.7; they have the following meanings.

Bit 0 :
Bit 1 :

transmit enable. Enable transmitter when this bit is set. data terminal ready. Setting this bit will will force the DTR output low. receive enable. Enable receiver when this bit is set send break character. Setting this bit forces TxD low error reset. Setting this bit clears the PE, OE, and FE error flags. request to send. Setting this bit forces the CTS output low. internal reset. To reset the 8251 and prepare for a new mode instruction this bit must be set.

Bit 2 Bit 3 Bit 4 Bit 5 Bit 5

: : : : :

Bit 6

internal reset. To reset the 8251 and prepare for a new mode instruction, this bit must be set.

Bit 7

enter hunt mode. Setting this bit enables a search for SYNC characters (in synchronous mode only).

Figure 5.7 : 8251 command instruction format

The command instruction needed to enable the transmitter and receiver and ignore all other functions is 05H. This byte must be output to the control port after the mode

instruction. So, to totally initialize the 8251 for operation in the circuit of Figure 5.5, we need these instructions:

MOV AL, 0FAH OUT 79H, AL MOV AL,05H OUT 79H, AL


KKTMPJ

; mode instruction

; command instruction

184

INTRODUCTION TO INTERFACING

Once the UART has been programmed we have no need for the control port. Instead, we use the 82512 status port to help control the way data are transmitted and received. Figure 5.8 shows the bit assignments in the 8251s status port. Particularly important are the TxRDY (transmitter ready) and RxRDY (receiver ready) flags. They tell us when the transmitter is ready to transmit a new character and when the receiver has received a complete character. A number of error bits are included to show what may have given wrong with the last reception. PE is parity error, and will go high fi the parity of the received character is wrong. OE is overrun error, and will be set if a new characterize received before the processor read the last one. FE stands for framing error, and goes high when stop bits are not received in synchronous mode. DSR (data set ready) will go high whenever DSR is low.

Figure 5.8 : 8251 status byte

The programmer must use the 8251s status bits to ensure proper serial data communication. Figure 5.9 shows how the first two bits are used to implement a simple serial input/output procedure. Both flowcharts indicate that repeated testing of the RxRDY/TxRDY bits may be necessary. For example, to show the importance of this repeated testing, consider the following case. Suppose that an 8251 is configured to transmit and receive data at 1200 baud, with 7 data bits, odd parity, and 1 stop bit. How long does it take to fully transmit or receive a character? At 1200 baud, the bit time is just over 833 us, and the selected word length of 10 bits makes the total time to receive or transmit a single character roughly 8.3 ms. It is not difficult to imagine how many instructions the 8088 might be able to execute in 8.3 us. Would a few thousand be unreasonable? Probably not. Therefore, we use the status bits to actually slow down the 8088, so that it does not try to send or receive data from the 8251 faster than the 8251 can handle. The two short routine is used to read a character from the receiver, returning it in AL. It is necessary to check the state of RxRDY before reading the receiver.
KKTMPJ 185

INTRODUCTION TO INTERFACING

Figure 5.9 : I/O flowcharts

CHARACTER INPUT

CHARIN RSTAT:

PROC IN

FAR AL, 79H ; ; ; ; ; read UART status examine RxRDY wait until receiver is ready read receiver ensure 7 bit ASCII code

AND AL,02H JZ IN RSTAT AL, 78H

AND AL, 7FH RET CHARIN ENDP

KKTMPJ

186

INTRODUCTION TO INTERFACING

The data byte received is ANDed with 7F to clear the MSB. Because the UART is being used for character transmission, only a 7-bit ASCII code is required.

CHARACTER OUTPUT
This routine checks to see if the transmitter is ready for a new character. If it is, the ASCII character stored in AL is output to the transmitter.

CHAROUT TSTAT:

CHAROUT

PROC MOV IN AND JZ MOV OUT RET ENDP

FAR AH,AL AL, 79H AL, 1 TSTAT AL, AH 78H, AL

; ; ; ; ;

save character read UART status wait until transmitter is ready get character back output to transmitter

KKTMPJ

187

INTRODUCTION TO INTERFACING

5.2 APPLICATION OF SERIAL AND PARALLEL PORT


5.2.1 Application of Serial Port
Considered to be one of the most basic external connections to a computer, the serial port has been an integral part of most computers for more than 20 years. Although many of the newer systems have done away with the serial port completely in favor of USB connections, most modems still use the serial port, as do some printers, PDAs and digital cameras. Few computers have more than two serial ports.

Figure 5.10 Two serial ports on the back of a PC

Essentially, serial ports provide a standard connector and protocol to let you attach devices, such as modems, to your computer., you will learn about the difference between a parallel port and a serial port, what each pin does and what flow control is.

The external connector for a serial port can be either 9 pins or 25 pins. Originally, the primary use of a serial port was to connect a modem to your computer. The pin assignments reflect that. Let's take a closer look at what happens at each pin when a modem is connected.

KKTMPJ

188

INTRODUCTION TO INTERFACING

Figure 5.11

9-pin connector:
1. Carrier Detect - Determines if the modem is connected to a working phone line. 2. Receive Data - Computer receives information sent from the modem. 3. Transmit Data - Computer sends information to the modem. 4. Data Terminal Ready - Computer tells the modem that it is ready to talk. 5. Signal Ground - Pin is grounded. 6. Data Set Ready - Modem tells the computer that it is ready to talk. 7. Request To Send - Computer asks the modem if it can send information. 8. Clear To Send - Modem tells the computer that it can send information. 9. Ring Indicator - Once a call has been placed, computer acknowledges signal (sent from modem) that a ring is detected.

KKTMPJ

189

INTRODUCTION TO INTERFACING

25-pin connector:
1. Not Used 2. Transmit Data - Computer sends information to the modem. 3. Receive Data - Computer receives information sent from the modem. 4. Request To Send - Computer asks the modem if it can send information. 5. Clear To Send - Modem tells the computer that it can send information. 6. Data Set Ready - Modem tells the computer that it is ready to talk. 7. Signal Ground - Pin is grounded. 8. Received Line Signal Detector - Determines if the modem is connected to a working phone line. 9. Not Used: Transmit Current Loop Return (+) 10. Not Used 11. Not Used: Transmit Current Loop Data (-) 12. Not Used 13. Not Used 14. Not Used 15. Not Used 16. Not Used 17. Not Used 18. Not Used: Receive Current Loop Data (+) 19. Not Used 20. Data Terminal Ready - Computer tells the modem that it is ready to talk. 21. Not Used 22. Ring Indicator - Once a call has been placed, computer acknowledges signal (sent from modem) that a ring is detected. 23. Not Used 24. Not Used 25. Not Used: Receive Current Loop Return (-) Voltage sent over the pins can be in one of two states, On or Off. On (binary value "1") means that the pin is transmitting a signal between -3 and -25 volts, while Off (binary value "0") means that it is transmitting a signal between +3 and +25 volts...

KKTMPJ

190

INTRODUCTION TO INTERFACING

5.2.2

Application of Parallel Port


If you have a printer connected to your computer, there is a good chance that it

uses the parallel port. While USB is becoming increasingly popular, the parallel port is still a commonly used interface for printers.

Figure 5.12 A typical parallel port on the back of your computer Parallel ports can be used to connect a host of popular computer peripherals:
Printers Scanners CD burners External hard drives Iomega Zip removable drives Network adapters Tape backup drives

Parallel port is a very commonly known port, widely used to connect the printer to the PC. If you see backside of your computer, there will be a port having 25 pins with a small symbol like this:. That port is known as LPT port or printer port. We can program this port for device control and data transfer. In this article, we will learn basics of parallel port and programming the parallel port.

KKTMPJ

191

INTRODUCTION TO INTERFACING

Parallel port basics:


In computers, ports are used mainly for two reasons: Device control and communication. We can program PC's Parallel ports for both. Parallel ports are mainly meant for connecting the printer to the PC. But we can program this port for many more applications beyond that. Parallel ports are easy to program and faster compared to the serial ports. But main disadvantage is it needs more number of transmission lines. Because of this reason parallel ports are not used in long distance communications. Let us know the basic difference between working of parallel port and serial port. In serial ports, there will be two data lines: One transmission and one receive line. To send a data in serial port, it has to be sent one bit after another with some extra bits like start bit, stop bit and parity bit to detect errors. But in parallel port, all the 8 bits of a byte will be sent to the port at a time and a indication will be sent in another line. There will be some data lines, some control and some handshaking lines in parallel port. If three bytes of data 01000101 10011100 10110011 is to be sent to the port, following figures will explain how they are sent to the serial and parallel ports respectively. We can understand why parallel port communication is faster compared to that of serial. In computers, ports are used mainly for two reasons: Device control and communication. We can program PC's Parallel ports for both. Parallel ports are mainly meant for connecting the printer to the PC. But we can program this port for many more applications beyond that.

KKTMPJ

192

INTRODUCTION TO INTERFACING

Parallel Port: Data transmission is byte wise: Whole byte at a time.

Figure 5.13

In the PC there will be D-25 type of female connector having 25 pins and in the printer, there will be a 36-pin Centronics connector. Connecting cable will combine these connecter using following convention. Pin structure of D-25 and Centronics connecters are explained bellow.

KKTMPJ

193

INTRODUCTION TO INTERFACING Centronics D25- Pin 36 Pin Number Number 1 1 2 to 9 10 11 12 13 14 15 16 17 18 to 25 -

Function Strobe Data Lines Acknowledgement Busy Out of Paper Select Auto feed Error Init Select In GND N/C

2 to 9
10 11 12 13 14 15, 32 16, 31 17, 36 18 to 30, 33 34, 35

Table 5.0: Pin numbers and functions

Now let us know how communication between PC and printer takes place. Computer places the data in the data pins, then it makes the strobe low. When strobe goes low, printer understands that there is a valid data in data pins. Other pins are used to send controls to the printer and get status of the printer, you can understand them by the names assigned to the pins. To use the printer port for applications other than printing, We need to know how ports are organized. There are three registers associated with LPT port: Data register, Control register and Status register. Data register will hold the data of the data pins of the port. That means, if we store a byte of data to the data register, that data will be sent to the data pins of the port. Similarly control and status registers. The following table explains how these registers are associated with ports.

KKTMPJ

194

INTRODUCTION TO INTERFACING

Pin No (D-Type 25) SPP Signal 1* 2 3 4 5 6 7 8 9 10 11* 12 13 14* 15 16 17* 18 - 25

nStrobe Data 0 Data 1 Data 2 Data 3 Data 4 Data 5 Data 6 Data 7 nAck Busy Paper-Out / Paper-End Select nAuto-Linefeed nError / nFault nInitialize nSelect-Printer/ nSelectIn/Out In Ground Gnd

Direction In/out In/Out In/Out In/Out In/Out In/Out In/Out In/Out In/Out In/Out In In In In In/Out In In/Out

Register.bit Control.0 Data.0 Data.1 Data.2 Data.3 Data.4 Data.5 Data.6 Data.7 Status.6 Status.7 Status.5 Status.4 Control.1 Status.3 Control.2 Control.3

Table 5.1: Pin directions and associated registers. * Pins with * symbol in this table are hardware inverted. Than means, If a pin has a 'low' ie. 0V, Corresponding bit in the register will have value 1. Signals with prefix 'n' are active low. That means, Normally these pins will have low value. When it needs to send some indication, it will become high. For example: Normally nStrobe will be high, when the data is placed in the port, computer makes that pin low. Normally, data, control and status registers will have following addresses. We need these addresses in programming later.
Register Data register (Base Address + 0) Status register (Base Address + 1) Control register (Base Address + 2) LPT1 0x378 0x379 0x37a LPT2 0x278 0x279 0x27a

KKTMPJ

195

INTRODUCTION TO INTERFACING

Note: All the parallel ports do not have bidirectional capability. Earlier parallel ports had only output enabled in data pins since printers only inputs data. But latter, to make parallel port capable of communicating with other devises, bidirectional ports are introduced. By default, data port is output port. To enable the bidirectional property of the port, we need to set the bit 5 of control register. To know the details of parallel ports available in your computer, follow this procedure: 1. Right click on My Computer, go to "Properties". 2. Select the tab Hardware, Click Device manager. 3. You will get a tree structure of devices; In that Expand "Ports(Com1 & LPT)". 4. Double Click on the ECP Printer Port(LPT1) or any other LPT port if available. 5. You will get details of LPT port. Make sure that "Use this Port (enable)" is selected. 6. Select tab recourses. In that you will get the address range of port. To start programming, you will need a D-25 type Male connector. Its pin structures can be found in the connector as follows:

Programming the printer port in DOS:


To start programming the port, we will use DOS. In DOS we have commands to access the port directly. But, these programs will not work on the systems based on Windows XP, Windows NT or higher versions. For security reason, higher versions of the windows does not allow accessing the port directly. To program the parallel port in these systems, we need to write kernel mode driver.

KKTMPJ

196

INTRODUCTION TO INTERFACING

When we want to find out whether particular pin of the port is high or low, we need to input the value of corresponding register as a byte. In that, we have to find out whether the corresponding bit is high or low using bitwise operators. We can't access the pins individually. So, you need to know basic bitwise operations. Main bitwise operators that we need are bitwise AND '&' and bitwise OR '|'. To make a particular bit in a byte high without affecting other bits, write a byte with corresponding bit 1 and all other bits 0; OR it with original byte. Similarly, to make particular bit low, write a byte with corresponding bit 0 and all other bits 1; AND it with original byte. In Turbo C, there are following functions used for accessing the port:

outportb( PORTID, data); data = inportb( PORTID); outport( PORTID, data); data = inport( PORTID);

Outport() function sends a word to port, inport() reads a word from the port. outportb() sends a byte to port and inportb() reads a byte from the port. If you include DOS.H header, these functions will be considured as macro, otherwise as functions. Function inport() will return a word having lower byte as data at PORTID and higher byte as data at PORTID+2. So, we can use this function to read status and control registers together. inportb() function returns byte at PORTID. outport() writes the lower byte to PORTID and higher byte to PORTID+1. So this can be used to write data and control together. outportb() function write the data to PORTID. outport() and outportb() returns nothing. excessive draw of current from the port. Connect an LED in series with a resister of 1KW or 2.2KW between any of the data pins(2 to 9) and ground. With that, if you run the program given below, you should see the LED blinking with app. 1 sec frequency.

KKTMPJ

197

INTRODUCTION TO INTERFACING

Exercise For Topic 5


1. What is the characterizing feature of serial communications

2. Explain the sequence of 8255 to do the read or write operation.

3. How many mode is 8255 have ?. State the purpose each of them.

4. Explain what is RS 232C ?.

5. Explain the difference between asynchronous communications and synchronous communications.

6. Determine the function of each no of 9 pins connector when a serial port was connect a modem to your computer .

KKTMPJ

198

INTRODUCTION TO INTERFACING

SUMMARY
In this unit we have studied : 1. The 82C55A is an LSI peripheral design to permits easy implementation of parallel I/O in the 8088 and 8086 microprocessor system .

2.

Two example of interfaces that require a synchronized data transfer are serial communication interface and a parallel printer interface.

3.

Two types of serial data communication are widely used in microprocessor system are asynchronous communications and synchronous communication.

ANSWERS Exercise For Topic 3


1. Permits data to be transferred between two units using just two data lines.

2.

First the CS input must be a logic 0 and correct I/O address must be applied to the A1 and A0 pins. The remaining port address pins are dont cares as far as the 8255 is concerned , and are externally decoded to select the 8255.

3.

3 modes , that is mode 0 , mode 1 and mode 2. The purpose of :

Mode 0 as a basic input

/ output . Port A , B and C can be individually

programmed as input or output port.

Mode 1 in this mode the 8255 uses port C as a handshaking port.

Mode 2 this mode allow port A to operate as an 8 bit bidirectional bus. This is needed to allow the 8255 to be interfaced with 8 bit peripheral such as UARTS , which require a bidirectional data bus.

KKTMPJ

199

INTRODUCTION TO INTERFACING

4.

RS 232C interface is a standard interface for implementing asynchronous serial data communication port on devices such as printers , CRT terminals , keyboards and modems.

5.

By synchronous , mean that the receiver and transmitter sections of the two pieces of equipment communicating with each other must ran synchronously. For this reason , the interface includes a clock line as well as transmit data , receive data and signal common lines. It is a clock signal that synchronizes both the transmission and reception of data. Meanwhile by asynchronous method of communications eliminates the need for the clock signal. The simplest form of an asynchronous communications

interface could consist of a Receive data , Transmit data , and Signal common communication lines. In this case , the data to be transmitted are sent out one character at a time, and the receiver examining synchronization bits that are included at the beginning and end of each character performs end of the communication line synchronization.

6.

9 pin connector :

1. Carrier Detect - Determines if the modem is connected to a working phone line. 2. Receive Data - Computer receives information sent from the modem. 3. Transmit Data - Computer sends information to the modem. 4. Data Terminal Ready - Computer tells the modem that it is ready to talk. 5. Signal Ground - Pin is grounded. 6. Data Set Ready - Modem tells the computer that it is ready to talk. 7. Request To Send - Computer asks the modem if it can send information. 8. Clear To Send - Modem tells the computer that it can send information. 9. Ring Indicator - Once a call has been placed, computer acknowledges signal (sent from modem) that a ring is detected.

KKTMPJ

200

INTRODUCTION TO INTERFACING

KKTMPJ

201

Вам также может понравиться