beautypg.com

Omega Engineering IOP-241 User Manual

Page 31

background image

5.10

Programming Example

The following C program segment demonstrates how to program an IOP-241 located at I/O
base address 300h. Port A will be programmed as output, and 55h will be latched at Port A.
Port B will be configured with it's upper 3 bits as output and it's lower five bits as input. The
upper three bits will be latched with 010b. Port C will be configured as input. Interrupts will
be enabled as explained in the program comments.

outp(0x300,0x55);

/* writes 55h to Port A */

outp(0x301,0x5F);

/* writes 010b to Port B upper 3 bits*/

/* sets Port B lower 5 bits for input */

outp(0x302,0xFF);

/* initializes Port C for input */

Port_B = inp(0x301);

/* reads data from Port B */

/* Port_B(bit7) = '0' and Port_B(bit5) = '0' due to 'masking' */

Port_C = inp(0x302);

/* reads data from Port C */

outp(0x306,0x76);

/* INT7 - INT4 set for Level Sensitive Active High Interrupt Mode */

/* INT3 - INT0 set for Edge Sensitive High-to-low Transition Interrupt Source */

/* External Interrupt Source Enabled */

/* External Interrupt Source set for Low-to-high Edge Sensitive Interrupt Source*/

outp(0x305,0x77);

/* Enables six Port C interrupt sources */

/* Enables INT6,INT5,INT4,INT2,INT1,INT0 */

IOP-241 Users Manual 31