This example shows how to implement a command line interface. This way, the microcontroller can receive control commands via the EUSART. In this use case, an LED is controlled using commands sent from the MPLAB® Data Visualizer.
More details and code examples on the PIC18F47Q10 can be found at the following links:
- PIC18F47Q10 Product Page
- PIC18F47Q10 Code Examples on Discover
- PIC18F47Q10 Code Examples on GitHub
- TB3282 - Getting Started with UART using EUSART on PIC18
- The PIC18F47Q10 Curiosity Nano Development board is used as a test platform:
To program the Curiosity Nano board with this MPLAB X project, follow the steps provided in the How to Program the Curiosity Nano Board chapter.
The following peripheral and clock configurations are set up using the MPLAB Code Configurator (MCC) Melody for the PIC18F47Q10:
- Clock Control:
- UART2:
- EUSART2 Peripheral:
- Receive Enable: Enabled
- Clock/Transmit Polarity: Non-Inverted
- Serial Port Enable: Enabled
- Transmit Enable: Enabled
- Baud Rate Generator: 16-bit generator
- Baud Rate Generator Speed Select: High speed
- Pins:
The following configurations must be made for this project:
Pin | Configuration |
---|---|
RD0 (EUSART2 - TX) | Digital output |
RD1 (EUSART2 - RX) | Digital input |
RE0 (LED0) | Digital output |
Run the code and configure the Data Visualizer as described in the Technical Brief document. Type commands to be sent to the board. The two available commands are "ON" and "OFF". Observe the LED on the board as it changes its state according to the command sent.
One important usage of the EUSART represents the implementation of a command line interface. This way, the microcontroller can receive control commands via EUSART. It is convenient to use the line terminator as command delimiter, so for this use case, EUSART will read full lines and then check if the line contains a valid command.
This chapter demonstrates how to use the MPLAB X IDE to program a PIC® device with an Example_Project.X. This is applicable to other projects.
-
Connect the board to the PC.
-
Open the
Example_Project.X
project in MPLAB X IDE. -
Set the
Example_Project.X
project as main project.
Right click the project in the Projects tab and click Set as Main Project. -
Clean and build the
Example_Project.X
project.
Right click theExample_Project.X
project and select Clean and Build. -
Select PICxxxxx Curiosity Nano in the Connected Hardware Tool section of the project settings:
Right click the project and click Properties.
Click the arrow under the Connected Hardware Tool.
Select PICxxxxx Curiosity Nano (click the SN), click Apply and then click OK: -
Program the project to the board.
Right click the project and click Make and Program Device.