Not Recommended for New Installations. Please contact Technical Support for more information. Parallel Port Input/Output Converter Model PPIO Document No. PPIO2899 B&B Electronics Mfg. Co. Inc. 707 Dayton Road -- P.O. Box 1040 -- Ottawa, IL 61350 USA Phone (815) 433-5100 -- General Fax (815) 433-5105 Home Page: www.bb-elec.com Sales e-mail: orders@bb-elec.com -- Fax (815) 433-5109 Technical Support e-mail: support@bb.elec.
TABLE OF CONTENTS INTRODUCTION .............................................................................1 PACKING LIST.................................................................................2 PC PARALLEL PORT DESCRIPTION ...........................................3 PPIO DESCRIPTION & CONNECTION..........................................7 CONTROLLING THE PPIO USING GWBASIC..............................9 CONTROLLING THE PPIO USING PASCAL...............................
INTRODUCTION The PPIO allows you to connect your IBM PC (or clone) computer to the outside world using the computer’s parallel port. The eight I/O points can be used as either inputs or outputs. As an output they can control voltages as high as 50 Volts DC and can handle currents as high as 500 mA DC. As an input they can handle voltages from 0 to 50 volts with a threshold of 2.5 Volts DC.
Packing List Examine the shipping carton and contents for physical damage. If there is damage, contact B&B Electronics immediately. The following items should be in the shipping carton: 1) 2) 3) PPIO unit This Instruction Manual PPIO Sample/Test Disk If any of the above items is missing contact B&B Electronics immediately.
PC PARALLEL PORT DESCRIPTION To understand how the PPIO can be controlled you must first understand how the parallel port works inside the computer. The parallel port is designed to connect the computer with the outside world. It can have up to 12 TTL compatible outputs and up to 9 TTL compatible inputs. It cannot have both at the same time since some inputs and outputs share pins. Eight of the outputs and five of the inputs are dedicated. Four of the lines can be either inputs or outputs.
used to read the status of the port. The PPIO does not need to use this port as an input port. Again, referring to Table 1, if you input the data on port 0379H, then whatever TTL level pins 15, 13, 12, 10, and 11 are will show up as bits 3 through 7. The state of bits 0, 1, and 2 will be unknown since they are not hooked to anything, but they probably will be HIGH (ONE). Note that the data on pin 11 will be inverted, if pin 11 is LOW you will get a HIGH on bit 7.
378H BIT Output 379H Input Output 37AH Input Output Input _ 1 _ 14 _ 1 _ 14 16 _ 17 See Note 2 0 2 2 X X 1 3 3 X X 2 4 4 X X 3 5 5 X 15 4 6 6 X 13 16 _ 17 See Note 2 5 7 7 X 12 X X 6 8 8 X X X 7 9 9 X 10 _ 11 X X Table 1 Note 1: X means no connection to any DB-25 pin. Note 2: Bit 4 of 37AH as an output is used to control the interrupt IRQ7. When this bit is HIGH, IRQ7 is enabled and when this bit is LOW, IRQ7 is disabled.
There are three port addresses that are normally used on a PC for parallel ports: 3BCH, 378H, and 278H. When your PC is reset or turned on these three addresses are scanned by the BIOS in the order shown above. The first one that the BIOS finds with a parallel port installed is assigned the logical name LPT1. The second, LPT2, etc. You can connect the PPIO to a port located at any of these three addresses.
PPIO DESCRIPTION & CONNECTION The PPIO makes use of the eight output pins (pins 2 through 9) at address 378H to drive its eight outputs. It uses the upper four bits of address 379H (pins 13, 12, 10, and 11) for the upper four input bits of the PPIO. It uses the lower four input bits of address 37AH (pins 1, 14, 16, and 17) for the lower four input bits of the PPIO. This assumes you are using the same port addresses as in Table 1. In this way the PPIO can have eight inputs or eight outputs.
Figure 1 8 PPIO2899 Manual B&B Electronics Mfg Co Inc – 707 Dayton Rd - PO Box 1040 - Ottawa IL 61350 - Ph 815-433-5100 - Fax 815-433-5104
CONTROLLING THE PPIO USING GWBASIC Refer to the fragment of GWBASIC code in Figure 2 to see how to input the bits and make one 8-bit word. 100 OUT &H37A,&H04: 120 140 160 180 200 . . REM This disables the 37AH Outputs REM inside of the computer REM so that we can use REM 37AH as an input port. REM It also disables REM the IRQ7 interrupt. 300 A1=INP(&H37A) AND &H0F: 320 340 360 380 REM Input the REM lower 4 bits REM and mask OFF REM (force to 0) REM the upper 4 bits.
I/O Bit 0 1 2 3 4 5 6 7 Force I/O ON (Low) OR &H01 OR &H02 OR &H04 OR &H08 OR &H10 OR &H20 OR &H40 OR &H80 Table 2 Force I/O OFF (High) AND NOT &H01 AND NOT &H02 AND NOT &H04 AND NOT &H08 AND NOT &H10 AND NOT &H20 AND NOT &H40 AND NOT &H80 The big advantage of using the ANDing and ORing as shown in Table 2 is that it makes each PPIO pin independent. If you have, for instance, PPIO bit 2 ON and all of the rest of the bits OFF then your variable OB will be equal to 04H (00000100 binary).
When you input the 8-bit word using lines 300-460 of Figure 2, note that you also get the status of the outputs. If some I/O bits are used by the PPIO as outputs the status of the bits you read will tell you the status of the PPIO outputs. If PPIO output bit 0 is LOW then bit 0 of IB (the variable InputByte) will be HIGH (1). This can be used to check that the PPIO hardware is connected and is working properly.
CONTROLLING THE PPIO USING PASCAL The PPIO disk includes two source code files as an example of using the PPIO with the Pascal programming language. PPIO.PAS is the main routine of the example program. PPIOUNIT.PAS contains the routines for communicating with the PPIO. In the rest of this section, we assume that you know the Pascal programming language. Consult your reference manuals if you need help with the language. The Pascal Unit, PPIOUNIT.PAS handles communication with the parallel port.
PROCEDURE Set_IRQ_Off; BEGIN PORT[Control_Address] := $04;{Write 4 to disable IRQ} END; {Set_IRQ_Off} The function, In_Byte, returns the value of the variable, Input_Byte. It is defined as: FUNCTION In_Byte : Byte; BEGIN In_Byte := Input_Byte; End; { In_Byte } Notice that this does not read the value of the parallel port. The function Read_Input_Bit reads the port. The function, Out_Byte, returns the value of the variable Output_Byte.
The parallel port’s status register stores the upper nibble (four bits) of the input line status. Since the smallest value that can be read from the port is a byte, some work must be done to get only the upper nibble’s value. We read a byte from the status register and bitwise AND it with F0h (240 decimal, 11110000 binary). This sets the lower nibble of the byte to zero. The parallel port’s control register stores the low nibble of the input line status.
Notice that in the binary representation of the mask value, line zero’s mask has bit number zero set, and line one’s mask has bit number one set, etc. So, instead of retrieving the mask value from a table, the value is calculated by shifting 00000001b (1 decimal, 01 hexadecimal) right the same number of times as the desired line number. Once the mask value is calculated, it is bitwise ANDed with Input_Byte.
As with the function, In_Byte, the mask value is calculated by shifting 00000001b right the same number of times as the desired line number. Once the mask value is calculated, it is bitwise ANDed with Output_Byte. If the resulting value is non-zero, the line is ON and a boolean TRUE is returned, otherwise a boolean FALSE is returned. Notice that this function gets its value from Output_Byte that is set when we use the function, Set_Output_Bit. The value is not read from the port.
For example: Output_Byte Line_Number Status = 01010101b =3 =1 00000001b (1 decimal) shift-right 3 (Line_Number) = XOR AND 00000001b (Status) shift-right 3 (Line_Number) = OR 00001000b 11111111b 11110111b (mask 1) 01010101b (Output_Byte) 01010101b 00001000b (mask 2) 01011101b (New Output_Byte) For an example of an application that uses these functions, look at the source code in PPIO.PAS.
CONTROLLING THE PPIO USING C The PPIO disk includes three source code files as an example of using the PPIO with the C programming language. PPIO.C is the main routine of the example program. PPIOFUNC.C contains the routines for communicating with the PPIO. PPIOFUNC.H contains the function prototypes and definitions for use by PPIOFUNC.H and PPIO.C. In the rest of this section, we assume that you know the C programming language. Consult your reference manuals if you need help with the language. PPIOFUNC.
The function, Set_IRQ_OFF(), tells the parallel port not to generate any interrupts. This should be called immediately after Set_Start(). It is defined as: void Set_IRQ_Off(void) { outport (Control_Address, 0x04); } The function, In_Byte(), returns the value of the variable, Input_Byte. It is defined as: unsigned int In_Byte(void) { return (Input_Byte); } Notice that this does not read the value of the parallel port. The function Read_Input_Bit() reads the port.
The parallel port’s status register stores the upper nibble (four bits) of the input line status. Since the smallest value that can be read from the port is a byte, some work must be done to get only the upper nibble’s value. We read a byte from the status register and bitwise AND it with F0h (240 decimal, 11110000 binary). This sets the lower nibble of the byte to zero. The parallel port’s control register stores the low nibble of the input line status.
Notice that in the binary representation of the mask value, line zero’s mask has bit number zero set, and line one’s mask has bit number one set, etc. So, instead of retrieving the mask value from a table, the value is calculated by shifting 00000001b (1 decimal, 01 hexadecimal) right the same number of times as the desired line number. Once the mask value is calculated, it is bitwise ANDed with Input_Byte.
Line_Number = 3 Output_Byte = 10101010b 00000001b shift-right 3 (Line_Number) = AND 00001000b 10101010b (Output_Byte) 00001000b The function, Set_Output_Bit(), sets the selected output line ON of OFF. The function is defined as: void Set_Output_Bit(unsigned char Line_Number, boolean Status) { Output_Byte = (Output_Byte & ((1 << Line_Number) ^ 0xFF)) | (Status << Line_Number); outport(Base_Address, Output_Byte); } The variable, Output_Byte, stores the status of the output lines.
For example: Output_Byte = 01010101b Line_Number = 3 Status = 1 00000001b (1 decimal) shift-right 3 (Line_Number) = XOR AND 00000001b (Status) shift-right 3(Line_Number) = OR 00001000b 11111111b 11110111b (mask 1) 01010101b (Output_Byte) 01010101b 00001000b (mask 2) 01011101b (New Output_Byte) The function, Toggle(), is used to toggle the status of an output line. If the specified line is ON, it will be turned OFF. If it is OFF, it will be turned ON.
The function, Is_PPIO(), tests whether or not the PPIO is connected to the parallel port and functioning properly. This function should only be used if it is safe to toggle the state of the digital outputs.
Input_Byte = inp( Control_Address ) & 0x0F; if( (Input_Byte & Output_Byte) == Output_Byte ) { status |= 0x01; } } /* Restore the state of the digital outputs */ Output_Byte = old_value; outp( Base_Address, Output_Byte ); return (status); } This function writes A0h to the upper four digital outputs, then verifies that the digital output lines are in that state. Then it writes 50h to the upper four digital outputs and verifies that the digital outputs are in set properly.
INTERFACING TO THE PPIO Each output of the PPIO is capable of handling currents as high a 500 mA when the output is low. This means that you can connect a relay or a light or other load between the output and a positive power supply voltage. See Figure 3 for an example output. Whenever the PPIO output in the example is LOW the relay will turn ON and close the contact. To turn ON the relay you should use the force I/O ON portion of Table 2.
Figure 4 28 PPIO2899 Manual B&B Electronics Mfg Co Inc – 707 Dayton Rd - PO Box 1040 - Ottawa IL 61350 - Ph 815-433-5100 - Fax 815-433-5104
EXAMPLE USE OF THE PPIO Figure 5 shows a simple use of the PPIO to create an automatic Heating and Air Conditioning system. The top relay controls the Air Conditioning system. The other relay controls the heating system. The top thermostat controls the Air and the bottom one controls the Heat. On the PPIO I/O two and three are outputs to control the relays. PPIO I/O zero and one are inputs that are controlled by the thermostats.
Heat and the Air. See line 230. If IB is equal to two then the 72 degree thermostat is on and the 78 degree one is off. At this time we want both the Heat and the Air off. See line 260. If IB is equal to 3 then both thermostats are on and the temperature must be above 78 degrees. Line 280 turns on the Air Conditioner.
90 REM IB IS THE INPUT BYTE AND OB IS THE OUTPUT BYTE 100 OUT &H37A,&H4: REM SET UP 37A FOR INPUTTING 110 OUT &H378,&H0: REM FORCE I/O BITS 0&1 HIGH 120 REM TO USE THEM AS INPUTS 130 REM AND FORCE THE REST OF 140 REM THE BITS HIGH (OFF) 150 REM TO TURN EVERYTHING ELSE OFF.
APPENDIX Hexadecimal Numbers Hexadecimal numbers are base-16 numbers. Instead of only using the digits "0" through "9" to represent a number, the letters "A" through "F" are also used. Table 3 shows the value of the individual digits in the hexadecimal numbering system. When we write a hexadecimal number we add an upper or lower case "H" to the end of it to indicate that it is a hexadecimal number. Table 4 can be used to convert a number between 0 and 255 into its hexadecimal representation.
Decimal to Hexadecimal Conversion Second Digit: First Digit: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 15 1 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 2 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 3 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 4 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 5 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 6 9