------------------------------------------------------------------------------
  File: Instructions_READ_ME_1st.txt
  Project: CDI-2012 v1.0
  Author: Jake Stewart  -  jakestew@mail.com
  Credits: See the source code or website.
------------------------------------------------------------------------------

This file contains step-by-step instructions on compiling the firmware.

For all other information, including: building the hardware, proper settings to use, flashing the firmware, or other issues please see the the project website... 
http://www.electrofunnel.com/CDI-2012/index.htm
and/or the RC Universe thread... 
http://www.rcuniverse.com/forum/m_10662258/mpage_34/key_/tm.htm

Ideas, questions, comments, or snide remarks should be directed to the author (Jake) at:
jakestew@mail.com

Please don't pollute the RC Universe thread unless you have to, it's long enough already.


------------------------------------------------------------------------------
  Getting Started... [Setting up your toolchain]
------------------------------------------------------------------------------
You need to install MPLAB X v1.51 and the XC8 compiler v1.11.  If you use versions older or newer than this you may need to modify the instructions.

Apologies for the constant toolchain version changes. I realize this is a large download each time, but don't blame me, blame Microchip.  I have to use the latest versions because this is what is available for new users to download.  The code will compile just fine on any version of XC8, but the project files and instructions will change slightly. 

You can download MPLAB X  and XC8 at:
------------------------------------------------------------------------------
http://www.microchip.com/pagehandler/en-us/family/mplabx/
------------------------------------------------------------------------------
Click on the "MPLAB X Free Download" button on the left side of the page, then download "MPLAB X IDE v1.51" and "MPLAB XC8 Compiler v1.11".

These are large (312 & 164 MB) downloads, so I HIGHLY suggest using a download manager or at least using Firefox for the download.
I recommend "FDM Lite" which can be found at:
http://www.freedownloadmanager.org/download.htm
This download manager supports pause and resume, and will open multiple download threads which can greatly improve your download speed.  Firefox also has pretty good download resume capability, at least much better than Chrome or IE.

First, install the MPLAB X IDE...
------------------------------------------------------------------------------
1.  Run the MPLAB X IDE install file...
	-Use the default settings for install location.   
	-When setup finishes, uncheck the checkbox on the "Completing the Setup Wizard" screen. You should have already downloaded XC8.

2.  Run MPLAB X. If you had an older version installed previously it will ask you to import your old settings.  I suggest NOT doing this because it doesn't always work right and any previous problems could be imported into your new install.

3.  Uncheck the "Show On Startup" checkbox at the bottom of your screen, then close the start page by clicking the X on the "Start Page" tab near the top left of your screen.

4.  Go to Tools -> Options.  Click the "Embedded" icon at the top.  Click on the "Generic Settings" tab. Click the "..." button next to "Projects Folder:".  Now choose a location for all of your PIC project folders, I suggest something like "C:\MPLABXProjects".  Using the default location leads to a long path name with spaces in it.  Foolishness like this can sometimes cause problems later, so it's best to avoid them in the first place (you can thank me later).  

5.  Close MPLAB X.

Next, install the XC8 Compiler...
------------------------------------------------------------------------------
1. Run the XC8 Compiler installation file.
	-1st screen, choose "Install compiler".
	-2nd screen, choose "Install MPLAB XC8 C Compiler on this computer".
	-3rd screen asks for an activation key, just leave it blank and click next.
	-Click "OK" on the popup that asks you if you're sure.
	-4th screen, choose "Run the compiler in Free mode".  You can always activate the Pro version evaluation later if you want, but it is time limited to 60 days so don't start burning up your time until/unless you need it.
	-5th screen, use the default installation directory that is supplied.
	-7th screen, check all of the boxes and click next.
	-8th screen, click next to finally begin the installation.
	-9th screen, uncheck "View Readme File" and click Finish.

You now have your IDE and toolchain setup and are ready to compile software for all 8-bit PIC processors!

------------------------------------------------------------------------------
  Compiling the Code!
------------------------------------------------------------------------------
You have two easy methods to compile the code.  You can use the project file I supplied, or create your own.

The first step is to unpack the project files.  Simply unzip the file and move the project directory of your choice to your MPLAB X projects directory.  You can also locate them anywhere you like, but for the sake of simplicity I suggest sticking to these instructions.

Simply select all the files and directories from the ZIP file and copy them to "C:\MPLABXProjects\".  You should now have the Excel file, these instructions, and both MPLAB X project directories in your MPLAB X project directory.

To use the supplied project file...
------------------------------------------------------------------------------
1.  Open MPLAB X
2.  Go to File -> Open Project, and select "CDI-2012_12F1840_v1.0.X" or "CDI-2012_12F683_v1.0.X" depending on the processor you are using.  Check "Open as Main Project", if available. Click Ok.
3.  Click on the hammer icon at the top of the screen to compile.
4.  Check the output window to see if there were any errors.  You can ignore warnings and advisories.  There should be no erros and one advisory, which you can ignore.

Congradulations, you've just compiled the code to a HEX file you can flash onto your chip!

Now that you know everything is working right you can change settings and curves in the Excel file, copy the code into the project, and compile your own custom CDI firmware!

To compile your own custom CDI firmware...
------------------------------------------------------------------------------
1.  Click "Copy 12F____ Code" button on the "Setup_Settings" tab in the Excel sheet.
2.  Open MPLAB X, double-click on the "CDI-2012_12F____v1.0.c" file under "Source Files".
3.  Select all of the code in the file and delete it.
4.  Paste the code copied from the Excel sheet.
5.  Click the hammer icon to compile.
6.  The output HEX will be located in the "\dist\default\production" directory under your project directory.  If you used my directory suggestions this file will be: "C:\MPLABXProjects\CDI-2012_12F????_v1.0.X\dist\default\production\CDI-2012_12F????_v1.0.X.production.hex"

You can now flash this to the chip using your favorite flashing tool.  For the 12F683 you can flash directly from MPLAB X.  For the 12F1840 you will have to use another tool.

I use this hardware for flashing (icp01/icp02)...
http://www.piccircuit.com/shop/pic-programmer/55-icp02-usb-pic-programmer.html
It can be purchased for around $20.  There are also cheaper options.  You can find it on eBay or buy just the programmer without the socket.

They also sell a nice little dev board (icp07) for small PICs here...
http://www.piccircuit.com/shop/pic-dev-board/76-icp07-iboard-tiny.html

------------------------------------------------------------------------------
  Other Notes...
------------------------------------------------------------------------------
You can also make your own project file in MPLAB X.  Just make sure to choose the right processor.  Then right click on "Source Files", select New -> C Main File, name the file something with a ".c" extension, delete the generated code in the file, and paste in the source code from the Excel sheet.

If you would like to only install the compiler and just compile the code from the command line you can do so easily.  Just use the Excel spreadsheet to generate and copy the code, create a text file in the directory of your choosing, paste the code into the text file, use the Excel spreadsheet to copy the correct command line, open a command line window in the same directory, and paste the command line into it and hit enter.  You can also copy the cleanup command line and use that to delete the extra garbage files generated by the compiler.

John (gr8flyer55) on RC Universe is the source for the hardware.  He sells kits and finished units.  You can PM him for details.

I highly suggest reading the RCU thread to learn the details about the hardware and settings that will work best for you.  At some point this will be posted on the website, but don't hold your breath.






