Help > RITTLE FOR THE PIC32MZ MICROCONTROLLER > Work with I/O ports > port


port (text_function, integer_portN [, integer_portN …] );

The ‘port’ function is used to initialise an I/O port for specific functionality.

The function parameter is provided as text, and the following one or more parameters are port numbers that need to be initialised all with the same function.

The port numbers are specified as per the numbering system in the RITTLE board – i.e. equal pin numbers. Therefore, PIC32’s pin 5 corresponds to Rittle port 5, PIC32’s pin 48 is Rittle port 48, and so on. Note that some port numbers are not available as they are being used for system purposes – power, etc.

Furthermore, depending on the system configuration, Rittle reserves some of these ports for other required functionality. Ports 17 and 18 are used by the serial system console, ports 3, 4, 5, and 6, are shared with the external SD card, and other ports may be shared with other functions.

The function is built from two sub-parts – switch and function. The switch is optional precedes the function.

Valid switches are:

+      Enable the built-in pull-up resistor on the port

-       Enable the built-in pull-down resistor on the port

#      The port is initialised as Open-Drain

Supported functions are:

DIN”                The port is initialised as digital input. Reading from the port will return a value 0 or 1 only, depending on the logic level applied on the port.

DOUT”           The port is initialised as digital output. Writing 0 to it will set the output low, otherwise writing a non-0 value will set the port high.

AIN”                The port is initialised as analogue input. Reading from the port will return a real number value between 0 and 1, proportional to the voltage applied on the port in respect to the configured negative and positive reference for the ADC. See command ‘Vref’ for further details about ADC referencing.

                        Not all ports can be initialised as AIN. Valid AIN port numbers (before applying the already reserved functionality for other needs) are:

                        1, 2, 3, 4, 5, 6, 10, 11, 12, 13, 14, 15, 16, 17, 18, 21, 22, 23, 24, 27, 28, 29, 30, and 64.         

PWM:freq”  The port is initialised as digital output that generates pulse-modulated signal. This function requires its own parameter ‘frequency’ (given in Hertz) to specify the carrying frequency for the pulse width modulation. Carrier frequencies may vary from 1Hz up to 64MHz, however the practically usable values are between 10Hz and 10MHz since with increasing the frequency, the accuracy of the duty reduces.

                        Not all ports can be initialised as PWM. Valid PWM port numbers (before applying the already reserved functionality for other needs) are:

                        14, 15, 21, 30, 38, 45, and 46

                        In addition to that, PWM ports share the carrier frequency in groups.  Initialising carrier frequency for one port will apply the same frequency for the other ports in the same group, regardless of whether they have been initialised with a different value prior to that. There are three groups of ports, therefore at any moment of time up to three separate PWM carrier frequencies are possible:

                        Group 1 – ports 15 and 21

                        Group 2 – ports 14 and 38

                        Group 3 – ports 30, 45, and 46


port “-DIN”, 12, 38, 50, 57;

port “+#DOUT”, 64;

port “AIN”, 21, 28, 29;

port “-PWM:50000”, 45, 46;