4 Generating MCC Code
Now that MCC has been installed and its main operating areas are learned, it is time to set up MCC according to the user’s needs and begin configuring the project. The following subsections cover basic MCC operation and the code generation process.
4.1 Setting Up MPLAB® X IDE and Launching MCC
To generate drivers using the MCC in MPLAB X IDE, follow these steps:
- Create a new MPLAB X IDE project or open an existing project (see figure below).
- If multiple projects are open in MPLAB X IDE, set one as the main (active) project by selecting “Set as Main Project” in the MPLAB X IDE. For the active project, the MCC automatically includes the generated driver files.
- Open the MCC plugin tool. In the menu bar of the MPLAB X IDE, go to Tools → Embedded → MPLAB Code Configurator 3.x: Open/Close. Or click on the MCC icon in the MPLAB X IDE toolbar.
When opening MCC for the first time on an MPLAB X project, the configuration saving
dialog will be displayed asking for a name and saving path for the MCC configuration
file attached to the project. The MCC configuration is also saved to the disk when the
Generate button is pressed or if the MPLAB X IDE Save button is
clicked. An existing MCC configuration file can be loaded by double-clicking on the
desired .mc3
file in the Important Files section of the MPLAB X
IDE project.
4.2 Generating Code
When the MCC Generate button is pressed in the Project Resources window, the listed actions are performed by MCC. Details of the code generation are shown in the MCC Output tab. See The MPLAB® Code Configurator - Output Tab.
- The MCC configuration file is saved.
- MCC generates code for the peripheral or library module if the module’s configuration has changed since the last time MCC generated code for that module.
If MCC attempts to regenerate a file on the disk that has been modified outside of MCC, the Merge [MCC] window is displayed. Use the Merge [MCC] window to select whether to keep the modified file (default action) or replace the modified content with the content generated by MCC.
The Merge [MCC] window is discussed in Section 4.3.2 “The Merge [MCC] Window.”
4.2.1 Saving and Loading the MCC Configuration
Saving and loading the MCC configuration is integrated into the MPLAB X IDE Save and Load functions. The MCC configuration is saved whenever the Generate button is pressed. The MCC configuration can also be saved by clicking on the MPLAB X IDE Save tool or selecting Save from the File menu.
The MCC configuration file is included in the MPLAB X IDE project under the Important
Files folder. The configuration file uses the extension .mc3
.
Double-clicking on the MCC configuration file will cause that MCC configuration to be
loaded.
4.2.2 The Merge [MCC] Window
If any of the files generated by the MCC have been edited outside of MCC and saved to the disk, then the Merge [MCC] window appears in the Composer Area. Use the Merge [MCC] window to select whether to keep the edits or replace them with the newly generated MCC code.
When changes have been made to both a generated file and the corresponding MCC UI within the Composer Area, the Merge [MCC] window shown in Figure 4-2 will be displayed. The Merge [MCC] window allows resolving the conflicts between the newly generated file and the edits made to the file.
When the newly generated MCC content has been accepted, MCC makes the changes to the file. To the MPLAB X IDE, these changes are the same as if they were typed in the new content. The normal MPLAB X IDE edit undo can be used in the MCC Merge operation.
A list of all the files that need to be merged is shown at the top of the Merge [MCC] window. Each file in the list must be selected, in turn, to ensure that all of the newly generated code is incorporated into the project.
At the top of the Merge [MCC] window, in the center margin, there is an arrow, as shown in Figure 4-3. Clicking on the arrow will replace all the edits in the current file with the MCC updated code that the MCC has just generated. The numbers above the arrow indicate the current difference and the total number of differences.
The individual lines of MCC Updated Code can be selected to replace the edited code. As shown in Figure 4-4, clicking on the arrows in the right margin of the left window will copy the MCC Updated Code to the generated driver file. Once the changes are accepted, the Merge mechanism will remove the highlighted file and highlight the next file on the list. A warning will be generated if the Merge mechanism is closed before all the changes are accepted to ensure all updates are completed.
- Remember to merge the code for every file shown in the file list of the Merge [MCC] window.
- Be sure to save all the changed files from the Merge process.