Using a Digital Output With MPLAB® Code Configurator Classic

Last modified by Microchip on 2024/02/08 11:22

Using the MPLAB® Code Configurator (MCC) simplifies the setup for the various registers within the device to create a digital output.  In this example, you used MPLAB X IDE, MCC Classic, and MPLAB XC8 to demonstrate how to toggle a digital port pin using the MPLAB IDE simulator.  The technique extends beyond the PIC16F1769, as it can be applied uniformly across various Microchip Technology MCU devices, including both PIC® and AVR® architectures. 

Resources

Step-by-Step Project

Create a new "standalone" project in MPLAB X IDE for a PIC16F1769. Select the simulator as your debug tool.

Open MCC under the Tools > Embedded menu of MPLAB X IDE or click the icon mcc icon on the toolbar.
Select MCC from the menu or the toolbar
Click image to enlarge.

Click Select MCC Classic for this project.  This will provide a graphical interface for the registers needed.
select Classic Mode
Click image to enlarge.

Back to Top


MCC Content Manager Wizard now gives a list of Required Content and Optional Content list.  In this case, no additional content is required for this project. Click Finish.
content manager wizard
Click image to enlarge.

Back to Top


In the upper left corner of the MPLAB X IDE, MCC has the Project Resources window with three modules, System, Pin, and Interrupt, loaded.
project resources window
Click image to enlarge.

Back to Top


Open the Pin Manager: Grid View tab in the output window and then click on the PORTA pin 2 (RA2) Output blue lock symbol, it will turn green.  It should look like the accompanying image when completed:
Pin manager grid view setting RA2 as output
Click image to enlarge.

Back to Top


Click on the Pin Module selection in the Project Resources section. The center screen should show RA2 listed on the I/O chart. Click on the Output box to make the pin an output (if not checked) and make sure Analog and WPU are not checked (click on them to uncheck them).
Pin module window with RA2 set as an output
Click image to enlarge.

Back to Top


The system needs to be set up next. Click on System Module in the Project Resources list.

Select the INTOSC from the drop-down menu for the System Clock Select.
system module and clock selections
Click image to enlarge.
Select the 1MHz_HF selection from the Internal Clock drop-down menu.
Each configuration setting can be changed under the Registers tab of the System window. Match the selections shown in the accompanying image.
shows the register view
Click image to enlarge.

Back to Top


Click on the Generate button in the Project Resources window to have the MCC create the software libraries for this project.
The generate button is shown
Click image to enlarge.

Back to Top


The project will now include both the generated header and source files under the Projects tab.
files generated by mcc
Click image to enlarge.

Back to Top


Double-click on main.c to open it up in the editor window.
main.c file added by mcc
Click image to enlarge.

Back to Top


Add the following code to the end of the main.c file near the bottom of the file:

IO_RA2_Toggle();  // Add your application code

Back to Top


Set a breakpoint on the IO_RA2_Toggle() line by clicking on the line number (71) to the left of the code. A red box will replace the line number.
show the breakpoint set
Click image to enlarge.

Back to Top


Click on the Debug and Run icon Debug Project Button to compile and run the code; you should see a BUILD SUCCESSFUL message in the output window under the Digital-out (Build,Load,...) tab.
build successful in the output window
Click image to enlarge.

Back to Top


Open Window > Target Memory Views > SFRs.
open the SFR memory view
Click image to enlarge.

Back to Top


In the Output window select the SFRs tab, then scroll until you can see PORTA, if it is not already visible.
PORTA in the output window
Click image to enlarge.

Back to Top


Each time you click on Continue Continue Button the program will run until it hits the breakpoint on the IO_RA2_Toggle()O_RA2 command.  You will see the RA2 bit of PORTA change state.

RA2 highRA2 low

Back to Top


The project can be closed in MPLAB X IDE. The project is saved automatically when it is built, but any changes to files or configuration may ask to be saved before the project is closed.

Close the project under File Menu > Close Project.

Back to Top