
Appendix B
Register-Level Programming
DAQCard-DIO-24 User Manual
B-22
©
National Instruments Corporation
/* EXAMPLE 1*/
wrt(cnfg,0xC0);
/* Port A is in mode 2. */
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,0x67);
/* Write the data to port A. */
while (!(rd(portc) & 0x20))
/* Wait until IBFA is set, indicating */
rd(ireg1);
/* that data is available in port A to */
/* be read. */
valread = rd(porta);
/* Read data from port A. */
}
Interrupt Programming Examples
The following examples show the process required to enable interrupts
for several different operating modes. The interrupt handling routines
and interrupt installation routines are not included. Also, if you generate
interrupts with the PC3 or PC0 lines of the 82C55A, you must maintain
the active high level until the interrupt service routine is entered.
Otherwise, the host computer considers the interrupt a spurious
interrupt and routes the request to the channel responsible for handling
spurious interrupts. To prevent this problem, try using some other I/O
bit to send feedback to the device generating the interrupt. In this way,
the interrupting device can be signaled that the interrupt service routine
has been entered. For further information on using PC3 and PC0 for
interrupts, see the Interrupt Handling section later in this appendix. The
base address used may not correspond to the base address of the card in
your system. For information on card activation, base addresses, 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)))