MPLAB Tutorial

1. What you will learn
    1.1. How to create a project using MPLAB.

    1.2. How to link the files necessary to build a hex file.

    1.3. How to simulate operation of the file.

    1.4. How to emulate the microcontroller using MPLAB ICE 2000.

    1.5. How to program the microcontroller using the BPMICROSYSTEMS BP-1400.

2. Setting up your environment
    2.1. First, it is recommended that you create an separate directory under your class account to hold the designs for the tutorial.  Open a DOS window and type the following:
     
      >>cd\
      >>cd students
      >>mkdir <user name>
      >>cd <user name>
      >>mkdir tutorial
      >>cd tutorial
      >>mkdir arm
      >>cd arm
    2.2.  Copy the files robot.c and dy100tcx.asm from the directory c:\mcc\examples\robot into your directory.
     
      >>copy c:progra~1\mplab\mcc\examples\arm\arm.c .

     

    2.3.  Open the arm.c file in the notepad to examine it.

         This program generates a pulse for each of the three movements of the robotic arm.  The robot operates on a pulse that is transmitted to each servo.  The pulse can be between .5 and 2.5ms.  A 1.5ms pulsewidth centers the servo.  The program calls two header files.  One for the 17C44 microcontroller and the the other for the delays.  The define statements are constants that are inserted into the body of the code when it is compiled and do not count as memory.  Any constant you want to use should be a define statement.  All of the variables are defined and set to intial values to center the robotic arm.  DDRC = 0x00 sets port C as an output.  The output pulses will control the robotic arm.  A high signal is generated and the code then goes through a delay, the length of which determines the generated pulse width. The output is then set low. This process is repeated for the other two servos in the arm. The value of the three pulses is added and then subtracted from 10 ms to generate the overall loop delay.  This insures a stable pulse repetition rate.

3. Creating the project for control of the robotic arm
    3.1.   Start the MPLAB IDE (Integrated Development Environment) by double clicking on the MPLAB icon inside the Microchip MPLAB folder on the desktop.
    3.2.   Create a new project by selecting Project->New Project from the main window menus. Navigate to your c:\students\<user name>\tutorial\arm directory and set the file name to  arm.pjt.  This will bring up the Edit Project box and make the Target Filename arm.hex as shown below.
     


     

    3.3.  Click on arm.hex and then click on Node Properties.  The Node Properties box will come up.  Change the Language tool to MPLINK.  Click OK.

    3.4.  In the Edit Project box click Add Node.  Choose folder C:\Students\<user>\tutorial\arm\ click on the arm.c file and click OK.
     

    3.5.  Click Add Node again.  Choose folder C:\progra~1\mplab\mcc\lib\ and change the file types to .o object files.  Add files c0s17.o, idata17.o and p17c44.o.  Click OK.

    3.6. Click Add Node.  Choose folder C:\progra~1\mplab\mcc\lkr\ and change the file type to .lkr linker files.  Add node p17c44s.lkr

    3.7. Click Add Node.  Choose folder C:\progra~1\mplab\mcc\src\pmc\ and change the file type to .c, .asm source files.  Add node dy100tcx.asm.  Click OK  The screen should look similar to the one below:
     


     
     

    3.7.  Click OK.  Select Project->Make Project.  The program will now link and assemble all of the necessary files.  A Build Results window will come up showing the files being compiled.  The last line in the Build Results window should say "Build completed successfully."
4. Simulation of the Program
5. Emulation of the microcontroller on the robotic arm board
6. Programming of the microcontroller
    6.3.  Turn the BP-1400 programmer on.  Log on to the other computer and on the desktop double click on the BP icon.  This will bring up the program in DOS.
     
    6.4.  Tab over to Select and type in 17c42a and hit enter.  This will set the proper microcontroller.
     
    6.5.  Tab over to the heading Buffer/Load.  Change the directory to where you put the robot.hex file.  Hit enter and this will show the program being loaded into the buffer.
     
    6.6.  Insert the chip into the socket and push the lever down to lock it in place.