next up previous
Next: Polling Input Pins Up: PARAPIN: A Parallel Port Previous: Configuring Pins as Inputs


Setting Output Pin States

Once Parapin has been initialized (Section 5), and pins have been configured as output pins (Section 6), values can be asserted on those pins using the following functions:

        void set_pin(int pins);
        void clear_pin(int pins);
        void change_pin(int pins, int state);

The pins argument of all three functions accepts the LP_PINnn constants described in Section 3. set_pin turns pins on, electrically asserting high TTL values. clear_pin turns pins off, electrically asserting low TTL values. The convenience function change_pin does the same thing as set_pin and clear_pin; its state argument takes one of the constants LP_SET or LP_CLEAR. Calling change_pin(pins, LP_SET) has exactly the same effect as calling set_pin(pins).

These three functions will only have effects on pins that were previously configured as output pins as described in Section 6. Attempting to assert a value on an input pin will have no effect.

Note that while the direction of Pins 2-9 must be the same at all times (i.e., either all input or all output), the actual values of these pins are individually controllable when they are in output mode.

Examples:

        pin_output_mode(LP_PIN01|LP_DATA_PINS|LP_PIN14|LP_PIN16|LP_PIN17);
        /* All these pins are now in output mode */

        set_pin(LP_PIN01 | LP_PIN04 | LP_PIN07 | LP_PIN14 | LP_PIN16);
        /* Pins 1, 4, 7, 14, and 16 are all on */

        clear_pin(LP_PIN01 | LP_PIN16);
        /* Pins 1 and 16 are now off */

        change_pin(LP_PIN01 | LP_PIN02, some_integer ? LP_SET : LP_CLEAR);
        /* Pins 1 and 2 are now off if and only if some_integer == 0 */


next up previous
Next: Polling Input Pins Up: PARAPIN: A Parallel Port Previous: Configuring Pins as Inputs
Jeremy Elson 2000-03-30