home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / textinfo / pc_tech.arj / PC-TECH7.TXT < prev   
Encoding:
Text File  |  1988-04-22  |  16.0 KB  |  503 lines

  1.   
  2.  
  3.  
  4.  
  5.  
  6.  
  7. This document  details the RS232 parallel printer ports of the IBM-PC
  8. Each of the printer ports conforms to a modified Centronics Parallel
  9. Interface. The connection to the PC is through a DB25 25 pin connector.
  10. The IBM-PC will support up to three parallel ports. Each port provides
  11. 12 TTL outputs and 5 TTL inputs.  This document contains the following
  12. data:
  13.       a. DB25 PINOUT, and signal names where known.
  14.       b. PORT addresses of each parallel port.
  15.       c. DATA, CONTROL, and INPUT PORTS pinouts w/bit positions
  16.          within each byte.
  17.       d. Example programs written in C highlighting input and
  18.          output to the ports.
  19.       e. Clock display circuit diagram w/parts list.
  20.       f. Closing comment.
  21.  
  22.                            DB25 PINOUT
  23.  
  24.                         IMMMMMMMMMMMMMM;
  25.            -STROBE ---> :  1           :
  26.                         :         14   : <------  -AUTO FEED
  27.             D0 -------> :  2           :
  28.                         :         15   : ------> ?
  29.             D1 -------> :  3           :
  30.                         :         16   : <------ INITIAL
  31.             D2 -------> :  4           :
  32.                         :         17   : <------  -?
  33.             D3 -------> :  5           :
  34.                         :         18   : <------+
  35.             D4 -------> :  6           :        |
  36.                         :         19   :    G   |
  37.             D5 -------> :  7           :        |
  38.                         :         20   :    R   |                      IMM;
  39.             D6 -------> :  8           :        |  Output Signal ----> :  :
  40.                         :         21   :    O   |  (From Computer)     HMM<
  41.             D7 -------> :  9           :        |
  42.                         :         22   :    U   |
  43.             ACK <------ :  10          :        |
  44.                         :         23   :    N   |
  45.            -BUSY <----- :  11          :        |                      IMM;
  46.                         :         24   :    D   |   Input Signal <---- :  :
  47.             PE <------- :  12          :        |   (To Computer)      HMM<
  48.                         :         25   : <------+
  49.             SEL <------ :  13          :
  50.                         HMMMMMMMMMMMMMM<
  51.  
  52.  
  53.            Pins 1, 11, 14, 17 are negative TTL, meaning
  54.  
  55.                        0 is ON & 1 is OFF
  56.  
  57.  
  58.  
  59.          PARALLEL Port Addresses    DATA PORT (Output from computer)
  60.  
  61.  
  62.          LPT1: 956     3BC Hex
  63.          LPT2: 888     378 Hex
  64.          LPT3: 632     278 Hex
  65.  
  66.  
  67.          IMMMMMMQMMMMMMQMMMMMMQMMMMMMQMMMMMMQMMMMMMQMMMMMMQMMMMMM;
  68.          :      3      3      3      3      3      3      3      :
  69.          :      3      3      3      3      3      3      3      :
  70.          :  D7  3  D6  3  D5  3  D4  3  D3  3  D2  3  D1  3  D0  :
  71.          :      3      3      3      3      3      3      3      :
  72.          :      3      3      3      3      3      3      3      :
  73.          HMMMMMMOMMMMMMOMMMMMMOMMMMMMOMMMMMMOMMMMMMOMMMMMMOMMMMMM<
  74.  
  75.  
  76. PIN  #      9       8      7      6      5       4      3       2
  77. BIT  #      7       6      5      4      3       2      1       0
  78. VALUE     128      64     32     16      8       4      2       1
  79.  
  80.  
  81.  
  82.          PARALLEL Port Addresses    CONTROL PORT (Output from computer)
  83.  
  84.  
  85.          LPT1: 958     3BE Hex
  86.          LPT2: 890     37A Hex
  87.          LPT3: 634     27A Hex
  88.  
  89.  
  90.  
  91.          IMMMMMMQMMMMMMQMMMMMMQMMMMMMQMMMMMMQMMMMMMQMMMMMMQMMMMMM;
  92.          :      3      3      3      3      3      3      3      :
  93.          :      3      3      3      3      3      3      3      :
  94.          :  NA  3  NA  3  NA  3  NA  3  -?  3 INIT 3  -AF 3 -ST  :
  95.          :      3      3      3      3      3      3      3      :
  96.          :      3      3      3      3      3      3      3      :
  97.          HMMMMMMOMMMMMMOMMMMMMOMMMMMMOMMMMMMOMMMMMMOMMMMMMOMMMMMM<
  98.  
  99.  
  100. PIN  #      -       -      -      -     17      16     14       1
  101. BIT  #      -       -      -      -      3       2      1       0
  102. VALUE       -       -      -      -      8       4      2       1
  103.  
  104.  
  105.          Notes:
  106.  
  107.               1. -? denotes negative TTL signal, name unknown.
  108.               2. INIT is INITIAL.
  109.               3. -AF is negative TTL signal, AUTOFEED is signal name.
  110.               4. -ST is negative TTL siganl, STROBE is signal name.
  111.               5. NA not applicable.
  112.  
  113.  
  114.  
  115.  
  116.          PARALLEL Port Addresses   INPUT PORT (Input to computer)
  117.  
  118.  
  119.          LPT1: 957     3BD Hex
  120.          LPT2: 889     379 Hex
  121.          LPT3: 633     279 Hex
  122.  
  123.  
  124.  
  125.          IMMMMMMQMMMMMMQMMMMMMQMMMMMMQMMMMMMQMMMMMMQMMMMMMQMMMMMM;
  126.          :      3      3      3      3      3      3      3      :
  127.          :      3      3      3      3      3      3      3      :
  128.          : -BUSY3  ACK 3  PE  3  SEL 3   ?  3  NA  3  NA  3  NA  :
  129.          :      3      3      3      3      3      3      3      :
  130.          :      3      3      3      3      3      3      3      :
  131.          HMMMMMMOMMMMMMOMMMMMMOMMMMMMOMMMMMMOMMMMMMOMMMMMMOMMMMMM<
  132.  
  133.  
  134. PIN  #     11      10     12     13     15       -      -       -
  135. BIT  #      7       6      5      4      3       -      -       -
  136. VALUE     128      64     32     16      8       -      -       -
  137.  
  138.  
  139.          Notes:
  140.  
  141.               1. ?  signal name unknown.
  142.               2. NA not applicable.
  143.               3. -BUSY is negative TTL signal.
  144.  
  145.  
  146.  
  147.  
  148.     Example of Negative TTL logic
  149.  
  150.  
  151.                 PIN  #      6    5     4     3     2
  152.                 BIT  #      4    3     2     1     0
  153.                 VALUE      16    8     4     2     1
  154.  
  155.  
  156.       IMMMMMQMMMMMQMMMMMQMMMMMQMMMMMQMMMMMQMMMMMQMMMMM;
  157.       :     3     3     3     3     3     3     3     :
  158.       :  -  3  -  3  -  3  1  3  0  3  0  3  0  3  0  :  DATA PORT
  159.       :     3     3     3     3     3     3     3     :
  160.       HMMMMMOMMMMMOMMMMMOMMMMMOMMMMMOMMMMMOMMMMMOMMMMM<
  161.  
  162.                            |     |     |     |     |
  163.                            |     |     |     |     |
  164.  
  165.                         IMMMMMQMMMMMQMMMMMQMMMMMQMMMMMQMMMMMQMMMMMQMMMMM;
  166.                         :     3     3     3     3     3     3     3     :
  167.             INPUT PORT  :  0  3  0  3  0  3  0  3  0  3  -  3  -  3  -  :
  168.                         :     3     3     3     3     3     3     3     :
  169.                         HMMMMMOMMMMMOMMMMMOMMMMMOMMMMMOMMMMMOMMMMMOMMMMM<
  170.  
  171.                PIN  #     11     10     12    13    15
  172.                BIT  #      7      6      5     4     3
  173.                VALUE     128     64     32    16     8
  174.  
  175.  
  176.          Notes:
  177.  
  178.              1. A 1 bit in the DATA port causes 2.5 to 5.0 volts
  179.                 to appear on the cooresponding pin on the DB25 connector.
  180.                 In the example above PIN # 6 is on.
  181.  
  182.              2. BIT # 7 of the INPUT port has negative TTL logic, where
  183.                 2.5 to 5.0 volts on PIN # 11 is logic level zero.  The other
  184.                 bits of the INPUT port are normal TTL logic.
  185.  
  186.  
  187. /* CLOCKC.C ==> This program runs the binary clock */
  188.  
  189. #include "conio.h"
  190. #define PORT_HR         634
  191. #define PORT_MIN        632
  192. #define OFF_MIN         0
  193. #define OFF_HRS         0x0b
  194. #define WINK            64  /* bit 7 of minute byte used for seconds */
  195.  
  196. main()
  197. {
  198.    unsigned char ctr_min, ctr_hr, status, hours, minutes, seconds,
  199.                  hundrds, lastsec, second_on();
  200.    void time(), turn_on(), turn_off();
  201.  
  202.    /* start by turning off all circuits */
  203.  
  204.    ctr_min = OFF_MIN;
  205.    ctr_hr = OFF_HRS;
  206.  
  207.    outp (PORT_HR, ctr_hr);
  208.    outp (PORT_MIN, ctr_min);
  209.  
  210.    /* the clock will run indefinately */
  211.  
  212.    for (;;) {
  213.  
  214.        /* get the time */
  215.        time(&hours, &minutes, &seconds, &hundrds);
  216.  
  217.        /* the hours require special handling, DOS returns hours in 24  */
  218.        /* hour format. Convert to 12 hr format. Next XOR hours against */
  219.        /* OFF_HRS to get the proper bit pattern for the hours.         */
  220.  
  221.        ctr_hr = ((hours = hours % 12) ? hours : 12) ^ OFF_HRS;
  222.  
  223.        /* the minutes are easy, output ASIS */
  224.  
  225.        ctr_min = minutes;
  226.  
  227.        /* Display the hours and minutes */
  228.  
  229.        outp (PORT_HR, ctr_hr);
  230.        outp (PORT_MIN, ctr_min);
  231.  
  232.        /* wink the seconds, up to the next minute */
  233.  
  234.  
  235.  
  236.  
  237.        for (lastsec = seconds; seconds <= 59; ) {
  238.  
  239.            time (&hours, &minutes, &seconds, &hundrds);
  240.  
  241.            if (lastsec != seconds) { /* seconds has changed */
  242.  
  243.                lastsec = seconds;
  244.  
  245.                /* if second is on turn off, else turn on */
  246.  
  247.                if (!second_on(ctr_min, WINK))
  248.  
  249.                  turn_on (PORT_MIN, &ctr_min);
  250.                else
  251.  
  252.                  turn_off (PORT_MIN, &ctr_min);
  253.  
  254.            }
  255.  
  256.            /* seconds up to 59, exit loop */
  257.  
  258.            if (seconds == 59)
  259.                break;
  260.  
  261.  
  262.        }
  263.    }
  264.  
  265. }
  266.  
  267. unsigned char second_on(control, sec)
  268. unsigned char control, sec;
  269. {
  270.    return (control & sec);
  271.  
  272. }
  273.  
  274. void turn_on (port, control)
  275. unsigned char *control;
  276. int port;
  277. {
  278.    *control = *control | WINK;
  279.  
  280.    outp (port, *control);
  281.  
  282. }
  283.  
  284. void turn_off (port, control)
  285. unsigned char *control;
  286. int port;
  287. {
  288.    *control = *control & ~WINK;
  289.  
  290.    outp (port, *control);
  291.  
  292. }
  293.  
  294.  
  295.  
  296. /* PORTTST.C -- This program is used to determine if the info  */
  297. /* I have gathered about Input Ports is correct.  The program  */
  298. /* is to send pre-determined values to PORT 632 bits 0-4       */
  299. /* the bits coorespond to pins 2-6 of a printer parallel port. */
  300. /* Pins 2-6 are then connected to Pins 15,13,12,10,11 respec-  */
  301. /* tively.  Pins 10-13,15 coorespond to Bits 7-3 of Input PORT */
  302. /* 633.  For a given input a pre-determined set of values will */
  303. /* be returned. Pin 11 of the Input port is negative TTL       */
  304.  
  305. #define PORTE     633
  306. #define PORTD     632
  307. #include "conio.h"
  308.  
  309. main()
  310. {
  311.     static char test_values [] = {16, 17, 18, 20, 24, 0};
  312.  
  313.     /* test_value =>  16        return 0  */
  314.     /* test_value =>  17        return 1  */
  315.     /* test_value =>  18        return 2  */
  316.     /* test_value =>  20        return 4  */
  317.     /* test_value =>  24        return 8  */
  318.     /* test_value =>  0         return 16 */
  319.  
  320.     unsigned char bit, send;
  321.     void porttst();
  322.  
  323.     /* turn off all bits in send */
  324.  
  325.     for (bit = 0; bit < sizeof(test_values); bit++) {
  326.  
  327.         porttst (PORTD, PORTE, *(test_values + bit));
  328.  
  329.     }
  330.  
  331. }
  332. void porttst (pd, pe, send)
  333. int pd, pe;
  334. unsigned char send;
  335. {
  336.     unsigned char result;
  337.     int bits();
  338.  
  339.     outp (pd, send);
  340.  
  341.     result = inp(pe);
  342.  
  343.     /* display the bit patterns sent and recieved */
  344.  
  345.     printf ("\nOut Value ");
  346.     bits (4, 0, send);
  347.     printf (" In Value ");
  348.     bits (7, 3, result);
  349.  
  350. }
  351.  
  352.  
  353.  
  354.          OUTPUT from PORTTST.C
  355.  
  356.  
  357. C>porttst
  358.  
  359.     Out Value 10000 In Value 00000
  360.     Out Value 10001 In Value 00001
  361.     Out Value 10010 In Value 00010
  362.     Out Value 10100 In Value 00100
  363.     Out Value 11000 In Value 01000
  364.     Out Value 00000 In Value 10000
  365.  
  366.  
  367.  
  368.  
  369. /* DTIME.C ==> This program generates binary code representing    */
  370. /* 0 to 12, which are then output from the computers control port */
  371. /* (actually part of the parallel printer port) to 4 LED's that   */
  372. /* are connected to pins 1, 14, 16 & 17 of the parallel port      */
  373. /* with the first being binary digit 0 and the latter being digit */
  374. /* 3.                                                             */
  375. /* See diagram of the Control Port for more data.                 */
  376.  
  377. #define CONTROL_PORT  634
  378. #define XOR           0xb
  379.  
  380. main()
  381. {
  382.     char count, send;
  383.     int bits();
  384.  
  385.     printf("\nCOUNT\tHOUR\t\tXOR\t    ACTUAL BITS\n");
  386.  
  387.     for (count = 0; count <= 12; count++) {
  388.  
  389.         send = count ^ XOR;
  390.         outp(CONTROL_PORT, send);
  391.  
  392.         /* in practice the following is not used. it exists */
  393.         /* for illustration purposes only.                  */
  394.  
  395.         printf ("\n%4d\t", count);
  396.         bits (3, 0, count);
  397.  
  398.         printf ("\t\t");
  399.         bits (3, 0, XOR);
  400.  
  401.         printf ("\t\t");
  402.         bits (3, 0, send);
  403.  
  404.         }
  405.  
  406. }
  407.  
  408. COUNT    HOUR        XOR        ACTUAL BITS
  409.  
  410.    0    0000        1011        1011
  411.    1    0001        1011        1010
  412.    2    0010        1011        1001
  413.    3    0011        1011        1000
  414.    4    0100        1011        1111
  415.    5    0101        1011        1110
  416.    6    0110        1011        1101
  417.    7    0111        1011        1100
  418.    8    1000        1011        0011
  419.    9    1001        1011        0010
  420.   10    1010        1011        0001
  421.   11    1011        1011        0000
  422.   12    1100        1011        0111
  423.  
  424.  
  425.           CLOCK CIRCUIT
  426.  
  427.                        Minutes Display (uses DATA PORT)
  428.  
  429.  
  430.       PIN #            R1         D1
  431.  
  432.            2      o----/\/\/-------|<-------+
  433.                                             |    <--- Ground uses pins
  434.                        R2         D2        |         18 - 25.
  435.                                             |
  436.            3      o----/\/\/-------|<-------|
  437.                                             |
  438.                        R3         D3        |
  439.                                             |   Parts List:
  440.            4      o----/\/\/-------|<-------|
  441.                                             |   R1 - R10: 220f +w resistors
  442.                        R4         D4        |   D1 - D10: 2.5vdc @20ma LED's
  443.                                             |
  444.            5      o----/\/\/-------|<-------|    Misc:
  445.                                             |
  446.                        R5         D5        |   1 - DB25 male connector
  447.                                             |       snap on is best.
  448.            6      o----/\/\/-------|<-------|
  449.                                             |   1 - 25 line ribbon cable
  450.                        R6         D6        |
  451.                                             |
  452.            7      o----/\/\/-------|<-------|
  453.                                             p
  454.  
  455.  
  456.                        Hours Display (uses CONTROL PORT)
  457.  
  458.  
  459.  
  460.       PIN #            R7         D7
  461.  
  462.            1      o----/\/\/-------|<-------+
  463.                                             |    <--- Ground uses pins
  464.                        R8         D8        |         18 - 25.
  465.                                             |
  466.           14      o----/\/\/-------|<-------|
  467.                                             |
  468.                        R9         D9        |
  469.                                             |
  470.           16      o----/\/\/-------|<-------|
  471.                                             |
  472.                        R10        D10       |
  473.                                             |
  474.           17      o----/\/\/-------|<-------|
  475.                                             p
  476.  
  477.  
  478.  
  479.     Closing comment.
  480.  
  481.     I hope that the information contained within this document is usefull,
  482.     although usefullness depends upon who is doing the looking.
  483.  
  484.     The programs listed are very simple in terms of capabilities.  If there
  485.     is anyone in BBS Land who is capable (read willing) of writing a TSR
  486.     that can drive the clock circuit, Please contact me:
  487.  
  488.     Michael N. White, President
  489.     MNW Consulting
  490.     6715 Red Top Rd
  491.     Takoma Park, Md. 20912
  492.     (301)559-5585
  493.  
  494.     The TSR should come with theory of operation and source code.  The
  495.     program is to be used for demonstration purposes only, and to further
  496.     my knowledge of TSR.
  497.  
  498.  
  499.   
  500. /* turn off all bits in send */
  501.  
  502.     for (bit = 0; bit < sizeof(test_values); bit++) {