Mode 0 programming example – National Instruments PC-DIO-24/PnP User Manual

Page 70

Advertising
background image

Appendix C

Register-Level Programming

PC-DIO-24/PnP User Manual

C-10

© National Instruments Corporation

Mode 0 Programming Example

The following example shows how to configure the 82C55A for various
combinations of mode 0 input and output. This code is strictly an
example and is not intended to be used without modification in a
practical situation.

Main() {

#define BASE_ADDRESS

0x180

/* Board located at address 180 */

#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 int porta, portb, portc, cnfg;

char valread;

/* Variable to store data read from a port */

/* Calculate register addresses */

porta = BASE_ADDRESS + PORTAoffset;

portb = BASE_ADDRESS + PORTBoffset;

portc = BASE_ADDRESS + PORTCoffset;

cnfg = BASE_ADDRESS + CNFGoffset;

/* EXAMPLE 1*/

outp(cnfg,0x80);

/* Ports A, B, and C are outputs. */

outp(porta,0x12);

/* Write data to port A. */

outp(portb,0x34);

/* Write data to port B. */

9

10010001

Input

Output

Output

Input

10

10010010

Input

Output

Input

Output

11

10010011

Input

Output

Input

Input

12

10011000

Input

Input

Output

Output

13

10011001

Input

Input

Output

Input

14

10011010

Input

Input

Input

Output

15

10011011

Input

Input

Input

Input

1

Upper nibble of port C

2

Lower nibble of port C

Table C-3. Mode 0 I/O Configurations (Continued)

Number

Control Word

Group A

Group B

Bit

76543210

Port A

Port C

1

Port B

Port C

2

Advertising