7/30/2019
Basys MX3 Reference Manual [Reference.Digilentinc]
https://reference.digilentinc.com/reference/microprocessor/basys-mx3/reference-manual?_ga=2.68739409.1349070004.1564406803-1961480359.1…
9/52
example (bit LATA1 of the register LATA is set to 1):
LATAbits.LATA1 = 1;
Digilent provides a set of libraries called the Basys MX3 Library Pack that addresses much of the functionality on the Basys MX3:
ACL () (accelerometer)
ADC () (Analog to Digital converter)
AUDIO
BTN (buttons)
IRDA
LCD ()
LED ()
MIC (microphone)
MOT (motors)
PMODS
RGBLED
SPIFLASH
SSD ()
SWT (Switches)
UART
These libraries are wrappers over the lower level functions that access the registers, allowing the user to call the functionality using functions
like:
LED_Init();
LED_SetValue(4, 1); //turn on LED4
This set of libraries comes with the user documentation, but basically this is what you have to 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
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 Appendix 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.
1.3. Digital Inputs and Outputs