CONTROLLING THE PPIO USING C

The PPIO disk includes three source code files as an example of using the PPIO with the C programming language. PPIO.C is the main routine of the example program. PPIOFUNC.C contains the routines for communicating with the PPIO. PPIOFUNC.H contains the function prototypes and definitions for use by PPIOFUNC.H and PPIO.C. In the rest of this section, we assume that you know the C programming language. Consult your reference manuals if you need help with the language.

PPIOFUNC.H makes some definitions used in the rest of this section.

#define Status_Address Base_Address+1 #define Control_Address Base_Address+2 typedef enum { false=0, true=1 } boolean;

The module, PPIOFUNC.C, handles communication with the parallel port. It defines three variables that all functions inside the module can access. They are defined as:

unsigned char Input_Byte; unsigned char Output_Byte; unsigned int Base_Address;

No function outside the module can directly access these variables. Functions outside the module call functions within the module to modify and return the value of these variables.

The function, Set_Start(), sets the variables Base_Address and Output_Byte. It also sets up the initial state of the parallel port. The function is defined as:

void Set_Start(unsigned int Address, unsigned char Init)

{

Base_Address = Address; Output_Byte = Init; outport(Base_Address, Output_Byte);

}

This function must be the first one used, because all other functions assume that variable, Base_Address, has been set.

18

PPIO2899 Manual

B&B Electronics Mfg Co Inc – 707 Dayton Rd - PO Box 1040 - Ottawa IL 61350 - Ph 815-433-5100 - Fax 815-433-5104

Page 20
Image 20
B&B Electronics PPIO manual Controlling the Ppio Using C