| Joel | People | Hobbies | Fun | Miscellaneous | |||||||||
|
Step 3: Writing & Installing the Program MPLab Software MPLab is an Integrated Development Environment for PIC Microcontrollers. It is a piece of software that runs on your Windows computer that allows you to write PIC software, compile it, debug it, etc. If MPLab is connected to a PIC programmer such as PICSTART Plus, it will allow you to transfer your compiled program to a PIC chip. MPLab combines all these function into a single Windows application. If you have purchased PICSTART Plus, MPLab is included in the package. If you haven't done so already, you will need to install MPLab on your computer. Complete instructions for doing this are included with the software. Make sure you check the PICSTART Plus option when installing MPLab. If you have installed MPLab without the PICSTART Plus option, you will have to re-install MPLab. Connect the PICSTART Plus Programmer If you have not done so already, you will need to connect the PICSTART Plus programmer to a serial port on your computer. Complete instructions for doing this are included with the programmer. You may need to tell MPLab which COM port you are using. The documentation that comes with MPLab explains how to do this. Connect the programmer's power supply to the programmer and plug the power supply into the wall. The green power light on the programmer should come on, but the active indicator should be off. Insert a PIC Into the Programmer On the PIC Programmer, flip the zero-insertion force lever down so that it is laying flat. This opens up the socket so that the chip can be dropped in without having to apply any pressure. Important: Make sure the power supply is connected to the programmer before you insert the chip. Never connect the power supply to the programmer after inserting a chip into the socket. The power supply should be connected before you drop the chip in. This sounds counter intuitive, but this is the correct procedure. The documentation that comes with PICSTART Plus is slightly ambiguous on this point; I hope that I have not been. Place a blank (unprogrammed) PIC 16F84 into the programmer now. You may reuse a previously programmed PIC, but you will overwrite the old program with the new. EEPROM PICs can be reprogrammed this way thousands of times. The socket is labelled for 8, 18, 28 and 40 pin devices. Since the 16F84 is an 18 pin device, make sure the chip lines up with the 18P marks. Pin 1 is also labelled on the socket. Make sure you orient the chip so that pin 1 of the chip lines up with the pin 1 label on the socket. Verify the chip is properly seated in the socket. Make sure it is lying flat and that no pins are out of the socket. Make sure the pins are in the correct socket holes. Once you have verified the chip is situated correctly, lift the lever straight up to lock the chip in place. Create an MPLab Project Start MPLab on your computer. Verify that the PICStart Plus menu is on the menu bar. We'll use it later, but make sure it is there to verify the PICStart Plus option was installed. You will need to create a project. A project is simply a mechanism that MPLab uses to organize the files you create when you write a program. Typically, each MPLab project will have its own directory on your computer. The documentation that comes with MPLab explains how to create a project. Name your project DEMO. You will also need to add a file to the DEMO project. In MPLab, files within projects are represented as "nodes". Name the file DEMO.ASM. Consult the documentation for details about how to do this. Open up the DEMO.ASM file you added to the project. Copy and paste the following code into the blank DEMO.ASM file. ;DEMO.ASM ;LED patterns on port A list p=16F84 porta equ 0x05 org 0x000 goto start start ;configure all port A bits ;for output clrw tris porta ; send the bit pattern out port A movlw b'00000010' movwf porta ; loop forever loop goto loop end Make sure you save the file. Assembling the Program and Programming the PIC In order to send the program to the PIC, it must be assembled into a .HEX file. A .HEX file contains the bits and bytes the programmer needs. To assemble your program, press the F10 key. A status window will appear. You should get no errors, but a warning will appear. Our program uses the TRIS instruction to configure port A for output. Microchip recommends we stop using this instruction. There is another way to configure a port but it involves more code. TRIS still works, and it is much easier to use than the recommended method. You can safely ignore this warning; your PIC program will still run. Select the PICStart menu and click on Enable Programmer. If the programmer is communicating correctly with MPLab, you will see a dialog box appear. You should also see a Configuration Bits dialog. If you do not, click the Configuration Bits button to make it show up. Also, a window containing the HEX machine code of your program should have opened up.
You are just a few clicks from programming the chip.
Make sure the configuration bits settings are as follows: The only thing left to do now is click the Program button. Go ahead and do that. The Active indicator on the programmer should come on, and you should see a status dialog appear. It will take a few seconds to transfer the code and the configuration bits to the chip. EEPROM burning is not instantaneous. When the status window closes, the process is complete. You may click the Verify button to verify the code if you want. When you are done, click the Close button. The programming and configuration bits dialogs will disappear. Move the Chip From the Programmer to Your Circuit The Active indicator on the programmer should be off now. Leave the power supply connected to the programmer. Make sure you are wearing your anti-static wrist strap. Flip the lock lever back down so that it is laying flat again. This will release the chip. Use an IC extractor tool or carefully use your fingers to lift the chip out of the programmer's socket. Avoid touching the pins of the chip. Make sure the power is not connected to your circuit and place the chip into the breadboard. Verify the chip is fully seated into the breadboard and it is in the correct place. Double check each of your connections. The Moment You've Been Waiting For Connect the power to your circuit. If everything went well, one of the LEDs should light up and the other one should remain off. If this isn't the case, remove power immediately. Feel the case on the chip to make sure it is not hot, or even warm. If you feel any heat, it is probably already too late, but it is possible the chip has not been destroyed. What's Next? If you have made it this far, you have accomplished a lot. By performing this demonstration, you have proven you have the basic skills necessary to create PIC projects. What's next is up to you. You might want to connect more LEDs up to the PIC, then reprogram it to turn different patterns of LEDs on and off. Use this basic circuit with LEDs as a platform to learn how to program the chip. Write a program that blinks the LEDs on and off. Create a program that slowly counts from 0 to 255 (0x00 to 0xFF) and displays the counter value on Port B. By connecting LEDs to the Port B pins, you can watch the LEDs display the counter value in binary. Once you have written programs with a higher degree of complexity, you might want to start interfacing external components to the chip and writing programs to react to changing inputs. One project will lead to another. You probably already have ideas of what you'd like to build next. Have fun! Find more information about the PIC 16F84 here.
|
||||||||
| Tell me what you think | Copyright © 2000 Joel T. Anderson | |