Where we left off before, we were just about ready to try out the new MPLAB Xpress IDE. In order to do that, you need to open up your favorite browser and go to the following address: Microchip site.
Gest Mode and Registering
When you land on this page you are presented with the MPLAB Xpress IDE which looks almost identical to the MPLAB X IDE all through your web browser. The one thing I liked to see right off the bat was that there was no login or register window forcing registration before you can do anything.
Instead you are given almost full access to the IDE in guest mode. From what I can tell it means you can’t save your work to the cloud, but you can still export your work. Clicking myMicrochip Login will get you registered to use all features of the IDE.
Projects in MPLAB Xpress IDE
Now that we are logged in and staring at the blank MPLAB Xpress IDE it is time to start a project. I decided to start off with an existing example project as a first test. A first test usually starts with some sort of ‘hello world’ program. Since we have a few LEDs to work with and a 1-turn pot connected to an ADC pin we will choose a example project that will use the pot as a dimmer for our on-board LEDs.
Click File -> New Project -> Microchip Examples
One of the example projects is “LED Brightness Control using Potentiometer”.
Selecting that,’next’ brings you to a screen where you are prompted to select a target device you wish to write your code for. In our case the MPLAB Xpress dev board has a PIC16F18855 onboard. From there you are prompted to name your project and you are brought back into the IDE.
You will see the example project now open in your IDE. A source file ‘main.c’ will be open containing the below code. The project is very simple if you strip away all the comments and comment headers. Ignoring the include file and init function that is called at the beginning, which is a result of auto generated code from using the Code Configurator by the author of this example, all that exists is a while loop.
Generated Main Source File
Microchip Technology Inc.
This is the main file generated using MPLAB(c) Code Configurator
This header file provides implementations for driver APIs for all modules selected in the GUI.
Generation Information :
Product Revision : MPLAB(c) Code Configurator - v3.00
Device : PIC16F18855
Driver Version : 2.00
The generated drivers are tested against the following:
Compiler : XC8 1.35
MPLAB : MPLAB X 3.20
Copyright (c) 2013 - 2015 released Microchip Technology Inc. All rights reserved.
Microchip licenses to you the right to use, modify, copy and distribute
Software only when embedded on a Microchip microcontroller or digital signal
controller that is integrated into your product or third party product
(pursuant to the sublicense terms in the accompanying license agreement).
You should refer to the license agreement accompanying this Software for
additional information regarding your rights and obligations.
SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER
CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR
OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR
CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF
SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
// initialize the device
// When using interrupts, you need to set the Global and Peripheral Interrupt Enable bits
// Use the following macros to:
// Enable the Global Interrupts
// Enable the Peripheral Interrupts
// Disable the Global Interrupts
// Disable the Peripheral Interrupts
// Add your application code
adc_result_t dutyValue = ADCC_GetSingleConversion(pot); //load the potentiometer value in a 16 bit variable
PWM6_LoadDutyValue(dutyValue); //lod the potentiometer value to the PWM duty cycle
End of File
In this loop there is a call to read the ADC pin attached to the pot. This read value is then used to pass to PWM6 which is controlling the onboard LEDs. That’s it, two lines of code.
Compiling and Uploading Your Project
So lets see what this does on the Xpress board. Clicking the hammer icon ‘build’ which compiles the project and if successful results in the IDE triggering a download of the .hex file needed to upload to the microcontroller. No fancy programmer needed to push this to the board, the Xpress board enumerates as a USB Mass Storage device on your PC and the secondary micro on this board (the programmer) just sits waiting for a .hex file to be transferred to its flash memory at which point it will program the main PIC18F18855.
All you need to do is drag and drop your compiled code / hex file onto the Xpress drive that shows up when you plug in the Xpress board and in an instant your board will take that hex file and program itself with that code.
It literally took an instant to program and I was up and running the new code. I took a short video to show the board working with this first project.