Manual Mplab

Embed Size (px)

DESCRIPTION

Manual Mplab

Citation preview

Using PBP With MPLABThe PICBASIC PRO(TM) Compiler can be used within the MPLAB IDE.First, download the latest release of MPLAB, if you don't have it, fromMicrochip's web site (www.microchip.com). As of this writing, version 8.33is Microchip's latest release.Install MPLAB and its components. The default installation directory forMPLAB is C:\Program Files\Microchip. MPASMWIN.EXE is located in thesubdirectory C:\Program Files\Microchip\MPASM Suite.Install the PICBASIC PRO(TM) Compiler according to the instructions found inits readme file. Avoid long directory names or spaces in the installationpath. It is best to install the PICBASIC PRO Compiler in its defaultdirectory, C:\PBP.Next, setup PICBASIC PRO as a language tool within MPLAB. Start MPLAB andselect Set Language Tool Locations under the Project menu. Select theappropriate Toolsuite Name (PICBASIC PRO Compiler) and then Executables.Use the browse button to select PBPMPLAB.BAT within the subdirectory whereit was installed (C:\PBP).Installation of the compiler into MPLAB is now complete. You can now write,edit, simulate and program BASIC projects from within MPLAB.To create a BASIC project within MPLAB, run the Project Wizard under theProject menu. Select the desired processor. Select the appropriatemicroEngineering Labs, Inc. Toolsuite (PICBASIC PRO Compiler). Name theproject. Choose the directory where the source file exists. Add the sourcefile to the project. Click Next, then Finish. You should now be able toedit the source and build the project.More information about using PICBASIC PRO in MPLAB can be found on themelabs web site, http://melabs.com/support/mplab.htm.Additional Case Sensitivity InformationAs the PICBASIC PRO manual points out, the PICBASIC PRO Compiler itself isnot case sensitive. This means, for example, START: would be the same labelas start: or even StArT:.The assemblers that are launched by PBP, on the other hand, are of varyingdegrees of case sensitivity. PM, the included assembler, is also caseinsensitive.MPASM defaults to case sensitive and should be used this way. Normally thiswill have no noticable effect on programs, unless in-line assembly code isused. PBP DEFINEs like OSC and the LCD definitions must be in all upper-case as shown in the examples in the manual.Microchip ICD/ICD2PICBASIC PRO may be used with Microchip's ICD (In-Circuit Debugger) andICD2. The ICDs require certain resources from the target processorincluding access to RAM registers and, in some cases, the first locationof code space.Several files have been created to allocate these locations to the ICD andremove them from the resources the PICBASIC PRO program has access to. Whenit is desired to use the ICD, simply include one of these files at thebeginning of the PICBASIC PRO program.For PIC16F876(A) and 877(A): Include "ICDDEFS.BAS"For PIC16F873(A) and 874(A): Include "ICDDEFS1.BAS"For PIC16F870, 16F871 and 872: Include "ICDDEFS2.BAS"For PIC18F242, 248, 442 and 448: Include "ICDDEFS3.BAS"For PIC18F252, 258, 452 and 458: Include "ICDDEFS4.BAS"For PIC18F6620, 6720, 8620 and 8720: Include "ICDDEFS5.BAS"For PIC18F1220 and 1320: Include "ICDDEFS6.BAS"For PIC18F2220, 2320, 4220 and 4320: Include "ICDDEFS7.BAS"For PIC16F818 and 819: Include "ICDDEFS8.BAS"PICBASIC PRO Source Level Simulation and DebuggingPICBASIC PRO programs may be analyzed using the MPLAB simulator, ICD or ICEat either the assembler or BASIC source level. The generated COD or COFFfile contains the information necessary to do this. COD files are limited toa memory size of 64K bytes. If you want to debug on a device with morememory than this, such as the PIC16F6720 or 8720, you will need to use COFF.MPLAB versions 8.20 and beyond no longer include COD file generation. COFFfiles are used for debugging with these later versions.The steps required for source level debugging are:Create a new project (or open a previous one) in MPLAB using PICBASIC PRO asthe Language suite. If you haven't installed the compiler in MPLAB, referto the installation instructions elsewhere in this document or online athttp://melabs.com/support/mplab.htm.In the Debugger menu, select the debugging tool that you want to use (SIM, ICD, ICE...). In the Build Options dialog box, click on the PICBASIC PRO taband check "Source-Level Debug".Compile or build as usual. Open your source code in a window. Click somewhere on the source code window to set the focus (make the title bar onthis window turn blue).To start source level debugging press the "Step Over" icon or key F8. Youshould see the highlighted line move in the source window with each"Step Over". In general, use "Step Over" when doing source-level debug.If you use "Step" (F7), it may take many more steps to complete 1 BASICinstruction.To run to a particular line, click to place the cursor on the line, then right click the mouse and choose "Run to Cursor". Use this option in the PICBASIC PRO source window if you accidentally step into the LIB file.To set a break point, go to the source line of interest and right click themouse. Choose the Break Point menu item. A small symbol will appear tothe left of the line.Some instructions that make multiple calls will require multiple "Step Over"clicks. It will usually be one click for each command parameter. You willsee the "pc" program counter at the info-bar at the bottom of MPLAB incrementfor each item. Since it is part of the same BASIC command, the "current line" will remain the same. Example: DEBUG "Hello" requires five "Step Over"clicks.Command's that may require multiple "Step Over" clicks include:DEBUG, DEBUGIN, DTMFOUT, FREQOUT, HSERIN, HSEROUT, I2CREAD, I2CWRITE, LCDIN,LCDOUT, SERIN, SERIN2, SEROUT, SEROUT2, SHIFTIN, SHIFTOUT, SOUND, XIN, XOUT,Complex expression like x = y * z / a that have library calls for multiplyand divide.Notes:In simulator mode certain timed functions like PAUSE and PAUSEUS do notoperate at their real-time speed but are simulated very slowly. It may bedesireable to modify a PAUSE 250 to a PAUSE 2 while in simulation mode.It should work at full speed with an ICE.MPLAB is limited in the number of characters that are allowed in the path to your project. You may encounter problems if you store your project toodeeply within your directory structure. If you are encountering unexplained errors, try storing your project files in a directory closer to the root ofyour drive. PICBASIC PRO is a trademark of Microchip Technology Inc. in the U.S.A. andother countries. MPLAB, PIC and PICmicro are registered trademarks ofMicrochip Technology Inc. in the U.S.A. and other countries.