1. SOFTWARE

This section of the tutorial is only required if you wish to program form home or on your laptop. The software we will use in this course has already been installed on the computers in your lab.

1.1.Integrated Design Environment – MPLAB IDE

A free copy of the Integrated Design Environment that will be used in this course is available on the Microchip website, at this linkMPLAB® IDE Integrated DevelopmentEnvironment. Scroll to the bottom of the page and under MPLAB Software Downloads select MPLAB IDE v8.30 Full Release Zipped Installation.

Extract the all the files and Double Click on the Install_MPLAB_v830.exe file

1.2.Click Next

1.3.Accept License Agreement --> Click Next

1.4.Select Complete --> Click Next

1.5.Click Next

1.6.Accept License Agreement --> Click Next

1.7.Click Next

1.8.Wait

1.9.Click No

1.10.Click Finish

1.11.Close Window

  1. C Compiler – MCC18 Compiler

A free copy of the C Compiler that will be used in this course is available on the Microchip website, at this link MPLAB C Compiler for PIC18 MCUs.Under Downloads select MPLAB C Compiler for PIC18 MCUs v3.22 Student Edition.Microchip requires that an account be created to download this compiler. Save this file to an appropriate location and then install.

Double Click on the MPLAB-C18-Student Edition-v3.22.exe file

2.1.Click Next

2.2.Accept License Agreement --> Click Next

2.3.Click Next Twice

2.4.Check all check boxes --> Click Next

2.5.Check all check boxes --> Click Next

2.6.Click Next Twice

2.7.Wait

2.8.Uncheck all check boxes -> Click Finish

  1. CREATING A PROJECT (Quick Version)

3.1.Download ML2 Torque Lab *.zip files

3.2.Extract torqueLab.zip into a known 1040 working directory (somewhere you can find it)

3.3.Rename torqueLab folder to your own naming convention

3.4.Double Click torqueLab.mcp project file

3.5.Create a new project by selecting Project --> Save Project As… --> rename the project to you own naming convention --> Click Save

3.6.Double Click on torque.c in the project window

3.7.File --> Save As... --> rename file to you own naming convention (make sure the file has a *.c extension i.e. myRobot.c)

3.8.Click Save

3.9.The original torque.c file has to be removed from the project. Left Click on torque.c and then Right Click on remove.

3.10.The file that you created has to be added to the project. Left Click on the Source Files folder and the Right Click and select Add Files... Browse for the file that you saved and Click on Open to add the file to the project.

3.11.Click on Build All --> Build Succeeded should show in the output window

  1. CREATING A PROJECT (Detailed Version)

4.1.Create a directory (e.g., c:\eng1040) for your project on your hard drive using Windows Explorer.

4.2.Click start -> All Programs -> Microchip -> MPLAB IDE v8.10 -> MPLAB IDE.

4.3.From the toolbar at the top of the screen select Project -> Project Wizard. Click Next to continue to Step One.

4.4.Step One: Select a device. From the Device:dropdown window select PIC18f4550.

4.5.Step Two: Select a language toolsuite. From the Active Toolsuite: dropdown menu select Microchip C18 Toolsuite. All the files in the Toolsuite Contents window must be mapped to the proper location. Set the locations as follows:

4.5.1.MPASM Assembler (mpasmwin.exe) mapped toC:\Program Files\Microchip\MPASM Suite\MPAsmWin.exe

4.5.2.MPLINK Object Linker (mplink.exe) mapped to C:\Program Files\Microchip\MPASM Suite\MPLink.exe

4.5.3.MPLAB C18 C Compiler (mcc18.exe) mapped to C:\MCC18\bin\mcc18.exe

4.5.4.MPLIB Librarian (mplib.exe) mapped to C:\Program Files\Microchip\MPASM Suite\MPLib.exe

4.6.Step Three: Give your new project an appropriate name and locate it in the folder you created on your hard drive (e.g., c:\eng1040).

4.7.Step Four:Add existing files to your project. Navigate to C:\MCC18\h\ and add the following files to your project:

adc.h, delays.h, usart.h, xlcd.h, andp18f4550.h

Next navigate to C:\MCC18\lkr\ and add the following file to your project:

18f4550.lkr

4.8.Click Finish.

4.9.If you are working from home or from your laptop go to the course website and download the following files:

ledBlink.c, xlcd.c, xlcd.h

Copy these files to c:\eng1040and overwrite any of these files that already exist at this location. If you are working from the lab this step may be skipped.

  1. Modifying the Project

5.1.From the toolbar at the top of the screen select View -> Project to display the .mcp window which contains all the files that are included in your project. You should see all the files that you added when creating the project.

5.2.Files can also be added through this window. For example: Left Click on the Source Files folder and the Right Click and select Add Files. Browse to c:\eng1040and add ledBlink.cto your project.To open ledBlink.cjust Double Click on the file name in the .mcp window.

5.3.From the toolbar at the top of the screen select Project -> Build Options -> Project. The following window is displayed.

Select the Directories tab at the top of the window. Map the following directories to the locations specified.

Output Directory mapped to location on the c:\eng1040where you created your project.

Include Search Path mapped to C:\MCC18\h

Library Search Path mapped to C:\MCC18\lib

Linker-Script Search Path mapped to C:\MCC18\lkr

Then click OK.

5.4.Open the ledBlink.cfile you added in step 3.1. To produce the necessary output files we will need to build the project. From the toolbar on the top of the screen select Project -> Build All. Building the project will produce an output Hex file that we will use to download to the Microcontroller Board.

  1. Downloading to the Microcontroller Board

6.1.If you are programming from home or a laptop and this is the first time you have downloaded to the Microcontroller Board you will need to install the driver. From the course website download the bootloader folder and place it in the C: drive or in a location that you can easily locate. If you are programming from your lab you may skip to step 4.7 as the appropriate driver is already installed on the computers in the lab.

6.2.Connect the Microcontroller Board to your computer using the USB cable.On the Microcontroller Board hold the Program button while pressing the Reset button. Release the Reset button followed by the Program button. This puts the Microcontroller Board into bootload mode. The Found New Hardware Wizard will open. Select the No, Not this time option and click Next.

6.3.In the next window select Install from a list or specific location and click Next.

6.4.Select the Search for the best driver in these locations option and check just the box labeled Include this location in the search. Set the location to be C:\bootloader\MCHPUSB Driver\Release and click Next.

6.5.Click Continue Anyway.

6.6.Click Finish.

6.7.To open the PDFSUSB bootload program go to C:\bootloader folder and select PDFSUSB.exe. The following window will be displayed:

6.8.On the Microcontroller Board hold the Program button while pressing the Reset button. Release the Reset button followed by the Program button. This puts the Microcontroller Board into bootload mode.

6.9.On the PDFSUSBwindow select PICDEM FS USB 0 (Boot) from the dropdown menu.Click Load Hex File. Browse to the ledBlink.hex file that you created by building your project and click Open.

6.10.Click Program Device. It should only take a few seconds to program.

6.11.By pressing the Program button on the Microcontroller Board, it is know out of bootload mode and the ledBlink project should run. If the program was downloaded right you should see one led come and stay on for a few seconds until the other led comes on. This pattern should repeat.