Digital Input Operations

SetPinsDigitalIn
Configure selected pins as digital inputs.
Read
Read from a selected port.
ReadBits
Read selected bits (pins) from a port.

Thiese operations are available either as functions or macros. The advantage of the macro format is that it avoids function call overhead.

Macros

The macros incorporate the target port into the macro name.

These are the digital input macros associated with Port A.

mPORTASetPinsDigitalIn(unsigned int bits)
mPORTARead()
mPORTAReadBits(unsigned int bits)

Similar definitions exist for the other ports. For example,

mPORTAReadBits(unsigned int bits);
mPORTBReadBits(unsigned int bits);
mPORTCReadBits(unsigned int bits);
mPORTDReadBits(unsigned int bits);
mPORTEReadBits(unsigned int bits);
mPORTFReadBits(unsigned int bits);
mPORTGReadBits(unsigned int bits);

Function Calls

void PORTSetPinsDigitalOut(IoPortId portId, unsigned int bits);
unsigned int PORTRead( );
unsigned int PORTReadBits(IoPortId portId, unsigned int bits);

where

portID: Enumerated PORT Identifier

 typedef enum {
         IOPORT_A,
         IOPORT_B,
         IOPORT_C,
         IOPORT_D,
         IOPORT_E,
         IOPORT_F,
         IOPORT_G,
         IOPORT_NUM
         }IoPortId;

bits: Specified input pins, one or more bit masks bitwise ORd together

Appropriate bit masks are already defined, e.g. BIT_0 and BIT_6

Examples

  1. Define pins RD2 and RD0 as Inputs:
         #define PORT IOPORT_D
         #define PINS BIT_2 | BIT_0
         PORTSetPinsDigitalIn(PORT, PINS);
    
    or
        mPORTDSetPinsDigitalIn(BIT_2 | BIT_0);
    

  2. Read bits RB2 and RB4:
        n = PORTReadBits(IO_PORT_B, BIT_2 | BIT_4)
    
    or
        n = mPORTBToggleBits(BIT_2 | BIT_4);
    

Reference

PIC32 Peripheral Libraries for MPLAB C32 Compiler, Microchip Technology, 2007. 


Maintained by John Loomis, last updated 18 July 2008