
Appendix B
Register-Level Programming
DAQCard-DIO-24 User Manual
B-18
©
National Instruments Corporation
#define PORTAoffset
0x00
/* Offset for port A */
#define PORTBoffset
0x01
/* Offset for port B */
#define PORTCoffset
0x02
/* Offset for port C */
#define CNFGoffset
0x03
/* Offset for CNFG */
#define IREG1offset
0x14
/* Offset for Interrupt Reg. 1*/
unsigned long porta, portb, portc, cnfg, ireg1;
char valread;
/* Variable to store data read from a port */
/* Calculate register addresses. */
porta = BASE_A PORTAoffset;
portb = BASE_A PORTBoffset;
portc = BASE_A PORTCoffset;
cnfg = BASE_A CNFGoffset;
ireg1 = BASE_A IREG1offset;
/* EXAMPLE 1–Port A output */
wrt(cnfg,0xA0);
/* Port A is an output in mode 1.*/
while (!(rd(portc) & 0x80))
/* Wait until OBFA* is set, indicating */
rd(ireg1);
/* that the data last written to port A*/
/* has been read. */
wrt(porta,0x12);
/* Write data to port A. */
/* EXAMPLE 2–Port B output */
wrt(cnfg,0x84);
/* Port B is an output in mode 1.*/
while (!(rd(portc) & 0x02))
/* Wait until OBFB* is set, indicating */
rd(ireg1);
/* that the data last written to port B */
/* has been read. */
wrt(portb,0x34);
/* Write the data to port B. */
}
Mode 2 Bidirectional Bus
Mode 2 has an 8-bit bus that can transfer both input and output without
changing the configuration. The data transfers are synchronized with
handshaking lines in port C. This mode uses only port A; however,
port B can be used in either mode 0 or mode 1 while port A is
configured for mode 2.
The control word written to the CNFG Register to configure port A as
a bidirectional data bus in mode 2 is shown as follows. If port B is
configured for mode 0, then PC<2..0> of port C can be used as extra
input or output lines.