Then open the drop-down and select “Power”. Right-click the project name and go to “Properties”, all the way at the bottom. If you’re using the PICkit to power your circuit, we need to set that up. Save the file and build the project once again, we should clean and build successfully.
#MPLAB XC8 TUTORIAL CODE#
With all the appropriate configuration settings, click the “Generate Source Code to Output” button, which will generate a bunch of preprocessor directives that set our configuration bits. Instead, we’re going to use the 5-pin mode, so set this to OFF.
#include ).īefore we move to the next step, let’s try and compile our project and make sure everything’s okay so far. Also, make sure that the autogenerated code has #include and not the device specific header (i.e. A few lines of code will be auto-generated - don’t be outraged by the use of void main(void) instead of int main(void), as this is correct for a microcontroller (since there’s no operating system or runtime environment to return a int to). Call it “main” (who the hell uses newmain?) and create it. In the project view, right-click on “Source Files”, then navigate to New > main.c. When you use the compile/program/debug buttons, the active project is the one that gets targeted - which means that the files you’re editing could NOT be the ones that get compiled! Annoying, right? You can change this by right-clicking on a project you want to work on and selecting “Set as Main Project”. See how the first one (“babys_first_firmware”) is listed in bold? That means it’s the active project. I wanna take a second and point out something that will mess you up if you’re not careful - scroll up and take a look at my projects.
On the left of the application, we have a list of projects in our workspace. On the top of the application we have some buttons we’ll be using a lot: This one compiles and builds your project This one loads your firmware onto the microcontroller This one starts the debugger