Using a Digital Output With MPLAB® Code Configurator Classic
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 on the toolbar.
Click image to enlarge.
Click Select MCC Classic for this project. This will provide a graphical interface for the registers needed.
Click image to enlarge.
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.
Click image to enlarge.
In the upper left corner of the MPLAB X IDE, MCC has the Project Resources window with three modules, System, Pin, and Interrupt, loaded.
Click image to enlarge.
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:
Click image to enlarge.
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).
Click image to enlarge.
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.
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.
Click image to enlarge.
Click on the Generate button in the Project Resources window to have the MCC create the software libraries for this project.
Click image to enlarge.
The project will now include both the generated header and source files under the Projects tab.
Click image to enlarge.
Double-click on main.c to open it up in the editor window.
Click image to enlarge.
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
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.
Click image to enlarge.
Click on the Debug and Run icon to compile and run the code; you should see a BUILD SUCCESSFUL message in the output window under the Digital-out (Build,Load,...) tab.
Click image to enlarge.
Open Window > Target Memory Views > SFRs.
Click image to enlarge.
In the Output window select the SFRs tab, then scroll until you can see PORTA, if it is not already visible.
Click image to enlarge.
Each time you click on Continue 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.
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.