Computer System Applications: Design and Development Laboratory Manual Dr Mohammad Jahangir Ikram Department of Computer Science Lahore University of Management Sciences Table of Contents and List of Experiments 1. Data Input and Output Using Parallel Port 1.1. 1.2. 1.3. 1.4. 1.5. 2. 3. 4. 5. 6. 7. Introduction The Theory of Parallel Port The Circuit Diagram and Parallel Port Addressing Programming Languages Support for Data input and Output using Parallel Port The INPUT/OUTPUT Experiment 1.5.1. The OUTPUT experiment 1.5.1.1. Theory and Circuit Diagrams for Experiment 1 1.5.1.2. Programming Project: The Roulette Wheel 1.5.2. The INPUT Experiment 1.5.2.1. Circuit Diagrams 1.5.2.2. Study of Basic Input 1.5.2.3. Study of Key Debounce 1.5.2.4. Study of Nibble-Mode Input 1.5.2.5. Programming Project: The Printer Status Emulator Programming of Display Matrix 2.1. Introduction 2.2. The Theory And Circuit Diagrams For Display Matrix 2.3. Fundamental Operation 2.4. Time-Multiplexing Techniques for Display Matrix 2.5. Displaying a Character 2.6. Programming Project: The Snake and Marshmallows The A/D and D/A Conversion 3.1. Introduction 3.2. The Digital to Analog Conversion 3.2.1. The Basic Conversion and Study of Quantization Error 3.2.2. Waveform Generation 3.3. The Analog to Digital Conversion 3.3.1. Study of Basic Conversion 3.4. Programming Project: FFT Analysis The Motor Speed Measurement and Control 4.1. Introduction 4.2. Basic Measurement 4.3. Using of Data Acquisition Techniques 4.3.1. Array Filling 4.3.2. Interrupt Control 4.3.3. DMA Temperature Measurement and Control 5.1. Introduction 5.2. Basic Control Techniques 5.2.1. ON/OFF Control 5.2.2. Variable Control 5.3. Loose and Tight Control: Advantages and Disadvantages Interrupt Programming 6.1. Introduction 6.2. Basic Programming 6.3. A simple hardware Interrupt based TSR A simple Device DOS Device Driver for Motor Speed Control The block diagram of the LUMS Parallel Port Interface Board (LPPIB) is given on next page. Lahore University of Management Sciences Dr Mohammad Jahangir Ikram 1 Dr Mohammad Jahangir Ikram LEDs ADC 0804 Analog to Digital Connector Power Supply Section Kick Start Switch 0-5 V Analog DIP SWITCH Connector 747 Dual Op Amp Sensor O/P From Variable Power Supply LUMS Parallel Port Interface Board Analog I/P MOTOR EN 74244 as MUX +5 Analog Output Lahore University of Management Sciences 2 2 4 5 6 7 8 9 Input Port 8 X 8 Matrix Display Output Port 3 DB-25 Connector to Computer Parallel Port Resistors LEDs 1, 14 (for Row/ Coloumn Select) Row Latch Coloumn Latch Matrix Connector 1,14 (O/P) Digital to Analog Connector Computer System Applications: Design and Development Laboratory Manual Dr Mohammad Jahangir Ikram Department of Computer Science Lahore University of Management Sciences Read Laboratory Notes carefully before you come to the class. Chapter 1: Contents 1. 2. 3. 4. 5. 6. Introduction The Theory of Parallel Port The Circuit Diagram and Parallel Port Addressing Programming Languages Support for Data input and Output using Parallel Port Theory and Circuit Diagrams for Experiment 1 Programming Assignment 1. Introduction The Computer System Applications (CSA) course has extensive laboratory workload. A special hardware board has been designed to do a list of experiments. The list is as follows: 1. 2. 3. 4. 5. 6. 7. Study of Parallel port and I/O through Parallel port Programming a Display Matrix A/D and D/A Conversion Motor Speed Measurement & Control Interrupt Programming Speed Control Using Interrupts Device Driver Programming The board can be attached to the printer port of any computer and can be programmed in any software, namely, DEBUG, Pascal, C, C++, Qbasic and Visual Basic etc. In the laboratory two students are assigned to a single board and some boards may be available for issuing to students for experimenting at home. First we study the theory (history, circuit design, programming methods) of a parallel port. Then the experiments are discussed that you are going to perform on the first day of the lab. The main purpose of the lab is to provide students with some hands-on experience with the interfacing. Parallel port is not the only way to interface a computer with the outside world, a special plug-in card can also be used. This method is discussed in last experiment in the above list. 2. The Theory of Parallel Port: Programming, Interfacing, & Using the PC’s Parallel Printer Port A first step in exploring the parallel port is learning how to get the most from a port with your everyday applications and peripherals. Things to know include how to find, configure, and install a port, how and when to use the new bidirec-tional, EPP, and ECP modes, and how to handle a system with multiple parallel- port peripherals. This chapter presents essential information and tips relating to these topics. Lahore University of Management Sciences Dr Mohammad Jahangir Ikram 3 21. Defining the Port What is the “parallel port”? In the computer world, a port is a set of signal lines that the microprocessor, or CPU, uses to exchange data with other components. Typical uses for ports are communicating with printers, modems, keyboards, and displays, or just about any component or device except system memory. Most computer ports are digital, where each signal, or bit, is 0 or 1. A parallel port transfers multiple bits at once, while a serial port transfers a bit at a time (though it may transfer in both directions at once). We are talking about a specific type of parallel port: the one found on just about every PC, or IBM-compatible personal computer. Along with the RS-232 serial port, the parallel port is a workhorse of PC communications. On newer PCs, you may find other ports such as SCSI, USB, and IrDA, but the parallel port remains popular because it’s capable, flexible, and every PC has one. The original PC’s parallel port had eight outputs, five inputs, and four bidirectional lines. These are enough for communicating with many types of peripherals. On many newer PCs, the eight outputs can also serve as inputs, for faster communications with scanners, drives, and other devices that send data to the PC. The parallel port was designed as a printer port, and many of the original names for the port’s signals (PaperEnd, AutoLineFeed) reflect that use. But these days, you can find all kinds of things besides printers connected to the port. The term peripheral or peripheral device is a catch-all category that includes printers, scanners, modems, and other devices that connect to a PC. 2.2 Port Types As the design of the PC evolved, several manufacturers introduced improved versions of the parallel port. The new port types are compatible with the original design, but add new abilities, mainly for increased speed. Speed is important because as computers and peripherals have gotten faster, the jobs they do have become more complicated, and the amount of information they need to exchange has increased. The original parallel port was plenty fast enough for sending bytes representing ASCII text characters to a dot-matrix or daisy-wheel printer. But modern printers need to receive much more information to print a page with multiple fonts and detailed graphics, often in color. The faster the computer can transmit the information, the faster the printer can begin processing and printing the result. A fast interface also makes it feasible to use portable, external versions of peripherals that you would otherwise have to install inside the computer. A parallel-port tape or disk drive is easy to move from system to system, and for occasional use, such as making back-ups, you can use one unit for several systems. Because a backup may involve copying hundreds of Megabytes, the interface has to be fast to be worthwhile. Let us first discuss the new port types in detail, but for now, here is a summary of the available types: 2.2.1 Original (SPP) The parallel port in the original IBM PC, and any port that emulates the original port’s design, is sometimes called the SPP, for standard parallel port, even though the original port had no written standard beyond the schematic diagrams and documentation for the IBM PC. Other names used are AT-type or ISA-compatible. The port in the original PC was based on an existing Centronics printer interface. However, the PC introduced a few differences, which other systems have continued. SPPs can transfer eight bits at once to a peripheral, using a protocol similar to that used by the original Centronics interface. The SPP doesn’t have a byte-wide input port, but for PC-to-peripheral transfers, SPPs can use a Nibble mode that transfers each byte 4 bits at a time. Nibble mode is slow, but has become popular as a way to use the parallel port for input. Note: Our Experimentation will be limited to SPP mode 2.2.2 PS/2-type (Simple Bidirectional) An early improvement to the parallel port was the bidirectional data port introduced on IBM’s model PS/2. The bidirectional port enables a peripheral to transfer eight bits at once to a PC. The term PS/2-type has come to refer to any parallel port that has a bidirectional data port but doesn’t Lahore University of Management Sciences Dr Mohammad Jahangir Ikram 4 support the EPP or ECP modes described below. Byte mode is an 8-bit data-transfer protocol that PS/2-type ports can use to transfer data from the peripheral to the PC. 2.2.3 EPP The EPP (enhanced parallel port) was originally developed by chip maker Intel, PC manufacturer Zenith, and Xircom, a maker of parallel-port networking products. As on the PS/2-type port, the data lines are bidirectional. An EPP can read or write a byte of data in one cycle of the ISA expansion bus, or about 1 microsecond, including handshaking, compared to four cycles for an SPP or PS/2-type port. An EPP can switch directions quickly, so it’s very efficient when used with disk and tape drives and other devices that transfer data in both directions. An EPP can also emulate an SPP, and some EPPs can emulate a PS/2-type port. 2.2.4 ECP The ECP (extended capabilities port) was first proposed by Hewlett Packard and Microsoft. Like the EPP, the ECP is bidirectional and can transfer data at ISA-bus speeds. ECPs have buffers and support for DMA (direct memory access) transfers and data compression. ECP transfers are useful for printers, scanners, and other peripherals that transfer large blocks of data. An ECP can also emulate an SPP or PS/2-type port, and many ECPs can emulate an EPP as well. 2.2.5 Multi-mode Ports Many newer ports are multi-mode ports that can emulate some or all of the above types. They often include configuration options that can make all of the port types available, or allow certain modes while locking out the others. An example is IEEE 1284 parallel port described separately later in the chapter. 2.3 System Resources The parallel port uses a variety of the computer’s resources. Every port uses a range of addresses, though the number and location of addresses varies. Many ports have an assigned IRQ (interrupt request) level, and ECPs may have an assigned DMA channel. The resources assigned to a port can’t conflict with those used by other system components, including other parallel ports 2.3.1 Addressing The standard parallel port uses three contiguous addresses, usually in one of these ranges: 3BCh, 3BDh, 3BEh 378h, 379h, 37Ah 278h, 279h, 27Ah The first address in the range is the port’s base address, also called the Data register or just the port address. The second address is the port’s Status register, and the third is the Control register. EPPs and ECPs reserve additional addresses for each port. An EPP adds five registers at base address + 3 through base address + 7, and an ECP adds three registers at base address + 400h through base address + 402h. For a base address of 378h, the EPP registers are at 37Bh through 37Fh, and the ECP registers are at 778h through 77Fh. On early PCs, the parallel port had a base address of 3BCh. On newer systems, the parallel port is most often at 378h. But all three addresses are reserved for parallel ports, and if the port’s hardware allows it, you can configure a port at any of the addresses. However, you normally can’t have an EPP at base address 3BCh, because the added EPP registers at this address may be used by the video display. IBM’s Type 3 PS/2 port also had three additional registers, at base address +3 through base address + 5, and allowed a base address of 1278h or 1378h. Most often, DOS and Windows refer to the first port in numerical order as LPT1, the second, LPT2, and the third, LPT3. So on bootup, LPT1 is most often at 378h, but it may be at any of the three addresses. LPT2, if it exists, may be at 378h or 278h, and LPT3 can only be at 278h. Various configuration techniques can change these assignments, however, so not all systems will follow this conven-tion. LPT stands for line printer, reflecting the port’s original intended use. If your port’s hardware allows it, you can add a port at any unused port address in the system. Not all software will recognize these nonstandard ports as LPT ports, but you can access them with software that writes directly to the port registers. 2.3.2 Interrupts Lahore University of Management Sciences Dr Mohammad Jahangir Ikram 5 Most parallel ports are capable of detecting interrupt signals from a peripheral. The peripheral may use an interrupt to announce that it’s ready to receive a byte, or that it has a byte to send. To use interrupts, a parallel port must have an assigned interrupt-request level (IRQ). Conventionally, LPT1 uses IRQ7 and LPT2 uses IRQ5. But IRQ5 is used by many sound cards, and because free IRQ levels can be scarce on a system, even IRQ7 may be reserved by another device. Some ports allow choosing other IRQ levels besides these two. Many printer drivers and many other applications and drivers that access the parallel port don’t require parallel-port interrupts. If you select no IRQ level for a port, the port will still work in most cases, though sometimes not as efficiently, and you can use the IRQ level for something else. 2.3.3 DMA Channels ECPs can use direct memory access (DMA) for data transfers at the parallel port. During the DMA transfers, the CPU is free to do other things, so DMA transfers can result in faster performance overall. In order to use DMA, the port must have an assigned DMA channel, in the range 0 to 3. 2.4 Finding Existing Ports DOS and Windows include utilities for finding existing ports and examining other system resources. In Windows 95, click on Control Panel, System, Devices, Ports, and click on a port to see its assigned address and (optional) IRQ level and DMA channel. In Windows 3.1 or DOS, you can use Microsoft’s Diagnostic (msd.exe) to view ports, assigned IRQ levels, and other system details. 2.5 Configuring The parallel port that comes with a PC will have an assigned address and possibly an IRQ level and DMA channel. Multi-mode ports may also be configured with specific modes enabled. You can change some or all of these assignments to match your needs. If you’re adding a new port, you need to configure it, making sure that it doesn’t conflict with existing ports and other resources. 2.5.1 Port Options There is no standard method for configuring a port. Some ports, especially older ones, use jumper blocks or switches to select different options. Others allow configuring in software, using a utility provided on disk. A port on a system mother-board may have configuration options in the system setup screens (the CMOS setup) that you can access on bootup. On ports that meet Microsoft’s Plug and Play standard, Windows 95 can automatically assign an available port address and IRQ level to a port. Check your system or port’s documentation for specifics on how to configure a port. Some ports allow a choice of just one or two of the three conventional base addresses. A few allow you to choose any uncommitted address, including non-standard ones. On some boards, the jumpers or switches are labeled, which is extremely handy when you don’t have other documentation (or can’t find it). If your port supports ECP transfers, assign it an IRQ level and DMA channel if possible. Most ECP drivers do use these, and if they’re not available, the driver will revert to a slower mode. 2.5.2 Multi-mode Ports Configuring a multi-mode port needs special consideration. A multi-mode port’s controller chip supports a variety of modes that emulate different port types. In addition to the configuration options described above, on most multi-mode ports, you also have to select a port type to emulate. The problem is that there is no single standard for the basic setup on the controller chips, and there are many different chips! Usually the setup involves writing to configuration registers in the chip, but the location and means of accessing the registers varies. For this Lahore University of Management Sciences Dr Mohammad Jahangir Ikram 6 reason, every port should come with a simple way to configure the port. If the port is on the motherboard, look in the CMOS setup screens that you can access on bootup. Other ports may use jumpers to enable the modes, or have configuration software on disk. The provided setup routines don't always offer all of the available options or explain the meaning of each option clearly. For example, one CMOS setup I’ve seen allows only the choice of AT or PS/2-type port. The PS/2 option actually con-figures the port as an ECP, with the ECP’s PS/2 mode selected, but there is no documentation explaining this. The only way to find out what mode is actually selected is to read the chip’s configuration registers. And although the port also supports EPP, the CMOS setup includes no way to enable it, so again, accessing the configuration registers is the only option. If your port is EPP- or ECP-capable but the setup utility doesn't offer these as choices, a last resort is to identify the controller chip, obtain and study its data sheet, and write your own program to configure the port. The exact terminology and the number of available options can vary, but these are typical configuration options for a multi-mode port: SPP. Emulates the original port. Also called AT-type or ISA-compatible. PS/2, or simple bidirectional. Like an SPP, except that the data port is bidirec-tional. EPP. Can do EPP transfers. Also emulates an SPP. Some EPPs can emulate a PS/2-type port. ECP. Can do ECP transfers. The ECP’s internal modes enable the port to emulate an SPP or PS/2-type port. An additional internal mode, Fast Centronics, or Parallel- Port FIFO, uses the ECP's buffer for faster data transfers with many old-style (SPP) peripherals. ECP + EPP. An ECP that supports the ECP’s internal mode 100, which emulates an EPP. The most flexible port type, because it can emulate all of the others. 2.5.3 Drivers After setting up the port’s hardware, you may need to configure your operating system and applications to use the new port. For DOS and Windows 3.1 systems, on bootup the operating system looks for ports at the three conventional addresses and assigns each an LPT number. In Windows 3.1, to assign a printer to an LPT port, click on Control Panel, then Printers. If the printer model isn’t displayed, click Add and follow the prompts. Select the desired printer model, then click Connect to view the available ports. Select a port and click OK, or Cancel to make no changes. In Windows 95, the Control Panel lists available ports under System Properties, Device Manager, Ports. There’s also a brief description of the port. Printer Port means that Windows treats the port as an ordinary SPP, while ECP Printer Port means that Windows will use the abilities of an ECP if possible. To change the driver, select the port, then Properties, Driver, and Show All Drivers. Select the driver and click OK. If an ECP doesn't have an IRQ and DMA channel, the Windows 95 printer driver will use the ECP’s Fast Centronics mode, which transfers data faster than an SPP, but not as fast as ECP. The Device Manager also shows the port’s configuration. Select the port, then click Resources. Windows attempts to detect these settings automatically. If the configuration shown does not match your hardware setup, deselect the Use Automatic Settings check box and select a different con-figuration. If none matches, you can change a setting by double-clicking on the resource type and entering a new value. Windows displays a message if it detects any conflicts with the selected settings. To assign a printer to a port, click on Control Panel, Printers, and select the printer to assign. Parallel-port devices that don’t use the Windows printer drivers should come with their own configuration utilities. DOS programs generally have their own printer drivers and methods for selecting a port as well. On older systems, the parallel port is on an expansion card with the video adapter. These should include a way to disable the video adapter, so you can use the parallel port in any system. 2.6 Port Hardware Lahore University of Management Sciences Dr Mohammad Jahangir Ikram 7 The parallel port’s hardware includes the back-panel connector and the circuits and cabling between the connector and the system’s expansion bus. The PC’s microprocessor uses the expansion bus’s data, address, and control lines to transfer information between the parallel port and the CPU, memory, and other system components. 2.7 Connectors The PC’s back panel has the connector for plugging in a cable to a printer or other device with a parallel-port interface. Most parallel ports use the 25-contact D-sub connector shown in Figure above. The shell (the enclosure that surrounds the contacts) is roughly in the shape of an uppercase D. Other names for this connector are the subminiature D, DB25, D-shell, or just D connector. The IEEE 1284 standard for the parallel port calls it the IEEE 1284-A connector. Newer parallel ports may use the new, compact, 36-contact IEEE 1284-C. The connector on the computer is female, where the individual contacts are sockets, or receptacles. The cable has a mating male connector, whose contacts are pins, or plugs. The parallel-port connector is usually the only female 25-pin D-sub on the back panel, so there should be little confusion with other connectors. Some serial ports use a 25-contact D-sub, but with few exceptions, a 25-pin serial D-sub on a PC is male, with the female connector on the cable—the reverse of the parallel-port convention. (Other serial ports use 9-pin D-subs instead.) SCSI is another interface whose connector might occasionally be confused with the parallel port’s. The SCSI interface used by disk drives, scanners, and other devices usually has a 50contact connector, but some SCSI devices use a 25-contact D-sub that is identical to the parallelport’s connector. If you’re unsure about which is the parallel-port connector, check your system documentation. When all else fails, opening up the enclosure and tracing the cable from the connector to an expansion board may offer clues. 2.8 Alternatives to the Parallel Port The parallel port is just one of many ways to interface inputs and outputs to a computer. In spite of its many virtues, the parallel port isn’t the best solution for every project. These are some of the alternatives: Lahore University of Management Sciences Dr Mohammad Jahangir Ikram 8 Serial Interfaces One large group of parallel-port alternatives is serial interfaces, where data bits travel on a single wire or pair of wires (or in the case of wireless links, a single transmission path.) Both ends of the link require hardware or software to translate between serial and parallel data. There are many types of serial interfaces avail-able for PCs, ranging from the ubiquitous RS-232 port to the newer RS-485, USB, IEEE-1394, and IrDA interfaces. RS-232 Just about every PC has at least one RS-232 serial port. This interface is especially useful when the PC and the circuits that you want to connect are physically far apart. As a rule, parallel-port cables should be no longer than 10 to 15 feet, though the IEEE-1284 standard describes an improved interface and cable that can be 10 meters (33 feet). In contrast, RS-232 links can be 80 feet or more, with the exact limit depending on the cable specifications and the speed of data transfers. RS-232 links are slow, however. Along with each byte, the transmitting device normally adds a start and stop bit. Even at 115,200 bits per second, which is a typical maximum rate for a serial port, the data-transfer rate with one start and stop bit per byte is just 11,520 bytes per second. RS-485 Another useful serial interface is RS-485, which can use cables as long as 4000 feet and allows up to 32 devices to connect to a single pair of wires. You can add an expansion card that contains an RS-485 port, or add external circuits that convert an existing RS-232 interface to RS485. Other interfaces similar to RS-232 and RS-485 are RS-422 and RS-423. Universal Serial Bus A new option for I/O interfacing is the Universal Serial Bus (USB), a project of a group that includes Intel and Microsoft. A single USB port can have up to 127 devices communicating at either 1.5 Megabits/second or 12 Megabits/second over a 4-wire cable. The USB standard also describes both the hardware interface and software protocols. Newer PCs may have a USB port built-in, but because it’s so new, most existing computers can’t use it without added hardware and software drivers. IEEE 1284-1994 Standard The recently released standard, "IEEE Std.1284-1994 Standard Signaling Method for a Bi-directional Parallel Peripheral Interface for Personal Computers", is for the parallel port what the Pentium processor is to the 286. The standard provides for high speed bi-directional communication between the PC and an external peripheral that can communicate 50 to 100 times faster than the original parallel port. It can do this and still be fully backward compatible with all existing parallel port peripherals and printers. The 1284 standard defines 5 modes of data transfer. Each mode provides a method of transferring data in either the forward direction (PC to peripheral), reverse direction (peripheral to PC) or bi-directional data transfer (half duplex). The defined modes are: Forward direction only Compatibility Mode: "Centronics" or standard mode Reverse direction only Nibble Mode: 4 bits at a time using status lines for data. Hewlett Packard Bi-tronics Byte Mode: 8 bits at a time using data lines, sometimes referred to as a "bi-directional" port. Bi-directional EPP Enhanced Parallel Port- used primarily by non-printer peripherals, CD ROM, tape, hard drive, network adapters, etc.... ECP Extended Capability Port- used primarily by new generation of printers and scanners All parallel ports can implement a bi-directional link by using the Compatible and Nibble modes for data transfer. Byte mode can be utilized by about 25% of the installed base of parallel ports. All three of these Lahore University of Management Sciences Dr Mohammad Jahangir Ikram 9 modes utilize software only to transfer the data. The driver has to write the data, check the handshake lines (i.e.: BUSY), assert the appropriate control signals (i.e.: STROBE) and then go on to the next byte. This is very software intensive and limits the effective data transfer rate to 50 to 100 Kbytes per second. In addition to the previous 3 modes, EPP and ECP are being implemented on the latest I/O controllers by most of the Super I/O chip manufacturers. These modes use hardware to assist in the data transfer. For example, in EPP mode, a byte of data can be transferred to the peripheral by a simple OUT instruction. The I/O controller handles all the handshaking and data transfer to the peripheral. Overall, the 1284 standard provides the following: 1. 5 modes of operation for data transfer 2. A method for the host and peripheral to determine the supported modes and to negotiate to the requested mode. 3.Defines the physical interface Cables Connectors 4.Defines the electrical interface Drivers/Receivers Termination Impedance In summary, the 1284 parallel port provides an easy to use, high performance interface for portable products and printers. IEEE 1284 History When IBM introduced the PC, in 1981, the parallel printer port was included as an alternative to the slower serial port as a means for driving the latest high performance dot matrix printers. The parallel port had the capability to transfer 8 bits of data at time whereas the serial port transmitted one bit at a time. When the PC was introduced, dot matrix printers were the main peripheral that used the parallel port. As technology progressed and the need for greater external connectivity increased, the parallel port became the means by which you could connect higher performance peripherals. These peripherals now range from printer sharing devices, portable disk drives and tape backup to local area network adapters and CD ROM players. The problems faced by developers and customers of these peripherals fall into three categories. First, although the performance of the PC has increased dramatically, there has been virtually no change in the parallel port performance or architecture. The maximum data transfer rate achievable with this architecture is around 150 kilobytes per second and is extremely software intensive. Second, there is no standard for the electrical interface. This causes many problems when attempting to guarantee operation across various platforms. Finally, the lack of design standards forced a distance limitation of only 6 feet for external cables. In 1991 there was a meeting of printer manufacturers to start discussions on developing a new standard for the intelligent control of printers over a network. These manufacturers, which included Lexmark, IBM, Texas Instruments and others, formed the Network Printing Alliance. The NPA defined a set of parameters that, when implemented in the printer and host, will allow for the complete control of printer applications and jobs. While this work was in progress it became apparent that to fully implement this standard would require a high performance bi-directional connection to the PC. The usual means of connection, the ordinary PC parallel port, did not have the capabilities required to meet the full requirements or abilities of this standard. The NPA submitted a proposal to the IEEE for the creation of a committee to develop a new standard for a high speed bi-directional parallel port for the PC. It was a requirement that this new standard would remain fully compatible with the original parallel port software and peripherals, but would increase the data rate capability to greater than 1M bytes per second, both in and out of the computer. This committee became the IEEE 1284 committee. The IEEE 1284 standard, "Standard Signaling Method for a Bi-directional Parallel Peripheral Interface for Personal Computers", was approved for final release in March of 1994. Lahore University of Management Sciences Dr Mohammad Jahangir Ikram 10 IEEE 1394 The IEEE-1394 high-performance serial bus, also known as Firewire, is another new interface. It allows up to 63 devices to connect to a PC, with transmission rates of up to 400 Megabits per second. The 6-wire cables can be as long as 15 feet, with daisy chains extending to over 200 feet. The interface is especially popular for connecting digital audio and video devices. IEEE-1394 expansion cards are available for PCs. IrDA The IrDA (Infrared Data Association) interface allows wireless serial communications over distances of 3 to 6 feet. The link transmits infrared energy at up to 115,200 bits/second. It’s intended for convenient (no cables or connectors) transmitting of files between a desktop and laptop computer, or any short-range communications where a cabled interface is inconvenient. Some computers and peripherals now have IrDA interfaces built-in. Other Parallel Interfaces SCSI and IEEE-488 are two other parallel interfaces used by some PCs. SCSI SCSI (small computer system interface) is a parallel interface that allows up to seven devices to connect to a PC along a single cable, with each device having a unique address. Many computers use SCSI for interfacing to internal or external hard drives, tape back-ups, and CDROMs. SCSI interfaces are fast, and the cable can be as long as 19 feet (6 meters). But the parallel-port interface is simpler, cheaper, and much more common. IEEE 488 The IEEE-488 interface began as Hewlett Packard’s GPIB (general-purpose interface bus). It’s a parallel interface that enables up to 15 devices to communicate at speeds of up to 1 Megabit per second. This interface has long been popular for interfacing to lab instruments. Expansion cards with IEEE-488 interfaces are available. Custom I/O Cards Many other types of input and output circuits are available on custom expansion cards. An advantage of these is that you’re not limited by an existing interface design. The card may contain just about any combination of analog and digital inputs and outputs. In addition, the card may hold timing or clock circuits, function generators, relay drivers, filters, or just about any type of component related to the external circuits. With the standard parallel port, you can add these components externally, but a custom I/O card allows you to place them inside the computer. To use an expansion card, you of course need an empty expansion slot, which isn’t available in portable computers and some desktop systems. And the custom hardware requires custom software. PC Cards Finally, instead of using the expansion bus, some I/O cards plug into a PC Card slot, which accepts slim circuit cards about the size of a playing card. An earlier name for these was PCMCIA cards, which stands for Personal Computer Memory Card International Association, whose members developed the standard. Many portable computers and some desktop models have PC-Card slots. Popular uses include modems and data acquisition circuits. There are even PC Cards that function as parallel ports. You don’t need an internal expansion slot, and you don’t have to open up the computer to plug the card in. But again, the standard parallel-port interface is cheaper and more widely available. 3. The Circuits Inside Inside the computer, the parallel-port circuits may be on the motherboard or on a card that plugs into the expansion bus. Lahore University of Management Sciences Dr Mohammad Jahangir Ikram 11 The motherboard is the main circuit board that holds the computer’s microprocessor chip as well as other circuits and slots for expansion cards. Because just about all computers have a parallel port, the port circuits are often right on the motherboard, freeing the expansion slot for other uses. Notebook and laptop computers don’t have expansion slots, so the port circuits in these computers must reside on the system’s main circuit board. The port circuits connect to address, data, and control lines on the expansion bus, and these in turn interface to the microprocessor and other system components. The parallel port circuit does not contain an 8255 PPI. IBM originally supplied three adapters that included a parallel printer port for its PC/XT/AT range of microcomputers. Depending on which were installed, each available parallel port's base address in the processor's I/O space would be one of 278, 378 and 3BC (all Hex). Most (All?) contemporary PCs, shipped with a single parallel printer port, seem to have the base address at 378 Hex. The PC parallel port adapter is specifically designed to attach printers with a parallel port interface, but it can be used as a general input/output port for any device or application that matches its input/output capabilities. It has 12 TTL-buffer output points, which are latched and can be written and read under program control using the processor IN or OUT instruction. The adapter also has five steady-state input points that may be read using the processor's IN instruction. In addition, one input can also be used to create a processor interrupt. This interrupt can be enabled and disabled under program control. Reset from the power-on circuit is also ORed with a program output point, allowing a device to receive a power-on reset when the processor in reset. The input/output signals are made available at the back of the adapter through a right-angled, PCB-mounted, 25-pin, D-type female connector. This connector protudes through the rear panel of the system, where a cable may be attached. When this adapter is used to attach a printer, data or printer commands are loaded into an 8-bit, latched, output port, and the strobe line is activated, writing data to the printer. The program then may read the input ports for printer status indicating when the next character can be written, or it may use the interrupt line to indicate "not busy" to the software. The Parallel Port Printer Adopter Block Diagram Address Decoder Address Bus Buffer Control Signals Interrupt Data Bus Data Buffer/ Latch for Output 25 – PIN D-Type Connector Control Input Buffer Data Wrap Buffer Control Wrap and Signal Input The output ports may also be read back at the card's interface for diagnostic loop functions. This allows faults to be isolated between the adapter and the attached device. Lahore University of Management Sciences Dr Mohammad Jahangir Ikram 12 The original IBM-PC's Parallel Printer Port had a total of 12 digital outputs and 5 digital inputs accessed via 3 consecutive 8-bit ports in the processor's I/O space. 8 output pins accessed via the DATA Port 5 input pins (one inverted) accessed via the STATUS Port 4 output pins (three inverted) accessed via the CONTROL Port The remaining 8 pins are grounded 4. Programming Considerations: The printer adapter responds to five I/O instructions: two output and three input. The output instructions transfer data into two latches whose outputs are presented on the pins of a 25-pin Dtype female connector. Two of the three input instructions allow the processor to read back the contents of the two latches. The third allows the processor to read the realtime status of a group of pins on the connector. A description of each instruction follows Output to address 278/378/3BC Hex Bit Pin 7 9 6 8 5 7 4 6 3 5 2 4 1 3 0 2 The instruction captures data from the data bus and is present on the respective pins. These pins are each capable of sourcing2.6 mA and sinking 24 mA. It is essential that the external device not try to pull these lines to ground. Output to address 27A/37A/3BE Hex Bit Pin Lahore University of Management Sciences 7 - 6 - 5 - 4 IRQ Enable Dr Mohammad Jahangir Ikram ~3 17 2 16 ~1 14 ~0 1 13 This instruction causes the latch to capture the least significant bits of the data bus. The four least significant bits present their outputs, or inverted versions of their outputs, to the respective pins shown above. If bit 4 is written as 1, the card will interrupt the processor on the condition that pin 10 transitions high to low. These pins are driven by open collector drivers pulled to +5 Vdc through 4.7 k-ohm resistors. They can each sink approximately 7 mA and maintain 0.8 volts down-level. Input from address 278/378/3BC Hex This command presents the processor with data present on the pins associated with the corresponding output address. This should normally reflect the exact value that was last written. If an external device should be driving data on these pins (in violation of usage groundrules) at the time of an input, this data will be ORed with the latch contents. Input from address 279/379/3BD Hex This command presents realtime status to the processor from the pins as follows. Bit Pin 7 11 6 10 5 12 4 13 3 15 2 - 1 - 0 - Input from address 27A/37A/3BE Hex This instruction causes the data present on pins 1, 14, 16, 17 and the IRQ bit to be read by the processor. In the absence of external drive applied to these pins, data read by the processor will exactly match data last written to the corresponding output address in the same bit positions. Note that data bits 0-2 are not included. If external drivers are dotted to these pins, that data will be ORed with data applied to the pins by the output latch. Bit Pin 7 - 6 - 5 - 4 3 2 IRQ ~17 16 Enable Note 0 1 0 Note: state assumed after processor reset: 1 ~14 0 ~1 1 1 4.1 Registers: The following Tbale shows the register/port address available at the Printer Port. An X means available. 7 6 5 4 3 2 1 0 I/O Port Address Data X X X (D) Status ~X X X (S) Control (C) Note: ~ are inverted signals Lahore University of Management Sciences X X X X ~X X X Hex 378 Hex 379 X Dr Mohammad Jahangir Ikram ~X ~X Hex 37A 14 4.2 Interface with External Device The interface of printer port with an external device is shown in the above diagram. 4.3 Signal Desciption The following table shows the signal description. Lahore University of Management Sciences Dr Mohammad Jahangir Ikram 15 4.4 The Connector Pin Layout IBM-PC Parallel Printer Port Female DB-25 Socket external Pin layout ______________________________________________________ / \ \ 13 12 11 10 9 8 7 6 5 4 3 2 1 / \ / \ 25 24 23 22 21 20 19 18 17 16 15 14 / \__________________________________________________/ 4.5 Software Considerations QBasic QBasic provides access to the I/O ports on the 80x86 CPU via the INP function and the OUT statement. INP(portid) ' returns a byte read from the I/O port portid OUT portid, value ' writes the byte value to the I/O port portid portid can be any unsigned integer in the range 0-65535. value is in the range 0-255. For example: pdata = &H378 status = &H379 control = &H37A OUT pdata, bits ' output data bits = INP(status) ' input data Turbo Pascal Turbo Pascal provides access to the I/O ports on the 80x86 CPU via two predefined arrays, Port and PortW. var Port: array[0..65535] of byte; PortW: array[0..65534] of word; The indexed elements of each array match the port at the corresponding I/O address. Assigning a value to an element of the Port or PortW arrays causes that value to be written out to the corresponding port. When an element of the Port or PortW arrays is referenced in an expression, the value is read in from the corresponding port. Const Data = $378; Status = Data + 1; Control = Data + 2; var Bits: Byte; Port[Data] := Bits; { output data } Bits := Port[Status]; { input data } Turbo C and Borland C/C++ Turbo C and Borland C/C++ provide access to the I/O ports on the 80x86 CPU via the predefined functions inportb / inport and outportb / outport. int inportb(int portid); /* returns a byte read from the I/O port portid */ int inport(int portid); /* returns a word read from the I/O port portid */ void outportb(int portid, unsigned char value); /* writes the byte value to the I/O port portid */ Lahore University of Management Sciences Dr Mohammad Jahangir Ikram 16 void outport(int portid, int value); /* writes the word value to the I/O port portid */ #include <stdio.h> #include <dos.h> #define Data 0x378 #define Status 0x379 #define Control 0x37a unsigned char Bits; outportb(Data,Bits); /* output data */ Bits = inportb(Status); /* input data */ Microsoft Visual C/C++ Microsoft Visual C/C++ provides access to the I/O ports on the 80x86 CPU via the predefined functions _inp / _inpw and_outp / _outpw. int _inp(unsigned portid); /* returns a byte read from the I/O port portid */ unsigned _inpw(unsigned portid); /* returns a word read from the I/O port portid */ int _outp(unsigned portid, int value); /* writes the byte value to the I/O port portid */ /* returns the data actually written */ unsigned _outpw(unsigned portid, unsigned value); /* writes the word value to the I/O port portid */ /* returns the data actually written */ portid can be any unsigned integer in the range 0-65535 #include <conio.h> /* required only for function declarations */ #define Data 0x378 #define Status 0x379 #define Control 0x37a int Bits, /* 0 <= Bits <= 255 */ Dummy; Dummy = _outp(Data,Bits); /* output data */ Bits = _inp(Status); /* input data */ Debug Finally, of course, you can use the very old Debug. Type the following command at C prompt to see the help for Debug. C:\>debug /? Runs Debug, a program testing and editing tool. Debug [[drive:][path]filename [testfile-parameters]] [drive:][path]filename Specifies the file you want to test. testfile-parameters Specifies command-line information required by the file you want to test. Lahore University of Management Sciences Dr Mohammad Jahangir Ikram 17 After Debug starts, type ? to display a list of debugging commands. Debug provides input and output commands i port_address o port_address byte_value C:\>debug -o 378 5a -i 379 7F -q C:\> Lahore University of Management Sciences Dr Mohammad Jahangir Ikram 18 5 INPUT and OUTPUT Experiment. 5.2 The OUTPUT Experiment Procedure: Experiment Output data using parallel. The shaded area on main block diagram shows the part of the LUMS Parallel Port Interface Board (LPPIB) that is going to be used in this experiment. Connect the connector as instructed by the TA. This will connect output port (378) to 8 LEDs on the side thorough 220 resistors as described in the diagram below: Output from 378 decoder EN 8-bit Output Register/ Latch Resistors Parallel Port Connector Data Bus LEDs 2 3 4 LSB 8 MSB 25 Part of Computer I/O Card 5.2.1 Testing the circuit: Basic Output Go into Debug. Ask instructor if you are not sure how to. Using the following debug command format: O 378, <number between 0 – FF (hex)> For example O 378, FF /* all LEDS ON */ O 378, 00 /* All LEDs OFF */ O 378, 20 O 378, ff Output some data and by looking at the LEDs that are lit, confirm you experiment. Lahore University of Management Sciences Dr Mohammad Jahangir Ikram 19 Output Port 6 7 8 9 2 3 4 5 DB-25 Connector to Computer Parallel Port Input Port 1, 14 (for Row/ Coloumn Select) 8 X 8 Matrix Display Resistors Row Latch Coloumn Latch Matrix Connector LEDs 1,14 (O/P) Kick Start Switch LEDs ADC 0804 LUMS Parallel Port Interface Board DIP SWITCH Connector Analog to Digital Connector Analog I/P Power Supply Section 0-5 V Analog 747 Dual Op Amp EN MOTOR Sensor O/P 74244 as MUX +5 Analog Output From Variable Power Supply Digital to Analog Connector 5.2.2 Programming Assignments These programming assignments will given in Turbo C by TA. 1. Lit all the alternate LEDs 2. Lit 4 MSB LEDs 3. Make them all ON/OFF using delay loop 4. Any assignment suggested by you Project: The roulette wheel. A roulette wheel has circular number markings and a rotating pointer in the center. Once the pointer is moved and assuming a fair pointer, it can stop at any number. This device is usually used in “Qura Andazi”. Using a paper tape, mark all the eight LEDs and now program for roulette wheel. This project will be further explained in the Class. Questions: 1. How will you ensure your roulette wheel becomes platform independent? 2. How will you include true randomness in the roulette wheel? 5.3 The INPUT Experiment Procedure The Standard Parallel Port can only input 5-bit data. We will use 4-bits to perform Nibble Mode input of 8bit data. In part I of the experiment we will input only 4-bit and in part II we will use 74LS244 device to input 8-bit data. The 4 nibbles will be ‘combined’ in the software to form an 8-bit byte. Lahore University of Management Sciences Dr Mohammad Jahangir Ikram 20 1,14 (O/P) Output Port 9 8 7 6 5 4 3 1, 14 (for Row/ Coloumn Select) 2 DB-25 Connector to Computer Parallel Port Input Port 8 X 8 Matrix Display Resistors Row Latch Coloumn Latch Matrix Connector LEDs 5.3.1 Part I: Nibble Input The following diagram shows the circuit that is going to be used in part I and II of this part of experiment in shaded area and the shaded lines show where the connectors are to be connected. Kick Start Switch LEDs ADC 0804 LUMS Parallel Port Interface Board DIP SWITCH Connector Analog to Digital Connector Analog I/P Power Supply Section 0-5 V Analog 747 Dual Op Amp EN MOTOR Sensor O/P 74244 as MUX +5 Analog Output From Variable Power Supply Digital to Analog Connector Connect the circuit for input port (4-bit only). (Ask your TA). Use DIP switches to simulate input. 5.3.2 Study of Key Bounce and Debounce Whenever the position of a mechanical switch is changed, it bounces many times before becoming stable due to spring action. This can be problem for high speed reading of a key status using computer. Either hardware or software methods can be adopted to eliminate the key bounce. In this experiment you will study the key bounce and then write a software debouncing solution. Lahore University of Management Sciences Dr Mohammad Jahangir Ikram 21 5.3.3 Part II: Nibble Mode Input In nibble mode input, two nibbles are read one at a time and the are combined to form a byte in software. Basic Algorithm is: 1. Enable 74244 buffer to read the high nibble using Port 0378 (Outport (0x378, 00)) 2. Read the high nibble from 379h. 3. Mask out the 4 required bit (MASK = 0x78) 4. Divide by 8 (shift right 3 in logic) 5. Save this in variable lnibble 6. Enable 74244 buffer to read the low nibble using Port 0378 (Outport (0x378, 0xFF)) 7. Read the high nibble from 379h. 8. Multiply by 2 (Shift left one in logic) 9. Add this to hnibble to form the in_byte. 10. Repeat 1- 7 indefinitely if required. The circuit diagram is given below. Output from 0x0378 EN 4-bit Input Buffer 10 Parallel Port Connector 4 11 DIP Switches Output from 379 decoder 12 13 Data Bus 4 25 74 244 Tri-State Buffers Part of Computer I/O Card Lahore University of Management Sciences Dr Mohammad Jahangir Ikram 22 5.3.3 Programming Project: Printer Status Emulator Through Printer Port, a printer sends the following signals: Printer Off Printer Offline Paper out Printer Ready (Idle) Printer Busy Printer Idle for Too Long Assign one switch combination to one the above conditions of the printer, and then write a program that will give printer status. Your should submit a written report for all the programming assignments in this experiment on A4 size papers. Written report will be due next time you come for experiment. State your assumption clearly. All programs should be full of comments and variable names should be appropriate. Lahore University of Management Sciences Dr Mohammad Jahangir Ikram 23