4digital inputs and outputs – Digilent 410-297P-KIT User Manual

Page 9

Advertising
background image

ChipKIT MX3 Board Reference Manual

Copyright Digilent, Inc. All rights reserved.

Other product and company names mentioned may be trademarks of their respective owners.

Page 9 of 25

4

Digital Inputs and Outputs

The ChipKIT MX3 board provides access to 40 of the I/O pins from the PIC32 microcontroller via the Pmod
connectors. Two additional I/O pins can be accessed via the I

2

C connector, J2. Any of the pins on the Pmod or I

2

C

connectors can be individually accessed for digital input or output. Note that when the I

2

C signals on J2 are being

used for I

2

C communications, they are not available for general purpose I/O.


On PIC32 microcontrollers, the input/output pins are grouped into I/O Ports and are accessed via peripheral
registers in the microcontroller. There are seven I/O Ports numbered A–G and each is 16 bits wide. Depending on
the particular PIC32 microcontroller, some of the I/O Ports are not present, and not all 16 bits are present in all I/O
Ports.

Each I/O Port has four control registers: TRIS, LAT, PORT, and ODC. The registers for I/O Port A are named TRISA,
LATA, PORTA and ODCA. The registers for the other I/O Ports are named similarly.

The TRIS register is used to set the pin direction. Setting a TRIS bit to 0 makes the pin an output. Setting the TRIS
bit to 1 makes the pin an input.

The LAT register is used to write to the I/O Port. Writing to the LAT register sets any pins configured as outputs.
Reading from the LAT register returns the last value written.

The PORT register is used to read from the I/O Port. Reading from the PORT register returns the current state of all
of the pins in the I/O Port. Writing to the PORT register is equivalent to writing to the LAT register.

PIC32 microcontrollers allow any pin set as an output to be configured as either a normal totem-pole output or as
an open-drain output. The ODC register is used to control the output type. Setting an ODC bit to 0 makes the pin a
normal output and setting it to 1 makes the pin an open drain output.

Refer to the PIC32MX3XX/4XX Family Data Sheet, and the PIC32 Family Reference Manual, Section 12, IO Ports, for
more detailed information about the operation of the I/O Ports in the microcontroller.

The MPIDE system uses logical pin numbers to identify digital I/O pins on the connectors. These pin numbers start
with pin 0 and are numbered up consecutively.

On the ChipKIT MX3, pin numbers 0–39 are used to access the pins on the Pmod connectors and pin numbers 40
and 41 are used for the two signal pins on the I

2

C connector. The pin numbers are assigned so that connector JA

pin 1 (JA-01) is digital pin 0, JA pin 2 (JA-02) is digital pin 1, and so on.

Pins 0-7 are on connector JA, pins 8-15 on JB, pins 16-23 on JC, pins 24-31 on JD, and pins 32-39 on JE. Refer to the
tables in Appendices B–D for detailed information about the pin mapping between Pmod connector, logical pin
number, and PIC32 microcontroller pin number and pin function.

When using the ChipKIT MX3 with the MPIDE the functions pinMode(), digitalRead(), and digitalWrite() are used
for digital pin I/O.

The pinMode() function is used to set the pin direction. Pin direction can be set to: INPUT, OUTPUT, or OPEN.
OPEN is used for open-drain and implies output.

The digitalRead() and digitalWrite() functions are used to read or write the pins. DigitalRead() returns the current
state of the specified pin, and digitalWrite is used to set the state of an output pin. The pin state can be either
HIGH or LOW.

Advertising