2.2 Foundation Services Generated Code
To generate this project using the Foundation Services library, follow these steps:
- Create a new MPLAB X project.
- Open the MCC from the toolbar (information on how to install the MCC plug-in can be found on the Microchip website).
- Go to
Project Resources > System > System
Module and use the following
configurations:
- Oscillator Select: HFINTOSC
- HF Internal Clock: 4 MHz
- Clock Divider: 4
- In the WDT Enable field, in the WWDT tab, ensure WDT Disable is selected
- In the Programming tab, ensure Low-Voltage Programming Enable is checked
- In Device Resources under Libraries, find Foundation Services, expand it and double-click UART to add it to the project.
- Click the + button at the bottom to add a new Foundation Services federated UART.
- Select EUSART2 from the UART drop down in Foundation Services.
- Open the
Pin Manager > Grid View window,
select UQFN40 in the MCU package field and select
pin RD0 EUSART TX.
Figure 2-2. Pin Mapping - Click Generate in the Project Resources tab.
- In the
main.c
file, which was generated by MCC:- Uncomment the line that enables global interrupts and the one that enables peripheral interrupts
- Add the following code in the main function
(replacing the existing
while(1)
loop):char msg[] = "Hello world\r\n"; while (1) { for(uint8_t i = 0; i < strlen(msg); i++) { uart[UART0].Write(msg[i]); } }
- Use MPLAB X Data Visualizer as described in the appendix, How to Receive Data in MPLAB Data Visualizer.