
Appendix B
Register-Level Programming
©
National Instruments Corporation
B-21
DAQCard-DIO-24 User Manual
Mode 2 Programming Example
The following example shows how to configure the 82C55A for various
combinations of mode 2 input and output and how to use the
handshaking signals to control data flow. This code is strictly an
example and is not intended to be used without modification in a
practical situation. The base address used may not correspond to the
base address of the card in your system. For information on card
activation, base addressing, and interrupt levels, see PC Card
Initialization earlier in this appendix.
Main() {
/* Set PC to 1 if you are using a PC, or set MAC to 1 if you are using a
Mac.*/
#define
PC
0
#define
MAC
0
/* If MAC = 1, set base address and define rd and wrt. */
#if
MAC
#define
BASE_ADDRESS
0xa0000000L
#define
rd(a)
((unsigned char) *((unsigned char *) (a)))
#define
wrt(a,d)
(*((unsigned char *) (a)) = ((unsigned char) (d)))
/* 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 */
#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;