User manual

Appendix D Register-Level Programming
©
National Instruments Corporation D-17 PC-DIO-96/PnP User Manual
unsigned int porta, portb, portc, cnfg;
char valread; /* Variable to store data read from a port */
/* Calculate register addresses */
porta = BASE_ADDRESS + APORTAoffset;
portb = BASE_ADDRESS + APORTBoffset;
portc = BASE_ADDRESS + APORTCoffset;
cnfg = BASE_ADDRESS + ACNFGoffset;
/* EXAMPLE 1–port A input */
outp(cnfg,0xB0); /* Port A is an input in mode 1. */
while (!(inp(portc) & 0x20)); /* Wait until IBFA is set,
indicating that data has been
loaded in port A. */
valread = inp(porta); /* Read the data from port A. */
/* EXAMPLE 2–Port B input */
outp(cnfg,0x86); /* Port B is an input in mode 1. */
while (!(inp(portc) & 0x02)); /* Wait until IBFB is set,
indicating that data has been
loaded in port B. */
valread = inp(portb);
}
Mode 1—Strobed Output
The control word written to the CNFG Register to configure port A for
output in mode 1 is shown as follows. Bits PC4 and PC5 of port C can
be used as extra input or output lines.
The control word written to the CNFG Register to configure port B for
output in mode 1 is shown as follows. Notice that port B does not have
extra input or output lines from port C.
D2 D1 D0D3D7
D6 D5
D4
1 = input
0 = output
Port C bits PC4 and PC5
1
0
1/0
X
X
X10