
Appendix B
Register-Level Programming
©
National Instruments Corporation
B-11
DAQCard-DIO-24 User Manual
/* Else if PC = 1, set base address and define rd and wrt. */
#elif
PC
#define
BASE_ADDRESS
0x0220
#define
rd(a)
((unsigned char) inp(((unsigned int) (a))))
#define
wrt(a,d)
(outp(((unsigned int) (a)), ((unsigned char) (d))))
#end
#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 */
unsigned long porta, portb, portc, cnfg
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;
/* EXAMPLE 1*/
wrt(cnfg,0x80);
/* Ports A, B, and C are outputs. */
wrt(porta,0x12);
/* Write data to port A. */
wrt(portb,0x34);
/* Write data to port B. */
wrt(portc,0x56);
/* Write data to port C. */
/* EXAMPLE 2*/
wrt(cnfg,0x90);
/* Port A is input; ports B and C */
/* are outputs. */
wrt(portb,0x22);
/* Write data to port B. */
wrt(portc,0x55);
/* Write data to port C. */
valread = rd(porta);
/* Read data from port A. */
/* EXAMPLE 3 */
wrt(cnfg,0x82);
/* Ports A and C are outputs; port B */
/* is an input. */
/* EXAMPLE 4 */
wrt(cnfg,0x89);
/* Ports A and B are outputs; port C */
/* is an input. */
}