Digital Output Operations

SetPinsDigitalOut
Configure selected pins as digital outputs.
Write
Change all output bits to specified pattern.
SetBits
Set selected bits to 1.
ClearBits
Clear selected bits to 0.
ToggleBits
Invert (complement) value of selected bits.

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 output macros associated with Port A.

mPORTASetPinsDigitalOut(unsigned int bits)
mPORTAWrite(unsigned int value)
mPORTASetBits(unsigned int bits)
mPORTAClearBits(unsigned int bits)
mPORTAToggleBits(unsigned int bits)

Similar definitions exist for the other ports. For example,

mPORTAWrite(unsigned int value);
mPORTBWrite(unsigned int value);
mPORTCWrite(unsigned int value);
mPORTDWrite(unsigned int value);
mPORTEWrite(unsigned int value);
mPORTFWrite(unsigned int value);
mPORTGWrite(unsigned int value);

Function Calls

void PORTSetPinsDigitalOut(IoPortId portId, unsigned int bits);
void PORTWrite(IoPortId portId, unsigned int value);
void PORTSetBits(IoPortId portId, unsigned int bits);
void PORTClearBits(IoPortId portId, unsigned int bits);
void PORTToggleBits(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 output pins, one or more bit masks bitwise OR’d together

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

value: Specified output values (either 0 or 1) for all bits.

Only those bits enabled for output will be affected.

Examples

  1. Define pins RD2 and RD0 as outputs:
         #define PORT IOPORT_D
         #define PINS BIT_2 | BIT_0
         PORTSetPinsDigitalOut(PORT, PINS);
    
    or
         mPORTDSetPinsDigitalOut(BIT_2 | BIT_0);
    

  2. Toggle bits RB2 and RB4:
        PORTToggleBits(IO_PORT_B, BIT_2 | BIT_4)
    
    or
        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