Basys MX3™ Board Reference Manual
This set of libraries comes with the user documentation, but this is what you must do in order to use them:
Include in your project the .c and .h files corresponding to the module you want to use (for example led.c
and led.h).
In your code, include the header of the module:
#include "led.h"
In your code, call the needed functions
1.3
Digital Inputs and Outputs
The PIC32MX370F512L microcontroller offers access to all the board resources through its pins, so understanding
how to access their features is very important. The list that describes each pin functionality is included in
3. You can see that each pin may have multiple functions, but all pins have one feature in common: they have an
associated digital I/O (input/output) bit. On PIC32 microcontrollers, the I/O 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 PIC32 microcontroller, some of the I/O Ports are not present, and not all 16 bits are
accessible in all I/O Ports.
Each I/O Port has the following control registers: TRIS, LAT, PORT, ANSEL, CNPU, CNPD, and ODC. The registers for
each I/O Port are named after it: TRISx, LATx, PORTx, ANSELx, CNPUx, CNPDx and ODCx. For example, port A will
have the following assigned registers: TRISA, LATA, etc.
The TRIS register is used to set the pin direction. Setting a TRIS bit to 0 makes the corresponding 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
the pins in the I/O Port. Writing to the PORT register may not produce the expected result, therefore writing to LAT
register is recommended.
To summarize: write using LAT, read using PORT.
PIC32 microcontrollers allow any pin set as an output to be configured as either a normal digital 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.
The multifunction pins that include analog input functionality need to be configured in order to be used as digital
pins by clearing the corresponding bit from ANSEL register. These pins will include ANx in their name. For example:
AN11/PMA12/RB11 for RB11.
This microcontroller has a weak pull-up and a weak pull-down connected to each pin. These pull-ups and pull-
downs are enabled/disabled by setting the corresponding bits from CNPU and CNPD registers to 1/0. The default
setting is 0 (pull-ups and pull-downs disabled).
You can see a typical example of I/O pin configuration as output and digital output operations in the
section.
You can see a typical example of I/O pin configuration as input (including analog disable) and digital input
operations in the
User Buttons
Copyright Digilent, Inc. All rights reserved.
Other product and company names mentioned may be trademarks of their respective owners.
section.
Appendix
User LEDs
Page 9 of 56
Need help?
Do you have a question about the Basys MX3 and is the answer not in the manual?
Questions and answers