Performing Digital IO Operations

Universal Driver Documentation

Description

The driver supports four types of direct digital I/O operations: input bit, input byte, output bit, and output byte. Digital I/O is fairly straightforward - to perform digital input, you provide a pointer to the storage variable and indicate the port number and bit number if relevant. To perform digital output, you provide the output value and the output port and bit number, if relevant.

The four Universal Driver functions described here are dscDIOInputByte(), dscDIOInputBit(), dscDIOOutputByte(), dscDIOOutputBit(), dscDIOSetBit(), and dscDIOClearBit().

Step-By-Step Instructions

If you are performing digital input, create and initialize a pointer to hold the returned value of type BYTE*.

Some boards have digital I/O ports with fixed directions, while others have ports with programmable directions. Make sure the port is set to the required direction, input or output. Use function dscDIOSetConfig() to set the direction if necessary.

Call the selected digital I/O function. Pass it a BYTE port value, and either a pointer to or a constant BYTE digital value. If you are performing bit operations, then you will also need to pass in a BYTE value telling the driver which particular bit (0-7) of the DIO port you wish to operate on.

Example of Usage for Digital I/O Operations

...
DSCB dscb;
BYTE port, bit;
BYTE digital_value;	// the value ranges from 0 to 255 

/* 1. input bit - read bit 3 of port 0 (port 0 is in input mode) */
port = 0;
bit = 3;
if ((result = dscDIOInputBit(dscb, port, bit, &digital_value)) != DE_NONE)
    return result;

/* 2. input byte - read all 8 bits of port 0 (port 0 is in input mode) */
port = 0;
if ((result = dscDIOInputByte(dscb, port, &digital_value)) != DE_NONE)
    return result;

/* 3. output bit - 3 examples (assumes port 2 is in output mode) */
port = 2;
bit = 7;

/* 3a. dscDIOOutputBit(), set bit 7 of port 2 to 1, leave other bits alone */
if ((result = dscDIOOutputBit(dscb, port, bit, 1)) != DE_NONE)
    return result;

/* 3b. dscDIOSetBit(), set bit 7 of port 2 to 1, leave other bits alone */
if ((result = dscDIOSetBit(dscb, port, bit)) != DE_NONE)
    return result;

/* 3c. dscDIOClearBit(), set bit 7 of port 2 to 0, leave other bits alone */
if ((result = dscDIOClearBit(dscb, port, bit)) != DE_NONE)
    return result;

/* 4. output byte - set port 2 to "01010101" (port 2 is in output mode) */
port = 2;
if ((result = dscDIOOutputByte(dscb, port, 0x55)) != DE_NONE)
    return result;
...


This page was last modified 14:54, 12 Feb 2004.
Copyright (c) 2004 Diamond Systems. All Rights Reserved.