General purpose digital i/o functions, High-speed digital input – Measurement Computing TempBook rev.3.0 User Manual
Page 36

6-4 Standard API Programming of the TempBook with C
TempBook User’s Manual
General Purpose Digital I/O Functions
The following except from TBKEX.C shows the usage of the general purpose digital I/O functions.
unsigned char bit, in_bit, out_bit, out_byte, in_byte;
Read the state of the digital input bit 3, and place its value in in_bit.
tbkRdBit(3, &in_bit);
Depending on its state, print a message.
if (in_bit) {
sprintf(tempstr, "Digital input #3 is set\r\n\r\n");
strcat(response, tempstr);
} else {
sprintf(tempstr, "Digital input #3 is clear\r\n\r\n");
strcat(response, tempstr);
}
Set the digital output bit 5 to a high state.
tbkWtBit(5, 1);
The following lines of code use the byte manipulation functions to perform a "walking-bit" test on the
digital output port.
for (bit=0 ; bit<8 ; bit++)
{
out_byte = 0x01
sprintf(tempstr, "Digital output byte written 0x%2x\n", out_byte);
strcat(response, tempstr);
}
Read the value from the digital input port (DI0 - DI7 inclusive), then print the result.
tbkRdByte(&in_byte);
sprintf(tempstr, "Digital input byte is 0x%2x\r\n", in_byte);
strcat(response, tempstr);
High-Speed Digital Input
The following excerpt from TBKEX.C shows the usage of the high-speed digital input function calls.
The high-speed digital port can be specified as a channel in the analog scan sequence, just like an analog
input channel. In this way the high-speed digital port data is acquired synchronously with the analog input
data and is placed in the same data buffer as the analog input data. This program sets up a scan which
includes analog channels and the high speed digital port.
unsigned chans[9], data[9], i, chan;
unsigned char gains[9], polarity[9];
Configure a scan consisting of analog input channels 0 through 7.
for (i=0 ; i<8 ; i++){
chans[i] = i; // Analog input channels 0 - 7
gains[i] = TgainX1; // Unity gain
}
Include the high speed port as the last channel in the scan. Note that the high speed channel can be placed
anywhere in the scan.
chans[8] = TchHighSpeedDig; // High speed digital inputs
gains[8] = TgainX1; // Put any gain, it doesn't matter