MPLAB® Code Configurator

MPLAB Code Configurator

MPLAB® Code Configurator

The MPLAB® Code Configurator (MCC) is a user friendly Graphical User Interface (GUI) plug-in tool for MPLAB® X IDE which generates easy to understand C code that is inserted into an MPLAB® X project, based on the settings peripherals configurations and selections made in the Graphical User Interface (GUI). The generated code can be used in any application program.
When starting out with a new project using Microchip 8-bit microcontrollers, setup of the configuration and all the peripherals can be time consuming, especially for new projects. The MPLAB® Code Configurator simplifies this down to a series of simple graphical selections from the menus within the MCC. The MCC will then produce the configuration settings and all drivers for the peripherals selected to be setup. The code produced is automatically added to the MPLAB® X project and includes initialization of the registers and a set of API functions written for the MPLAB® XC8 compiler. This makes life easy as a programmer as it simplifies a lot for you.

The MCC Plugin can be installed from the Tools/Plugins menu in the MPLAB® X IDE

  • Select the ‘Tools’ menu, and click on ‘Plugins’
  • In the MPLAB® X IDE Plugins window, click the ‘Available Plugins’ tab or you can manually install it by downloading the MCC file form Microchip website. In the MPLAB® X IDE Plugins window, click on Downloaded tab, Select the MPLAB® Code Configurator and click ‘install’
  • Select MPLAB® Code Configurator and click ‘Install’

Watch the Video Tutorial:

Before starting MCC, a new MPLAB X IDE project needs to be created or an existing project needs to be opened. This is necessary as MCC needs to know the device used in the application, to have access to device-specific information like registers, bits and configurations and also to setup its GUI. MCC generates source and header files based on selections made in the GUI. It adds the generated files into the active project of MPLAB X IDE.
Once installed, the MCC tool can be launched from the the MPLAB® X Tools menu under the Embedded selection.

Configuration Settings

The first step of any project is to use the MPLAB X wizard tool to create a project. The wizard will step through selecting the microcontroller you are going to use, development programmer/debugger and compiler to use. This must be done before launching the Microchip Code Configurator.

Notes: If the PIC or a peripheral you are going to use is not supported yet by the MCC and your PIC is a PIC18 series, you can download from Microchip website under XC8 compilers download tab, the PIC18F Peripheral Libraries now called Legacy Peripheral Libraries as they are no longer included in XC8 compiler starting from XC8 v1.35. You have to download them separately and install them in your compiler.
The System Clock and Configuration Bits can be quickly configured in the Composer area. In the Project Resources area, click on System. The configuration register settings will show up below the clock selection area. By clicking on the configuration register name the list of register selections can be shown. Each of these selections have a range of settings and can be seen by clicking on the specific selection name. Click on the boxes for the settings desired and the MCC will produce the proper register settings and place that code in the project.
You can select your clock, specify your oscillator frequency, set your configuration bits (fuses) as desired. Once selected, the MCC will automatically use these settings to calculate timer periods, duty cycles, and baud rates as required by other peripherals. The figure below, shows an external 8 MHz clock oscillator selection.

Peripherals Selection

The Code Configurator makes it very easy to select the peripherals for a particular PIC. In the Devices Resources area of the Code Configurator you will see the peripherals available of the device you are using. If you change your PIC, the peripherals will change accordingly.
By clicking on the name of the peripheral, the list of associated options including multiple versions of the peripheral appears. There may be multiple Comparators on the device so the sub menu will show the list of all that are available. From the image below, for example it shows that the PIC18F45K22 has two EUSART modules by expanding the EUSART peripheral.
Clicking on the specific peripheral will add that peripheral to the Project Resources area.

I/O Pin Configuration

The Code Configurator allows the user to setup the I/O pin configurations using a graphical interface in the Pin Manager Area. Once you select a peripheral by double clicking it, the configurator will open up the MPLAB Configurator pin manager. This area provides a graphical representation of the selected device along with available pins for the selected peripheral in blue. The grayed pins are the pins that you cannot use.
Pins are assigned by selecting the desired pin in the lower section of the area. Select your PIC package using the Package drop-down menu. In our image below, PORTB.0 pin was selected. It changes its colour from blue to green and its lock locked.
In the Composer area, you can configure the pin as Output by checking the appropriate box, by default the pin is configured as input pin. You can also change the pin names to an easier to identify like LED for example in our example.

Generating Code

After each peripheral is setup along with the configuration and Input/Output pins, then just click on the Generate Code button has shown on the figure below to have the MCC create all the peripheral driver code for the project. The number shown in the generate code button (2) represents the number of peripherals that will have code generated ( in our case: Configuration bits and GPIO).
The code will be placed into the project automatically. If it is a new project then MCC will prompt you to generate a main.c

The code will show up in the project area of MPLAB® X as shown on figure below. The code produced is fully open sourced and editable.

The mcc.h and mcc.c files include the definitions of Configuration bits and the oscillator_initializer function. These definitions are based on the settings which were made for the System module in the Composer. The <peripheral_name>.h and <peripheral_name>.c files are module
specific files and include each module’s peripheral configuration functions.

The main.c file is generated only when the MCC detects that there is no main.c file present in the project. If there is any previous main.c in the project regardless of its creator (the user or MCC), it will not generate or overwrite the existing one. When using a main.c not generated by MCC the lines: “#include “mcc_generated_files/mcc.h”, and SYSTEM_Initializer() need to be added to the main.c file.

Functions present in these generated files can be called in the application program based on requirements. In our example, we are going to use the Toggle function generated by the MCC in the pin_manager.h file into the main.c file to toggle an LED connected to PORTB.0 All we need to add to this code is a delay function.

You can download the full project files (MPLAB XC8 source code and Proteus Schematic design) below here.  All the files are zipped, you will need to unzip them (Download a free version of the Winzip utility to unzip files).  

Download Mplab Project with Code Configurator: Blink_LED

Download Proteus Schematic with PIC18F26K20: Blinking_LED Proteus

Share this post

Select your currency