Get Adobe Flash player
English Arabic French German Italian Portuguese Russian Spanish

Did you know?

Rowan Atkinson, the actor who plays the comedic character Mr. Bean, got his degree in electrical engineering.

Help us stay online:

small donate

ioThe general purpose I/O ports allow the dsPIC30F to monitor and control other devices. Most I/O pins are multiplexed with alternate function(s). The multiplexing will depend on the peripheral features on the device variant. In general, when a peripheral is functioning, that pin may not be used as a general purpose I/O pin. All port pins have three registers directly associated with the operation of the port pin:

  1. TRISx-Data Direction register
  2. LATx  I/O Port register
  3. PORTx  I/O Latch register

The Data Direction register TRISx (sign x changes with name of register) determines whether the pin is an input or an output. If the data direction bit is a ‘1’, then the pin is an input. All port pins are defined as inputs after a Reset.

Example configuration of ports and pins of port:

TRISB=0x0000;//configures port B as output
TRISC=0xffff;// configures port C as input
TRISDbits.TRISD0=1;// configures pin RDO of port D as input
TRISFbits.TRISF6=0;// configures pin RF6 of port F as output

TIP: When setting output pin or port state, always use LATx registers. Usage of PORTx register may lead to errors.This is known problem when frequent port (pin) changes occur.

For writing data on port, use registers LATx or PORTx (sign x changes with name of register). If pin or port is defined as output, we can write data on port.

Example of writing data on port:

1.Use LATX register

LATBbits.LATB4=1;// writes data on pin RB4 of port B
LATFbits.LATF6=0;// writes data on pin RF6 of port F
LATB=0xFFFF; // writes data on port B
LATF=0x0000; // writes data on port F

2.Use PORTx register

PORTD=0x0000;// writes data on port D
PORTC=Y;// writes data on port C from variable Y
PORTBbits.RB2=1;// writes data on pin RB6 of port  

For reading data from port use registers PORTx. If pin or port is defined as input we can read data from port.

Example of reading data from port: 

X= PORTD// reads from portD in variable X
if (PORTBbits.RB2)//tests pin RB2


If you want to use PORTB, you must define register ADPCFG.


ADPCFG=0xFFFF//all pins of port B are digital
ADPCFG=0x0000//all pins of port B are analog
ADPCFGbits.PCFG4=1;//configures pin RB4 as digital
ADPCFGbits.PCFG4=0;//configures pin RB4 as analog

Only pins configured as digital can be used as input or output pins. Pins configured as analog must be used as input pin.