home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / MOUSE / GPIBLPT.ZIP / GPIB.DOC < prev    next >
Encoding:
Text File  |  1990-10-18  |  11.8 KB  |  331 lines

  1.      Using a Printer Port for Simple GPIB/IEEE-488 Operation
  2.  
  3.         All programs and documentation, Copyright 1990 by
  4.  
  5.                               Sydex
  6.                           P.O. Box 5700
  7.                         Eugene, OR  97405
  8.                      Voice:  (503)  683-6033
  9.                      FAX:    (503)  683-1622
  10.                      Data:   (503)  683-1385
  11.  
  12.                       All Rights Reserved.     
  13.  
  14. INTRODUCTION
  15.  
  16. A while back (quite a while, actually) we had a need for the  use 
  17. of a color plotter for some 1-2-3 spreadsheet graphs that we were 
  18. doing.  A friend offered us the use of his HP 7470--but there was 
  19. a  catch.   It seems that the thing  had  the  HPIB/GPIB/IEEE-488 
  20. interface, not a straight serial or parallel connection.
  21.  
  22. This  posed  a problem.  A GPIB card for a PC would set  us  back 
  23. about $350--and there was no guarantee that 1-2-3 could even talk 
  24. to the thing.
  25.  
  26. I recalled that the old Commodore Pet, as well as the Victor 9000 
  27. and  the Osborne I could do a limited amount of GPIB  interfacing 
  28. with their parallel ports--so why not a PC?  I even had an  extra 
  29. port that I wasn't using.
  30.  
  31. After looking at the IBM Tech Reference manual, I discovered that 
  32. there's  a problem with this.  Although the IBM Parallel  Printer 
  33. adapter bills itself as being bi-directional (input and  output), 
  34. it's  hard-wired  for output mode only!  Now,  I  probably  could 
  35. drive  the  plotter  with  an  output-only  port,  but  this  was 
  36. aesthetically unsatisfying.  How could the parallel port be wired 
  37. to be REALLY bi-directional?
  38.  
  39. The offending item appeared to be the 74LS374 IC used as the data 
  40. output  latch--the  Output Enable (OE*) pin was  grounded  (wired 
  41. active).  However, there was a spare bit (bit 5) available on the 
  42. 74LS174  6-bit  latch  used to control  the  printer  handshaking 
  43. lines.   The solution was obvious--wire the unused bit to  Output 
  44. Enable on the LS374--viola!
  45.  
  46. Incidentally,  if  you're  using an IBM  PS/2,  ignore  the  next 
  47. section, IBM finally came to its senses and implemented the  same 
  48. change  when  it brought the PS/2 out--you can use  the  software 
  49. that accompanies this documentation will operate with no changes.
  50.  
  51. ALTERING A PARALLEL ADAPTER
  52.  
  53. Once  again,  note  that  this applies to PC  XT-  and  AT-  type 
  54. computers  (ISA  bus) only.  If you've got a PS/2,  your  changed 
  55. parallel port is standard equipment.
  56.  
  57. I'll  discuss what has to be done to the simple  $15.00  born-in-
  58. Taiwan parallel adapter, but note that these changes can be  made 
  59. to  most  other parallel adapters that use  generic  LSTTL  IC's.  
  60. This  category  also  includes a  number  of  monochrome  display 
  61. adapters.
  62.  
  63. You should know one end of a soldering iron from another; a short 
  64. length  of wire-wrap or other small-gauge wire and an  X-acto  or 
  65. other hobbyist utility knife is useful.  The change is simple and 
  66. will take you about 15 minutes (assuming your iron is hot).
  67.  
  68. Most inexpensive parallel-only adapters come from the same  basic 
  69. design--12 SSI IC's on a half-slot card.
  70.  
  71. First, locate the 74LS374 IC adjacent to the printer connector on 
  72. the  rear  of  the  board.  Note that one end of  the  IC  has  a 
  73. recessed  notch on one end.  Also locate the 74LS174  just  above 
  74. it.  Note the pin numbering:
  75.  
  76.  
  77.              74LS374                             74LS174            
  78.                                                                     
  79.               +-U-+                               +-U-+             
  80.        Pin 1 [|   |] Pin 20                Pin 1 [|   |] Pin 16     
  81.        Pin 2 [|   |] Pin 19                Pin 2 [|   |] Pin 15     
  82.        Pin 3 [|   |] Pin 18                Pin 3 [|   |] Pin 14     
  83.        Pin 4 [|   |] Pin 17                Pin 4 [|   |] Pin 13     
  84.        Pin 5 [|   |] Pin 16                Pin 5 [|   |] Pin 12     
  85.        Pin 6 [|   |] Pin 15                Pin 6 [|   |] Pin 11     
  86.        Pin 7 [|   |] Pin 14                Pin 7 [|   |] Pin 10     
  87.        Pin 8 [|   |] Pin 13                Pin 8 [|   |] Pin 9     
  88.        Pin 9 [|   |] Pin 12                       +---+
  89.       Pin 10 [|   |] Pin 11               
  90.               +---+                       
  91.  
  92. Remembering  that the pin numbering becomes "mirrored", turn  the 
  93. board  over  and locate pin 1 of the 74LS374.  Note  that  it  is 
  94. connected by an enlargement of the solder pad to the wide  ground 
  95. trace  above  it.   Being careful not to sever  the  wide  ground 
  96. trace, take your knife and separate the pin 1 pad from the ground 
  97. trace.  Check your work with a continuity tester.
  98.  
  99. Next,  locate pin 7 on the 74LS174.  Take a short piece  of  wire 
  100. and connect pin 1 on the 74LS374 to this pin.  Be neat and  check 
  101. your work.
  102.  
  103. That's  it!  Your card will still function normally as a  printer 
  104. adapter, but now has a true bi-directional mode of operation.
  105.  
  106. BUILDING A CABLE
  107.  
  108. The  next  task  is to build a cable  from  the  25-pin  parallel 
  109. printer   connection   to   a   24-pin   male   GPIB   connector.  
  110. Unfortunately, some "criss-crossing" of connections is  necessary 
  111. between  the  two, so you can either solder up  a  multiconductor 
  112. cable  between  a male solder-cup DB25P connector and  a  24  pin 
  113. "Blue Ribbon" connector, or you can do what I did.
  114.  
  115. I  took a length of 24-conductor ribbon cable and crimped a  male 
  116. DP25P  IDC  connector on one end and a male 24  pin  "centronics" 
  117. connector  (Scotch  No. 3548, for example) on the other  end.   I 
  118. then  took an inexpensive solder-type DB25 "breakout box"  (cost: 
  119. about $7.50) and performed my "wire weaving" in it.
  120.  
  121. In  any case, you'll have to make sure the wiring works out  this 
  122. way:
  123.  
  124.  
  125.         GPIB Pin      Signal Name     DB-25
  126.         ========      ===========     =====
  127.  
  128.           1             -DATA 1         2
  129.           2             -DATA 2         3
  130.           3             -DATA 3         4
  131.           4             -DATA 4         5
  132.           5             -EOI            13
  133.           6             -DAV            1
  134.           7             -NRFD           16
  135.           8             -NDAC           17
  136.           9             -IFC            10
  137.           10            -SRQ            15
  138.           11            -ATN            14
  139.           12            GND             18
  140.           13            -DATA 5         6
  141.           14            -DATA 6         7
  142.           15            -DATA 7         8
  143.           16            -DATA 8         9
  144.           17            -REN            12
  145.           18            GND             19
  146.           19            GND             20
  147.           20            GND             21
  148.           21            GND             22
  149.           22            GND             23
  150.           23            GND             24
  151.           24            GND             25
  152.  
  153. Check your work for accuracy!
  154.  
  155. THE SOFTWARE
  156.  
  157. We've  supplied the source and object for a set  of  "C"-callable 
  158. routines to manage the GPIB interface.  We use Microsoft "C"  and 
  159. Microsoft  MASM,  though  there  should be  no  reason  why  this 
  160. wouldn't also work with Borland's Turbo "C" and TASM.  Note  that 
  161. we make use of the "small" memory model--you could alter this  to 
  162. use  the huge, large or compact models by making sure  that  full 
  163. segment-offset  addresses are handled and the  necessary  segment 
  164. register juggling is done.
  165.  
  166. Similarly, there's no reason that the package couldn't be modifed 
  167. to work with BASIC or FORTRAN with appropriate changes.
  168.  
  169. The  source  file  is the file "GPIB_C.ASM"  and  is  written  in 
  170. 8086 assembly language.  These are the routines that are included 
  171. in it:
  172.          int GPIB_Init( int io_port, int our_address)
  173.  
  174.          Initializes the GPIB interface. "io_port" is the address 
  175.          of the printer adapter being used--usually 0x378 for the 
  176.          first and 0x278 for the second.  If your adapter is part 
  177.          of  a monochrome display adapter, its address is  0x3bc.  
  178.          "Our_address"  is the GPIB talker/listener address  that 
  179.          the PC is to consider to be its own.
  180.  
  181.          The interface is initialized; if no response can be had, 
  182.          a  status of -1 is returned; a return of 0 signifies  no 
  183.          error.
  184.  
  185.          int GPIB_Send( int listen, char what)
  186.  
  187.          This routine sends a single character to the GPIB device 
  188.          addressed  by  "listen".  If this function  returns  -1, 
  189.          there's a problem, otherwise the return value is 0.
  190.  
  191.          int GPIB_PutStr( int listen, char *string, int count)
  192.  
  193.          This routine sends a string of bytes to the GPIB  device 
  194.          addressed by "listen".  "count" bytes are sent.  Returns 
  195.          are -1 for failure, 0 for success.
  196.  
  197.          int GPIB_Stat(void);
  198.  
  199.          Simply  returns  the  value of the  GPIB  status  lines.  
  200.          These  are  encoded in the lower 8 bits  of  the  return 
  201.          value as:
  202.  
  203.                IFC REN EOI SRQ NDAC NRFD ATN DAV
  204.  
  205.  
  206.          int GPIB_Get( int listen)
  207.  
  208.          Reads  a  character from the GPIB  device  addressed  by 
  209.          "listen".  Returns the character or -1 if error.
  210.  
  211.          int GPIB_GetStr( int listen, char *buf)
  212.  
  213.          Reads  a  string of data from the  device  addressed  by 
  214.          "listen".   Returns the number of bytes read into  "buf" 
  215.          or -1 if error.
  216.  
  217.  
  218.  
  219.  
  220.  
  221.          int GPIB_SerPoll( int listen)
  222.  
  223.          Executes  a  Serial  Poll on  the  device  at  "listen".  
  224.          Returns  the serial poll status in the lower 8  bits  of 
  225.          the return value or -1 if error.
  226.  
  227.  
  228.          int GPIB_PutAdd( char what)
  229.  
  230.          GPIB primitive.  Puts the value "what" out as an address 
  231.          byte.  Returns 0 if success or -1 if failure.
  232.  
  233.          int GPIB_PutData( char what)
  234.  
  235.          GPIB  primitive.   Puts the value "what" out as  a  data 
  236.          byte.  Returns 0 if success or -1 if failure.
  237.  
  238.          int GPIB_GetData(void);
  239.  
  240.          GPIB  primitive.  Reads the value on the GPIB bus  as  a 
  241.          data value and returns it or -1 if failure.
  242.  
  243. As  an example of usage, a  terminate-and-stay-resident  program, 
  244. LPPLOT,  is included to talk to an HP 7470 plotter  disguised  as 
  245. LPT3.  It works--but note that the GPIB version of the 7470 lacks 
  246. arc and circle-drawing HPGL extensions.
  247.  
  248. MISCELLANY
  249.  
  250. Clearly,  this  scheme represents a way to get by on  the  cheap.  
  251. This method will not support all GPIB functions, nor is it likely 
  252. to  be  able to drive more than one GPIB device  at  a  time--the 
  253. output current drive capability just isn't there.
  254.  
  255. If  I  had it to do over again, I'd change the way  I  wired  the 
  256. cable  and  wire the ATN signal to pin 10 on the DB25 so  that  I 
  257. could use the interrupt capability on the printer card to service 
  258. asynchronous requests such as Parallel Poll.
  259.  
  260. But  the thing does work--and with a little work, 2 PC's  could  be 
  261. coupled to do full 8-bit transfers in either direction.   Current 
  262. printer port data transfer schemes "nibble" the data, rather than 
  263. use the full data bus width.
  264.  
  265. USAGE AND LICENSING
  266.  
  267. License is hereby granted by Sydex for single-use  non-commercial 
  268. application  of this code.  Contact Sydex for commercial use  and 
  269. system-integration licensing rights.  Any other use of this  code 
  270. or  documentation is hereby prohibited without  explicit  written 
  271. permission from Sydex.
  272.  
  273.  
  274. Text and programs by Chuck Guzis
  275.  
  276. Certain  products  and  terms referred to in  this  document  are 
  277. property of the following firms:
  278.  
  279.     Hewlett-Packard Corporation, International Business Machines, 
  280.     Microsoft  Corporation,  Borland  International,  Centronics, 
  281.     ITT-Cannon, 3M Corporation.
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.