0
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
创作中心
发布
  • 发文章

  • 发资料

  • 发帖

  • 提问

  • 发视频

创作活动
QW1

QW1

  • 厂商:

    TECHTOOLS

  • 封装:

    -

  • 描述:

    PROGRAMMER PIC MCU QUICKWRITER

  • 数据手册
  • 价格&库存
QW1 数据手册
PicTools Manual 3.0 © 2007 TechTools PicTools Manual 3.0 © 2007 TechTools All rights reserved. No parts of this work may be reproduced in any form or by any means - graphic, electronic, or mechanical, including photocopying, recording, taping, or information storage and retrieval systems - without the written permission of TechTools except for the purpose of enhancing the operation of the product by the end user, informing other prospective users of the product's features or for instructional benefit by the US Government or an educational institution. While every precaution has been taken in the preparation of this document, TechTools assumes no responsibility for errors or omissions, or for damages resulting from the use of information contained in this document or from the use of programs and source code or hardware that may accompany it. In no event shall TechTools be liable for any loss of profit or any other commercial damage caused or alleged to have been caused directly or indirectly by this document. Printed: September 2007 in Garland, Texas U.S.A. Publisher TechTools P.O. Box 462101 Garland, TX 75046-2101 U.S.A. Technical Sales (972) 272-9392 Fax (972) 494-5814 Email Sales@tech-tools.com Support@tech-tools.com On The Web www.tech-tools.com Contents II Table of Contents Foreword 0 Part I TechTools PicTools Introduction 2 Part II QuickWriter MCU Programmer 4 1 HEX File ................................................................................................................................... 5 2 Setting Options ................................................................................................................................... 5 Setting Auto Options .......................................................................................................................................................... Setting General.......................................................................................................................................................... Options Setting HEX Options .......................................................................................................................................................... Setting Serial.......................................................................................................................................................... Number Options Setting Advanced .......................................................................................................................................................... Options Setting I.D. Locations .......................................................................................................................................................... Setting Options .......................................................................................................................................................... for Production Personnel 3 Operation ................................................................................................................................... 15 Selecting the .......................................................................................................................................................... MCU Setting the Configuration .......................................................................................................................................................... Word (Fuses) Using Gang Adapters .......................................................................................................................................................... Using Serial Numbers .......................................................................................................................................................... Reading the MCU .......................................................................................................................................................... Contents 4 Advanced 6 7 9 10 12 13 14 15 15 17 17 19 ................................................................................................................................... 20 In-Circuit Programming .......................................................................................................................................................... ICP with Self .......................................................................................................................................................... Powered Targets Cable Connector .......................................................................................................................................................... Command-line .......................................................................................................................................................... Operation Exit Codes .......................................................................................................................................................... Legend - Programming .......................................................................................................................................................... Tasks Part III TechTools Design Environment 20 21 23 23 24 25 27 1 Sample Project ................................................................................................................................... 27 Starting TDE .......................................................................................................................................................... Opening The .......................................................................................................................................................... Project Loading a Source .......................................................................................................................................................... File Hardware Settings, .......................................................................................................................................................... Project Info Device Settings, .......................................................................................................................................................... Building the Project Running the Code, .......................................................................................................................................................... Stopping Execution Single-Stepping .......................................................................................................................................................... Animation, Watching .......................................................................................................................................................... Variable Values Watching Variables, .......................................................................................................................................................... Viewing Special Registers Watching the .......................................................................................................................................................... Program Run Resetting the.......................................................................................................................................................... Emulator, Setting Breakpoints Finishing the .......................................................................................................................................................... Project 28 28 29 31 32 34 35 36 38 40 41 43 2 TDE Details ................................................................................................................................... 44 Project and File .......................................................................................................................................................... Operations 45 Creating a......................................................................................................................................................... Single-file Project 46 Adding a File ......................................................................................................................................... 48 Creating a......................................................................................................................................................... Multiple-file Project 50 © 2007 TechTools II III PicTools Manual 3.0 Adding Files ......................................................................................................................................... Mode of Operation ......................................................................................................................................................... Watch Dog ......................................................................................................................................................... Timer Break on ......................................................................................................................................................... Stack Over/Underflow Device Settings ......................................................................................................................................................... Trace Buffer ......................................................................................................................................................... Environment ......................................................................................................................................................... Preferences Editor Preferences ......................................................................................................................................... General preferences ......................................................................................................................................... Build Preferences ......................................................................................................................................... Debug Preferences ......................................................................................................................................... Programming Preferences ......................................................................................................................................... Resetting......................................................................................................................................................... the Emulator Printing ......................................................................................................................................................... Compiling and .......................................................................................................................................................... Executing Code Building the ......................................................................................................................................................... Project Executing......................................................................................................................................................... Code at Full Speed Halting Execution ......................................................................................................................................................... Single-Step ......................................................................................................................................................... Execution Step OUT......................................................................................................................................................... Execution Step Over......................................................................................................................................................... Execution Animation-Mode ......................................................................................................................................................... Execution Animate Over ......................................................................................................................................................... Execution Showing the ......................................................................................................................................................... Execution Point Resetting......................................................................................................................................................... the Emulated PIC Setting the ......................................................................................................................................................... Program Counter Using Breakpoints ......................................................................................................................................................... Using the Various .......................................................................................................................................................... TDE Windows Window Basics ......................................................................................................................................................... Editor Window ......................................................................................................................................................... Enter source code ......................................................................................................................................... Set and clear breakpoints ......................................................................................................................................... Cut, copy, and paste ......................................................................................................................................... Undo and redo ......................................................................................................................................... Search and replace ......................................................................................................................................... Place markers ......................................................................................................................................... Build Log......................................................................................................................................................... Code Window ......................................................................................................................................................... Symbols Window ......................................................................................................................................................... Special Registers ......................................................................................................................................... Window Variables Window ......................................................................................................................................... Labels Window......................................................................................................................................... Files Window ......................................................................................................................................... File Registers ......................................................................................................................................................... Window Watch List ......................................................................................................................................................... Window Adding Watch items ......................................................................................................................................... by Highlighting Add Watch Dialog ......................................................................................................................................... Modifying Watch ......................................................................................................................................... item values Watch List Options ......................................................................................................................................... Trace Buffer ......................................................................................................................................................... Window Data Breakpoints .......................................................................................................................................................... DBP Enable ......................................................................................................................................................... and Break On options DBP File......................................................................................................................................................... Register options DBP Match ......................................................................................................................................................... On options 51 55 57 57 59 60 62 63 64 65 65 66 66 67 68 68 70 71 71 72 73 74 74 75 76 77 78 80 80 82 85 85 85 88 89 91 93 95 96 97 99 103 105 105 108 108 109 112 115 116 118 120 120 121 © 2007 TechTools Contents IV DBP Include ......................................................................................................................................................... Constants Breaking......................................................................................................................................................... on data 123 124 3 Compiler Integration ................................................................................................................................... Notes 125 How we do it.......................................................................................................................................................... CVASM16 .......................................................................................................................................................... SPASM .......................................................................................................................................................... MPASM .......................................................................................................................................................... MPLINK .......................................................................................................................................................... Bytecraft C .......................................................................................................................................................... Bytecraft LINKER .......................................................................................................................................................... MPLABC .......................................................................................................................................................... Hi-Tech C .......................................................................................................................................................... CCS .......................................................................................................................................................... COD ONLY .......................................................................................................................................................... HEX ONLY .......................................................................................................................................................... Part IV ClearView Assembler 126 127 127 127 128 128 128 129 129 130 131 131 133 1 CVASM16 Reference ................................................................................................................................... 134 Software Installation .......................................................................................................................................................... Running the.......................................................................................................................................................... Assembler Generating Assembly .......................................................................................................................................................... Listings Command-Line .......................................................................................................................................................... Options Assembler Basics .......................................................................................................................................................... Addressing Definitions .......................................................................................................................................................... Data Types .......................................................................................................................................................... Expressions.......................................................................................................................................................... Symbols & Labels .......................................................................................................................................................... Local Labels.......................................................................................................................................................... Default_Symbol_Tables .......................................................................................................................................................... Comments .......................................................................................................................................................... Assembler Directives .......................................................................................................................................................... Source Code.......................................................................................................................................................... Formatting CVASM16 Error .......................................................................................................................................................... Messages 134 134 135 135 135 136 136 138 138 139 139 140 140 142 142 2 TechTools Instruction ................................................................................................................................... Set 144 Microchip to.......................................................................................................................................................... CVASM16 ADD, ADDB .......................................................................................................................................................... AND .......................................................................................................................................................... CALL .......................................................................................................................................................... CJA, CJAE .......................................................................................................................................................... CJB, CJBE .......................................................................................................................................................... CJE .......................................................................................................................................................... CJNE .......................................................................................................................................................... CLR .......................................................................................................................................................... CLRB, CLC, .......................................................................................................................................................... CLZ CSA, CSAE .......................................................................................................................................................... CSB, CSBE .......................................................................................................................................................... CSE .......................................................................................................................................................... CSNE .......................................................................................................................................................... DEC, DECSZ, .......................................................................................................................................................... DJNZ IJNZ, INC, INCSZ .......................................................................................................................................................... JB, JC .......................................................................................................................................................... JMP .......................................................................................................................................................... JNB, JNC .......................................................................................................................................................... 145 148 150 151 152 153 154 155 156 157 157 159 160 161 162 163 164 164 165 © 2007 TechTools IV V PicTools Manual 3.0 JNZ, JZ .......................................................................................................................................................... LCALL, LJMP, .......................................................................................................................................................... LSET MOV [to register] .......................................................................................................................................................... MOV [to OPTION] .......................................................................................................................................................... MOV [to I/O Control] .......................................................................................................................................................... MOV [to W] .......................................................................................................................................................... MOV [using .......................................................................................................................................................... Expressions] MOVB .......................................................................................................................................................... MOVSZ .......................................................................................................................................................... NOP .......................................................................................................................................................... NOT .......................................................................................................................................................... OR .......................................................................................................................................................... RET, RETFI, .......................................................................................................................................................... RETW RL, RR .......................................................................................................................................................... SB, SC, SZ .......................................................................................................................................................... SETB, STC, STZ .......................................................................................................................................................... SKIP .......................................................................................................................................................... SLEEP .......................................................................................................................................................... SNB, SNC, SNZ .......................................................................................................................................................... SUB, SUBB .......................................................................................................................................................... SWAP .......................................................................................................................................................... TEST .......................................................................................................................................................... XOR .......................................................................................................................................................... 166 166 169 169 171 172 172 174 175 175 176 176 178 179 179 180 181 181 182 183 184 184 185 3 Sample Projects ................................................................................................................................... 186 Simple.tpr .......................................................................................................................................................... Table.tpr .......................................................................................................................................................... Bargraph.tpr.......................................................................................................................................................... Part V ClearView Mathias Hardware 187 190 194 199 1 ClearView Mathias ................................................................................................................................... 199 2 System Requirements ................................................................................................................................... 200 3 Packing List................................................................................................................................... 200 4 Hardware Features ................................................................................................................................... 201 5 Hardware Installation ................................................................................................................................... 201 6 Power Supply ................................................................................................................................... Considerations 203 7 MCLR Pull-Up ................................................................................................................................... Resistor 204 8 Optional Modules ................................................................................................................................... 205 Index 207 © 2007 TechTools TechTools PicTools Introduction Part I 2 1 PicTools Manual 3.0 TechTools PicTools Introduction This manual covers information for using the following TechTools products: QuickWriter (MCU Programmer 4 ), ClearView Mathias (In-Circuit Emulator 199 ), CVASM (ClearView Assembler 133 ), TDE (TechTools Design Environment 27 ) QuickWriter and Mathias are hardware devices that use our CVASM and TDE software. This manual will reference both hardware products in the software sections, so not all features will be available unless you own both products. For example, the debugging features of TDE will not be available if you do not own a ClearView Mathias In-Circuit Emulator. Thank You for choosing TechTools for your development needs. www.tech-tools.com (972) 272-9392 Email Support Email Sales © 2007 TechTools QuickWriter MCU Programmer Part II 4 2 PicTools Manual 3.0 QuickWriter MCU Programmer Hex Files · Opening a HEX File 5 Setting Options · · · · · · · · Setting Options 5 Setting Auto Options 6 Setting General Options 7 Setting HEX Options 9 Setting Serial Number Options 10 Setting Advanced Options 12 Setting I.D. Locations 13 Setting Options for Production Personnel 14 Operation · · · · · · Operation 15 Selecting the MCU 15 Setting the Configuration Word (Fuses) Using Gang Adapters 17 Using Serial Numbers 17 Reading the MCU Contents 19 15 Advanced · · · · Advanced 20 In-Circuit Programming 20 ICP with Self Powered Targets Cable Connector 23 21 © 2007 TechTools QuickWriter MCU Programmer · Command-line Operation 23 · Exit Codes 24 · Legend - Programming Tasks 2.1 5 25 HEX File Overview QuickWriter accepts INHX8M (INTEL HEX 8 bit merged) and INHX32 HEX files. For the PICmicro MCU microcontroller, these are generally in one of two formats: Microchip: Includes Code, Data, ID and Configuration Word information. This format is normally saved with a ".hex" extension. TechTools: Includes Code, Data, ID, Device type, Configuration Word and sometimes Calibration information. This format is normally saved with a ".obj" extension. QuickWriter will accept the above formats and adjust all relative data according to the type of information found in the HEX file. Any information that is missing from the HEX file (such as the Configuration Word) will be set to defaults unless manually overridden elsewhere in the program. If the MCU type is not specified, then the currently selected MCU will be used. QuickWriter saves HEX files with the ".hex" extension following Microchip's format. However, it also includes the device type as a comment that can be read by QuickWriter. This allows other products that may not recognize the device type to use the HEX file without experiencing any errors. Details Select "FILE - Open File". Choose the desired file, then click "Open". The full filename and path will be displayed in the Title Bar of the program, the file will be loaded into memory and all displayed data will be updated with the contents of the HEX file. Shortcuts Alt+F, O 2.2 Setting Options Overview Options are divided into five categories: Auto Run Options 6 - Enables and disables programming operations and sections of the MCU for "Auto Run" cycles. These selections will enable or disable speed buttons and the associated item in the "Task Tree" on the left of the main window, but will not affect the "MCU SECTION" menu items, which will always be available while "Option Editing" is enabled in General Options. General Options 7 - General options that are not normally needed during development but help when preparing settings for production personnel. © 2007 TechTools 6 PicTools Manual 3.0 HEX Options 9 - Provides HEX file Overrides for the specific HEX file and selection of records to include when saving HEX files. Serial Numbers 10 - Enable and set Serial Numbering details such as number of locations, area of the MCU and address to place the serial number. Advanced Options 12 - Advanced settings mainly related to In-Circuit Programming. All options are dynamic and take effect immediately when changed. It is NOT necessary to "close" the options window or to "save option settings" in order to "apply" the new settings. QuickWriter was designed with developers in mind and frequent option changes between programming tasks or "auto run" cycles is expected. Details Option changes and Editing take effect immediately regardless of whether the Window is closed or remains open. Options are saved permanantly when the application is closed and when "File - Save Option Settings" is selected. Options are loaded whenever the application starts and when a HEX file is loaded. Options will be restored from the HEX file and the corresponding ".QWC" (QuickWriter Control) file if found, otherwise all options will remain unchanged from the current settings. NOTE: Some options are Refreshed from permanent settings when the MCU selection is changed. Be sure to save any changes to options before changing the MCU selection. Shortcuts Alt+O 2.2.1 Setting Auto Options Overview Enables and disables programming operations and sections of the MCU for "Auto Run" cycles. These selections will enable or disable speed buttons and the associated item in the "Task Tree" on the left of the main window, but will not affect the "MCU SECTION" menu items, which will always be available while "Option Editing" is enabled in General Options. Details Operations: Enable Erase - If available for the MCU and selected, a bulk erase is performed on the FLASH device during Auto Run cycles. Enable Blank Check - If selected, a blank check is performed on all enabled areas of the © 2007 TechTools QuickWriter MCU Programmer 7 device during Auto Run cycles. We suggest leaving this option enabled unless reprogramming an MCU that already contains data. Enable Verify - If selected, a verify will be performed during Auto Run cycles on all selected areas of the MCU (i.e. Code, EE Data, Calibration, ID) before the Configuration Word is programmed. Most programming operations automatically verify during programming, but because some MCU algorithms do not, we suggest always leaving this option enabled. Enable Serial Numbering - If selected, the MCU will be serialized (just prior to programming the Configuration word) during Auto Run cycles according to the settings in Serial Number options 10 (also see: Using Serial Numbers 17 ). MCU Sections: Enable Code - If selected, the Code Space area will be blank checked, programmed and verified during Auto Run cycles according to Operation settings. Enable EE Data - If selected, the EE Data area will be programmed and verified during Auto Run cycles. Enable ID Locations - If selected, the ID locations will be blank checked, programmed and verified during Auto Run cycles. ID locations have no bearing on the operation of the MCU and can be ignored if desired. Enable Calibration - If available for the MCU and selected, the Calibration area will be blank checked, programmed and verified during Auto Run cycles. Some FLASH MCUs with calibration require this option and QuickWriter will automatically select it for you. If the MCU is not a FLASH device, we strongly advise against selecting this option unless programming a JW (windowed) device. Attempting to program the calibration area of an OTP (one time programmable) device will result in corrupted calibration data. Enable Fuses - If selected, the Configuration Word will be programmed and verified during Auto Run cycles. Shortcuts Alt+O, O 2.2.2 Setting General Options Overview General options that are not normally needed during development but help when preparing settings for production personnel. © 2007 TechTools 8 PicTools Manual 3.0 Details Misc. Options: Skip Blank Locations - If selected, any "Blank" value will be skipped during programming, which can greatly reduce programming time on large devices that are only using small portions of the Code space. Keep in mind however, that after serializing an MCU in a "Blank" area of the code space, verifying will pass because of skipping over the blank area. Likewise, blank checking will fail because a "non-blank" value is detected. This normally is not an issue but could be confusing when manually selecting individual programming tasks out of sequence. NOTE: This setting has no effect on 18 series MCU's and some newer FLASH MCU's due to multi-word programming algorithms. Disable Task Confirmation Messages - If selected, all "Are You Sure?" type messages will be disabled. We suggest enabling this option after you are thoroughly familiar with the programs operation. Warn if CODE/Data Protection is Enabled - If selected, a warning dialog will appear if the Fuse Options are set to "Protect" any area of the MCU. (see: Setting the Configuration Word (Fuses) 15 ) Use High Speed Transfers - Select this option to enable higher speed communication between the PC and Quickwriter. This will double the speed of Reading from the device and may reduce total programming time slightly on some MCU's. If any communication errors are detected while this option is enabled, QuickWriter will automatically switch back to the normal transfer speed until "Reset QuickWriter" is selected, a new port is selected, this option is re-selected or the program is restarted. Use Microchip Checksums - If selected, QuickWriter's buffer checksum calculation will adhere to Microchip's method of calculation which does not include the EEDATA and only includes Code and User IDs depending on the values of the Fuses and the device selected. The resulting calculation is displayed as a 16 bit HEX value. To match Microchip's "Code Protected" checksum value, enable this option and "Read" a code protected device. If not selected, QuickWriter's checksum will include all enabled buffers (Code, EEDATA, User IDs and FUSES) and the resulting calculation is displayed as a 32 bit HEX value. Production Control: © 2007 TechTools QuickWriter MCU Programmer 9 Disable Option Editing - When this option is selected, all access to change options is hidden when the HEX file is opened. This prevents production personnel from accidentally changing settings and producing "unusable" devices. To regain access, simply choose "Edit - Enable Option Editing". Entering the correct password will re-enable access to the options and the Editors. If no password was specified when Option Editing was disabled, then leave the password field blank and select "OK" to re-enable access. Disable EE Data Editor - When this option is selected, access to the EE Data editor will be disabled. Disable Read Functions - If selected, all READ functions will be disabled. This will prevent production personnel from accidentally "Reading" the MCU and possibly changing loaded data. Open in Compact View - When this option is selected, QuickWriter will open in "Compact View" only, regardless of the view selected previously. When this option is left unchecked, the view state is retreived from the operator's local settings (stored in the Operating System's Registry). Password to Enable Option Editing - If a password exists in this field and the "Disable Option Editing" option is checked, then this password will be required to re-enable option editing when the current HEX file is re-opened. The password is limited to 32 Alpha-Numeric characters. (also see: Setting Options for Production Personnel 14 ) Shortcuts Alt+O, G 2.2.3 Setting HEX Options Overview Provides HEX file Overrides for the specific HEX file and selection of records to include when saving HEX files. Details Open HEX File - Override HEX Options: © 2007 TechTools 10 PicTools Manual 3.0 Ignore EE DATA - If selected, data currently displayed in the EE DATA editor will be saved and used whenever this HEX file is re-opened or the MCU selection changes, regardless of the data contained in the HEX file. Ignore FUSE record - If selected, data currently displayed in the FUSES editor will be saved and used whenever this HEX file is re-opened or the MCU selection changes, regardless of the data contained in the HEX file. Ignore ID record - If selected, data currently displayed in the ID Locations editor will be saved and used whenever this HEX file is re-opened or the MCU selection changes, regardless of the data contained in the HEX file. Ignore MCU record - If selected, the currently displayed MCU will be saved and used whenever this HEX file is re-opened, regardless of the data contained in the HEX file. Save HEX File - Include Record Options: Include MCU Type - If selected, a "device" record will be included in the generated HEX file during a save. Include FUSE Settings - If selected, a "Configuration Word" record will be included in the generated HEX file during a save. Include EE Data - If selected, the EE Data will be included in the generated HEX file during a save. Include Calibration Data - If selected, the Calibration Data will be included in the generated HEX file during a save. When multiple MCU devices with configuration data are present (i.e using a 4-gang adapter), the configuration data will be saved from the current selection in the Calibration Editor. Shortcuts Alt+O, H 2.2.4 Setting Serial Number Options Overview Enable and set Serial Numbering details such as number of locations, area of the MCU and © 2007 TechTools QuickWriter MCU Programmer 11 address to place the serial number. Details Serial Number Options: Enable Serial Numbering - If selected, the MCU will be serialized during Auto Run cycles. Use Existing Microchip SQTP file - When selected, use the button to the left of the option to choose an SQTP file (*.num). A log file will automatically be created with the same name but with a "QWL" extension. Each serial number is marked as "used" when it is retreived from the SQTP file to prevent using the same number twice. As each number is programmed into a PICmicro MCU, the results are stored in the log file, including Pass or Fail, the QuickWriter used, the Socket used and the time in ms. The SQTP file can reside anywhere on a local network as QuickWriter fully implements file sharing mechanisms for the SQTP file and the corresponding LOG file. Microchip SQTP files can be generated using the MPLAB environment provided by Microchip Technology Inc. To generate this file from MPLAB, the appropriate tool (such as a Pro version programmer) must be selected (see the Help information provided with MPLAB). Or an equivelant HEX file can be generated manually with an identical address specified for each HEX line. NOTE: When this option is selected, the "Locations" and "Address" options are disabled since this information is retreived from the SQTP file. © 2007 TechTools 12 PicTools Manual 3.0 Place in Code Memory - If selected, the Serial number will be programmed into the Code area of the MCU. This also enables access to the Encode as RETLW option. Encode as RETLW - This option is only available if the CODE memory option is selected. If selected, each Serial number location will be converted into the proper RETLW OPCODE (return literal in W) for the currently selected MCU. Place in EEPROM Memory - If selected, the Serial number will be programmed into the EE DATA area of the MCU. This also Disables access to the Encode as RETLW option. Number of Locations - Enter the maximum number of locations the serial number will need (from 1 to 8). Each byte of the serial number will use 1 location in the memory area specified. Place at Address - Enter the address in the selected memory area to place the serial number. This can be from 0 to the highest available address, minus the number of locations specified. If an address higher than the maximum valid address is specified, QuickWriter will notify you and automatically reduce the address to the highest valid address for the selected memory area and number of locations. (also see: Using Serial Numbers 17 ) Shortcuts Alt+O, N 2.2.5 Setting Advanced Options Overview Adjust the Programming Pulse Width of FLASH MCUs and choose Target Power Options for ICP (In-Circuit Programming). Details FLASH Programming Pulse Width: Modify this setting in "Less than Optimal" situations to ensure successful programming over voltage, temperature, device and circuit variations. The default value of Tmin is preset to the Factory Recommended Value that already accounts for temperature and device variations. However if errors occur when programming In-circuit, this value may need to be adjusted to account for Voltage and Circuit variations. Each step in the selector (shown above) will increase the duration of the programming pulse by 1/4 of the Factory Recommended Value. The 5 steps are as follows: PPW = Tmin or 1 PPW PPW = (Tmin + (Tmin /4)) or 1.25 PPW PPW = (Tmin + ((Tmin /4) * 2)) or 1.50 PPW PPW = (Tmin + ((Tmin /4) * 3)) or 1.75 PPW PPW = (Tmin * 2) or 2 PPW © 2007 TechTools QuickWriter MCU Programmer 13 If the calculated value exceeds factory specifications or a maximum of 255 ms, it will be adjusted apropriately. Target Voltage Option: Modify this setting for In-Circuit Programming to select whether QuickWriter supplies the power for the target circuit or whether the Target circuit will supply its own power. (see: ICP with Self Powered Targets 21 ) Skip Power Cycles: Select this option to have QuickWriter reduce the number of Power OFF/ON cycles during "Auto" cycles. This option is not recommended, but may be needed for some in-circuit configurations. Override Power Off Requirement: Select this option if it is neccessary to have power present in the target circuit before starting any "Auto" cycle. When selected, this option also will not require the target power to be removed when the cycle has been completed. NOTE: This option is not recommended, but has been added due to popular request. Shortcuts Alt+O, A 2.2.6 Setting I.D. Locations Overview PICmicro MCU's have four or eight ID locations reserved for the customer's use. Although each location may be 12, 14 or 16 bits in length (depending on the MCU), the manufacturer recommends using the 4 least significant bits of each location. Common industry practice has offered the ability to use the 7 least significant bits of each location therefore, we provide both options. If your HEX file does not include ID information or you would like override the ID with a different value whenever the HEX file is opened, select the "Override" check box after changing the ID values. Details © 2007 TechTools 14 PicTools Manual 3.0 Select "Edit - ID Locations". If the values displayed do not reflect those desired, simply select and edit the appropriate field (4 bit or 7 bit). Any changes take effect immediately and will be implemented with the next programming action (i.e. Autorun, program ID locations, etc.). (see also: Setting HEX Options 9 ) Shortcuts Alt+E, I 2.2.7 Setting Options for Production Personnel Overview Sometimes it is desirable to block access to option settings for a HEX file in order to prevent undesired changes. Whether this is for archiving "released" code or for the production department, QuickWriter provides a simple method of protecting your settings from accidental changes. This is accomplished through a "control" file. The control file contains all option settings for QuickWriter, is saved in the same directory as the HEX file and is created with the same name as the HEX file except the file extension is changed to ".QWC". One of the options in the control file instructs QuickWriter to DISABLE option editing. The following will be disabled when a HEX file is opened, if the "Disable Option Editing for this file" option has been selected: MCU selection. Auto Options, HEX Options and General Options. Code, FUSE, ID and Calibration editors. Manual access to tasks in the "Programming Tasks" tree or MCU Section menu. ALL programming functions except Auto Run, Erase, Blank Check and Verify. A detailed procedure for setting options for production personnel is described below but the general procedure is to Open the HEX file, set all desired options, select "Disable Option Editing" in "General Options", then select "File - Save Option Settings". The control file has now been created and modified (resides in the same directory as the HEX file), and is now ready for the production department. Details To configure a HEX file for archiving or production use, follow the procedure described here. 1. 2. 3. 4. Open the desired HEX file from the directory it will be used in if possible. Verify the MCU, Configuration Word and ID location settings. If the MCU and Configuration Word are incorrect you will need to make the necessary changes, then save the HEX file with ALL "Save Hex Options" enabled or select the proper overrides in HEX Options. After saving the hex file, re-open it and re-verify the MCU, Configuration Word and etc. If everything is correct, proceed with the next step. Go to the "Options - Auto Options" and select each option to be performed during programming. Each selected item will be performed when the production department chooses "Auto Run" (or F4 or Alt+A). If you have enabled Serialization, verify the serial number length and address settings to prevent overlapping valid code or EE data. Also verify the "last serial number" and "Auto Increment" settings (see: Using Serial Numbers 17 ). © 2007 TechTools QuickWriter MCU Programmer 5. 6. 7. 15 After all settings have been verified, select "Disable Option Editing.." in the "Misc. Options" section of the "General Options". You may also want to select "Disable Read Functions" in this same location. Select "File - Save Option Settings" from the main menu, then close the program. Copy the HEX file and the corresponding control file (hexfilename.QWC) to the desired location for production accessability. The production department can now open the HEX file without fear of accidental changes. Shortcuts Alt+E, i (disable option editing for testing) Alt+E, E (enable option editing for further editing) 2.3 Operation Operation · · · · · 2.3.1 Selecting the MCU 15 Setting the Configuration Word (Fuses) Using Gang Adapters 17 Using Serial Numbers 17 Reading the MCU Contents 19 15 Selecting the MCU Overview Some HEX files will not contain the MCU type or you may want to select a different MCU to program. When the MCU type changes, QuickWriter will adjust many aspects of the software to match the capabilities of the selected device. Because of this it is very important to select the proper MCU type (including prefixes such as 'A','B' and etc.). Details Select "Options - Select MCU Type". When the MCU dialog opens use the cursor keys or the mouse to select the desired MCU, then click the 'OK' button (or press the 'Enter' key) or "DBLClick" on the desired MCU. (see also: Setting HEX Options 9 ) Shortcuts Alt+O, S 2.3.2 Setting the Configuration Word (Fuses) Overview The configuration Word is set according to data stored in the HEX file when it is opened. However, you are free to change this information in the program before programming the MCU, provided "Option Editing" is enabled for this HEX file (see: Setting General Options 7 ; see also: Setting Options for Production Personnel 14 ). Specific bits in each Configuration Word control available MCU options when programmed. © 2007 TechTools 16 PicTools Manual 3.0 QuickWriter identifies each set of bits by labels provided in the manufacturers datasheet. If you are not familiar with a particular reference, such as WDT (Watch Dog Timer), you will need to see the datasheet which will give a full explanation of the configuration option and its meaning. Do not change the configuration word unless you are fully aware of each options function. Selecting the wrong configuration can make the MCU operation undesirable or unreliable, which renders the device unusable. Details Select "Edit - Configuration Word". To change FUSES in the configuration word, use the selection arrow beside each Fuse option to select from its available settings (or use the TAB and CURSOR keys). WARN if Code Protection Enabled - If selected and one of the Configuration Fuses indicate that the Code or Data Protection fuse(s) have been enabled, you will be presented with three options before programming the MCU. This warning will help remind you that the protection fuses are about to be enabled. Once the Code or Data protection fuses have been enabled on a device, the contents of the protected section is no longer accessible for READING or VERIFYING. NOTE: Code Protection will prevent erasing on most JW (Windowed, eraseble) devices. If setting the Protection fuse was unintentional, then select NO to have QuickWriter automatically disable the Protection and continue with the operation in progress. Otherwise choose YES to continue "AS IS" or CANCEL to completely abort the operation. NOTE: Each MCU has different Configuration options. If the MCU type is changed, you will need to review changes in the Configuration Word options before programming the MCU. (see also: Setting HEX Options 9 ) Special Consideration Some PICmicro MCUs have Fuse options to "turn off" the external MCLR signal and others may have options to set the Oscillator to "internal". On older MCUs with these options and a "Power First" requirement of VDD (such as the 12C508/12C509), QuickWriter may have problems reprogramming or reading the contents once the fuses have been programmed. This normally does not become an issue since the devices are OTP (one time programmable). Newer MCUs with these fuse options allow a "Power first" of VPP (programming Voltage), which ensures the device can re-enter programming mode and be read after the fuses have been programmed. © 2007 TechTools QuickWriter MCU Programmer 17 During an "Auto Run" programming cycle, QuickWriter always verifies all sections of the MCU before programming the Fuses. Programming the fuses last allows QuickWriter to perform a full verification of all areas of the MCU regardless of the fuse settings. Shortcuts Alt+E, W 2.3.3 Using Gang Adapters Overview When using Gang adapters, each device is programmed and verified independently, but at the same time. Because of this, QuickWriter is able to save time while also tracking individual errors that may occur for each device being programmed. Gang adapters are available for all serially programmed devices that are supported by QuickWriter. Multiple devices can be programmed at once without costing additional time except for the minor delay while Serializing. Details After connecting a gang adapter, you will want to enable multiple device support by selecting multiple sockets in the QuickWriter software. The Socket LED Indicators (shown above), will change states when "clicked" as shown below. Socket B disabled. Socket A enabled This can be done manually by toggling the button beneath each Socket LED Indicator or by using the Main Menu: "Options - Programming Sockets - Gang" , which will select all 4 sockets. Shortcuts Alt+O, P, G 2.3.4 Using Serial Numbers Overview QuickWriter programs serial numbers in Little Endian format. Any unused locations specified for serial numbering will be set to '00'. Therefore, the HEX serial number "FFFE" programmed into 8 locations of EE Data will be stored as "FE FF 00 00 00 00 00 00". If auto increment is selected, the next four incremented serial numbers will be stored as: "FF "00 "01 "02 © 2007 TechTools FF 00 00 00 00 01 01 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00" 00" 00" 00" (FFFFh or 65535) (10000h or 65536) (10001h or 65537) (10002h or 65538) 18 PicTools Manual 3.0 Stored Format in EE DATA: The serial number 62449988134764293 ( DDDDEEEEFFFF05h ) will be stored as: "05 FF FF EE EE DD DD 00" Stored Format in CODE memory: The serial number 62449988134764293 ( DDDDEEEEFFFF05h ) will be stored as: "0005 00FF 00FF 00EE 00EE 00DD 00DD 0000" Stored Format in Code memory as RETLW in a PIC16F873: The serial number 62449988134764293 ( DDDDEEEEFFFF05h ) will be stored as: "3405 34FF 34FF 34EE 34EE 34DD 34DD 3400" Details To enable Serialization, select the "Serial Numbers" section of the "Options" window, then select the "Enable Serial Numbering" option (see: Setting Serial Number Options 10 ): The last step is to set the beginning serial number and whether to have QuickWriter "Auto increment" before programming each device. Auto Increment - When selected, this option reads and stores the serial number indicated in the " LAST HEX" field as the last serial number used. The incremented value of this number will be programmed in the next device. The number used for each device will be displayed in HEX and Decimal beside the socket identifier and the results displayed on the right. The results field will indicate one of the following: Manual - Serial numbering preferences have changed to Manual mode. Auto - Serial numbering preferences have changed to Auto Mode. Skipped - An earlier error has dictated skipping serialization for this socket. The serial number is not incremented for skipped sockets. © 2007 TechTools QuickWriter MCU Programmer 19 Passed - Serialization was successful for this socket. Failed - An error occurred while serializing this socket. When a device fails to properly serialize, its serial number is not used for the next device. Manual Serial Numbers - Serial numbers can be entered manually for each device by unselecting the "Auto" check box and editing the HEX or Decimal field beside each socket identifier. The "Last HEX" and "Last Decimal" fields will reflect the last value used to serialize a device. Shortcuts Alt+E, S - Opens the Serial Number Editor (shown above). Alt+O, N - Opens the Serial Number Options. Alt+R, S - performs a "Serialize Only" programming task. 2.3.5 Reading the MCU Contents Overview Sometimes it may be desirable to "reproduce" an MCU that has already been programmed or to visually verify the contents. To do this, you will need to read the contents of the MCU instead of opening a HEX file. © 2007 TechTools 20 PicTools Manual 3.0 Details To read the contents of an MCU, choose "Run - Auto Read Only" from the main menu (or Ctl+R). If multiple sockets have been selected, a pop-up menu will appear for you to select the socket you wish to read from. After selecting the socket, the entire contents of the MCU (including I.D. locations and Configuration Word) will be loaded into the QuickWriter software. Unless you intend to make exact duplicates of the MCU just read, remember to re-open the HEX file before programming another device. (see also: Setting General Options 7 ; and Setting Options for Production Personnel 14 ) Shortcuts Ctl+R Alt+R, R 2.4 Advanced Advanced · · · · · · 2.4.1 In-Circuit Programming 20 ICP with Self Powered Targets Cable Connector 23 Command-line Operation 23 Exit Codes 24 Legend - Programming Tasks 21 25 In-Circuit Programming Overview QuickWriter can be used with single socket and gang programming adapters, but one of its key features is the ability to program devices already incorporated in a working circuit. To program devices in-circuit, a few requirements must be met by the target. For a detailed discussion on the key issues related to in-circuit programming, see the In-Circuit Programming Guide installed with the QuickWriter software. NOTE: ICP does not support parallel programmed devices (i.e. PIC16C55, PIC16C57, etc.). Details When using the ICP cable (provided with QuickWriter), always select Socket A. If additional sockets are selected or if socket A is not selected, programming errors will occur. If any error messages appear during ICP, pay special attention to any messages relating to voltage errors. QuickWriter performs extensive voltage testing to help prevent damage to itself and your target. All suggestions presented in the error dialog should be checked thoroughly before another programming attempt is made. Target Design Recommendations Use a 10K Ohm or larger pull up on MCLR Use 10uF or less capacitance on MCLR (most targets use none). © 2007 TechTools QuickWriter MCU Programmer 21 Avoid or isolate any other circuitry that touches the MCLR line. Ideally, use RB6 (clock), RB7(data) and RB3 (LVP/PGM pin, RB4 or RB5 on some PICmicros) as OUTPUTs in your circuit design OR connect them to outside-world connections or NO switches so that nothing is driving them during programming. This avoids any need for isolation. If that is not desirable, design to isolate or tri-state anything that drives these lines. Always connect the ground pin. Decide who powers the target and address the trade-offs involved. (see: ICP with Self Powered Targets 21 ) When programming, enable the PICmicro MCU's power-up timer Fuse Option if possible. Particularly if setting the device for internal MCLR or internal OSC. In-Circuit Programming Cable Pinout PIN Number | Signal Name | KEY --------------------------------------------1. VPP (MCLR) RED 2. VDD (+5) White 3. GND ( - ) White 4. RB7 (data) White 5. RB6 (clock) White 6. NC Pin Block 7. LVP (RB3/RB4/RB5) ** White ** Only necessary for some FLASH devices. Holds LVP/PGM low to disable Low Voltage Programming. (connect to RB3 on 16F87X devices, RB4 on PIC16F62X and RB5 on 18 series MCUs if needed). Shortcuts None 2.4.2 ICP with Self Powered Targets Overview QuickWriter can supply up to 100 ma of current on the VDD signal (5 volts) when programming MCUs in-circuit. This includes the current required by the MCU during programming (20 to 50 ma). When programming MCUs in-circuit, it is sometimes desirable or even necessary for the circuit to supply its own power. If the target circuit has larger current requirements or if it is not feasible to power the circuit from the 5 volt power trace (i.e. when this will apply 5 volts to the output of a voltage regulator), then you should choose QuickWriter's "Monitor a Self Powered Target" option. © 2007 TechTools 22 PicTools Manual 3.0 When the circuit supplies its own power, we have to be concerned with voltage sequence and timing requirements of the MCU. The programming algorithms for some devices require that the device's VDD be enabled/disabled several times during a programming cycle. In self-powered target boards, this requires that we ask the operator to do the power cycling for us. This can become tedious for the operator. Even with devices that only require a single power up and down, it would still be nice to free the operator from this burden. To enable full automation of in-circuit programming, without violating programming specs, QuickWriter provides a control signal called TVDDEN. Details When using the "Self Powered Target" option, QuickWriter provides two ways of determining when to activate your target circuits power supply. 1. Operator Notification for manual activation/deactivation. 2. Hardware Control Signal (TVDDEN) for electronic activation/deactivation (automation). Operator Notification When QuickWriter is ready for the target's power supply to be turned on or off, it will display a notification dialog that includes the current voltage reading. Once the required voltage condition is met, this dialog will automatically close and QuickWriter will continue operation. If for some reason the voltage condition can not be met, the operator can use the ABORT button to close the dialog. Using the abort button will cause QuickWriter to discontinue the operation and display a relevant error message. Hardware Control Signal (TVDDEN) TVDDEN can be used to control your target's power supply (through an appropriate driver circuit). QuickWriter's TVDDEN signal will help automate control of the target's power and make it possible to meet the required timing for power sequence specifications. TVDDEN is a new signal, available on QuickWriter's 26 pin interface connector. It is not available in the standard ICSP cable included with the unit. You may need to customize your in© 2007 TechTools QuickWriter MCU Programmer 23 circuit cable to make use of the new signal (and add your power control circuitry). (see: Cable Connector 23 ) TVDDEN is an active high, logic level (+-20ma) signal. Typically, one would use it to drive a current limited LED within a solid-state relay to control your target's power supply. 2.4.3 Cable Connector Overview QuickWriter's programming cable connector is compatible with existing PICwriter and Parallax PIC16CXX-PGM programmer adapters while also providing Gang programming with TechTools Gang programming adapters and In-Circuit Programming with the included ICP Cable. A newer signal, TVDDEN is also provided on this connector for automated control of the Target Circuit's power supply (see: ICP with Self Powered Targets 21 ). 2.4.4 Command-line Operation Overview Sometimes it is convenient to create a shortcut that will launch the QuickWriter software with a specific HEX file and device type, then have it program and close automatically. This can be accomplished from a BAT file or a Window's Shortcut using QuickWriter's command-line options. Details Usage - QW.exe Filename [/Ddevicename] [/A] [/X] Filename = [optional] - Any valid filename including drive and path. If omitted, the last file used is opened. A Control File can also be specified (hexfilename.QWC), in which case QuickWriter will open the associated filename stored in the Control File. /D = Device [optional - only valid if filename specified] - requires a valid, supported MCU number such as '18F2620'. /A = AutoRun [optional - only valid if filename specified] - instructs the software to "Auto Run" and close if no errors occurred. © 2007 TechTools 24 PicTools Manual 3.0 /X = Close with Exit Code [optional - only valid if filename and /A specified] - instructs the software to inhibit all non-critical notification dialogs during "Auto Run" and close when finished. The program will exit with an appropriate Error Code if an error occurred. Example 1 - QW myhexfile.obj /D12CE673 /A The above example will launch QuickWriter, load the hex file "myhexfile.obj" from the same directory as the QuickWriter software, retrieve all option settings from "myhexfile.qwc" (if it exists), set the MCU to a 12CE673 then "Auto Run" and close. If any errors occur, the program will remain open for you to view the results. After viewing the error, you will need to manually close the program (Alt+X, or "File - Exit" ). Example 2 - QW C:\myprojects\Blinkleds\myhexfile.obj The above example will launch QuickWriter, load the hex file "myhexfile.obj" from the "C: \myprojects\Blinkleds\" directory and retrieve all option settings from "myhexfile.qwc" (if it exists). The MCU information will be set from the Control file if that option is specified in the control file. If the control file did not specify an MCU override, then the MCU is extracted from the hex file if a device record is present, else the last selected MCU will be used. Shortcuts None 2.4.5 Exit Codes Overview When the QuickWriter program terminates, an exit code is returned. This is normally ignored by the system but can be a great benefit when programatically launching the QuickWriter program from custom software (such as using the Window's API "ShellExecute" function). The exit codes can be used by the lauching program to make intelligent decisions. Details QuickWriter's Exit Codes are returned as a 2 byte bitmask, with each bit position representing a particular error code. A return value of 0 (zero) indicates no errors occurred. Low byte of error codes EF_port EF_timeout EF_RX EF_failed EF_badfw EF_HIGHBAUD EF_abort EF_unknown = = = = = = = = $1; $2; $4; $8; $10; $20; $40; $80; { { { { { { { { 'Error communicating with Port' 'Communication Timeout, Hardware not responding' 'Communication Error Detected, BAD data received' 'Current Programming Task Failed' 'Firmware update Required' 'Higher Transfer Speed Failed' 'User Aborted Task in progress.' 'Unknown Error has Occurred.' } } } } } } } } High byte of error codes EF_VDDLV EF_VDDHV EF_VDDTIME EF_VPPLV EF_VPPHV EF_VPPTIME EF_VDD5 = = = = = = = $100; $200; $400; $800; $1000; $2000; $4000; { { { { { { { 'VDD Voltage TOO LOW (+5)' 'VDD Voltage TOO HIGH' 'VDD not rising' 'MCLR Voltage TOO LOW' 'MCLR Voltage TOO HIGH' 'MCLR not rising' 'Voltage detected on VDD' } } } } } } } © 2007 TechTools QuickWriter MCU Programmer EF_VPPNZ 2.4.6 = $8000; { 'Can not pull MCLR low' 25 } Legend - Programming Tasks Parent Node Select a parent node to perform the tasks listed beneath it. Some parent tasks will also perform a related sub task from another parent node (i.e. Program will also perform a Program/Verify of the Fuses node). - Child nodes are collapsed. - Child nodes are expanded. . - An error has occurred in at least one child task. - This node has been disabled in Option Settings and will be skipped. - This node is not available for the selected MCU and will be skipped. Child Nodes A Child node can be selected to perform a single task. - Normal, available child task. - Node is selected and preparing to perform its task or the task was canceled. - An error occurred for at least one socket while performing this task. - This task was completed successfully. - This task has been disabled in Option Settings and will be skipped. - This task is not available for the selected MCU and will be skipped. © 2007 TechTools TechTools Design Environment Part III TechTools Design Environment 3 27 TechTools Design Environment This portion describes the various feature s of TechTool’s TDE software. The first section is a brief step-by-step over-view, while the next section includes detailed descriptions of TDE's features. The following TDE topics are covered : Sample Project 27 TDE Details 44 Project and File Operations 45 Compiling and Executing Code Using TDE's Windows 80 Data Breakpoints 118 3.1 68 Sample Project If you already have emulator experience, then you may wish to skip to the next section, ( TDE Details 44 ) which explains features in more detail. Otherwise, the following project should help you to become familiar with the basic functions of the emulator and its software. The following pages describe a simple project that uses the most common features of ClearView Mathias and its TDE software. The project shows how to accomplish the following things : · · · · · · · · · · · · Starting TDE 28 Open a project 28 Load a source file 29 Select ClearView type, serial port, and serial baud rate 31 Select PIC type, clock frequency, watchdog status, etc 32 . Compile and download code 34 Execute code in single-step mode 35 Execute code in animate mode 36 Watch variables during execution 36 Watch special registers during execution 38 Reset the emulator 41 Set breakpoints 41 The tutorial is based upon the PIC16C554. Because this project is meant as a quick introduction, some details have been left out. For instance, there is no mention of changing register values. Much more detail is included in the text that follows this project. It’s assumed that you have successfully installed the Mathias hardware and software, as described in the previous sections of this chapter. If not, please review the installation sections before trying this project. © 2007 TechTools 28 3.1.1 PicTools Manual 3.0 Starting TDE Step 1: Start the TDE software. You should be able to select TDE from the Windows taskbar. 3.1.2 Opening The Project Step 2: Select Open from TDE’s Project menu, or click the equivalent button as shown above. © 2007 TechTools TechTools Design Environment 29 A "project" is a control file tha t stores all the information needed to integrate your work with the emulator. For example, the project file will store a reference to your source files (assembly language or C source files, for instance), and other useful setup and environment informat ion, such as Compiler options, emulator type, oscillator speed, editor settings, window positions, etc. When you close a project or exit from TDE, all of these settings are saved in a separate file with the ".tpr" extension. 3.1.3 Loading a Source File Step 3: Select the file "tutorial.tpr" from the newly-created TDE directory on your hard drive, then click OK. Since this is an existing proj ect, the source file "tutorial.src" has already been associated and the "Project Tool" option has been set to "CVASM16". ( For a detailed example of creating a new project and selecting project options, see the section "Project and File Operations" late r in this chapter. ) Now highlight the source file for this project and click the Open button. © 2007 TechTools 30 PicTools Manual 3.0 After Step 3, you should see the fo llowing screen. The tutorial program appears in the text editor window. © 2007 TechTools TechTools Design Environment 3.1.4 Hardware Settings, Project Info Step 4: Select Project from the Setup menu. Step 5: Select the serial com port that the emulator is connected to, as well as the baud rate for communication with the PC. © 2007 TechTools 31 32 PicTools Manual 3.0 ( Note: If the Emulator "Mode" is set to "Mathias", the software will attempt to find an emulator on the specified port when this dialog is closed. If an emulator is found, TDE will show the message "Status: Ready"; otherwise, it will indicate that no emulator was found.) 5X Note: Stack Viewing and the "Break on Stack Overflow/Underflow" options are not available on 5X devices. 3.1.5 Device Settings, Building the Project Step 6: Under the Device heading, select the following settings: Device: 16C554 Frequency : 20 MHz. © 2007 TechTools TechTools Design Environment The device types available (16C71, 16C74,...) depend upon the PIC family and PIC member modules in use on the emulator. Before this window is shown, TDE checks the emulator hardware to see what options are available. All available devices will be marked with an "*". If you do not have the necessary modules for 16C554 emulation or if you are not in Virtual Mathias mode, then you will not see the asterisk beside the device type. This project does not use the optional trace buffer, so there i s no need to adjust any settings under the fourth heading (Trace). Now click the OK button to close this dialog. Step 7: Select Build from the Project menu, or click the equivalent button. F4 © 2007 TechTools 33 34 3.1.6 PicTools Manual 3.0 Running the Code, Stopping Execution If the build function worked properly, you should see the status bar as above. Note the status "Project Build Complete." Step 8: Select Go from the Run menu, or click the equivalent button. F5 © 2007 TechTools TechTools Design Environment This causes the emulator to run your assembled program. If all goes well, the status bar should display several quick messages, such as "downloading code" and "resetting emulator." The final status message should be "Running..." Selecting Go is the only way to make the emulator ru n at full hardware speeds (20 MHz, etc). During full-speed execution, the screen is not updated. To watch changes during execution, you must select single-step or animate, which are slower modes of execution. Single-step and animate are shown in the foll owing pages. Step 9: Let the emulator run for several seconds, and then click the stop button. F6 After you click the Stop button, you should see something like the screen below. The highlighted line (green) indicates where program execution stopped. The status line (which is in the toolbar, but not shown here) will indicate the current address, such as "User Halted at 000Dh". 3.1.7 Single-Stepping Step 10: Select Single Step from the Run menu, or click the equivalent button. © 2007 TechTools 35 36 PicTools Manual 3.0 F8 This causes the emulator to execute one instruction in your program, and then stop. As each instruction is executed, you can watch variables and registers, as well as your target circuit. This ability makes it easier to find the exact instruction that may be causing an error. Try single-stepping several times. The green highlighted line should advance each time you step through the code. 3.1.8 Animation, Watching Variable Values Step 11: Select Animate from the Run menu, or click the equivalent button. F9 © 2007 TechTools TechTools Design Environment This causes the emulator to execute one instruction (much like single-stepping), but execution does not stop after one. The screen is updated after each instruction, so you can see the status of variables, registers, etc. as your program runs. Step 12: After a few seconds, click the Stop button to stop execution of the program. F6 Step 13: Add a Variable to the Watch Window When you stopped execution, the program probably stopped on a line where you can see the variable called Value. Let’s add this variable to the watch list, so you can watch its value as the program runs. Start by highlighting the variable’s name in the source code window. © 2007 TechTools 37 38 PicTools Manual 3.0 Watch Now Right-Click in the editor and choose "Add Watch Selected". This will add the highlighted variable to the current watch group displayed in the Watch List. To open the Watch List use the Open Watch button or select "Watch List" from the VIEW menu. 3.1.9 Watching Variables, Viewing Special Registers Step 14: Now select the Watch List option from the View menu. © 2007 TechTools TechTools Design Environment A small Watch window should appear. This window shows the values of all variables that have been selected for "watching." At this time, only one variable (Value) should appear in the window. Step 15: Select Special Registers from the View menu. This opens the Symbols Window which displays the Special Registers, user variables and etc. The Special Registers portion displays the contents of the PIC’s special register memory (status, fsr, option, etc). Step 16: Select Animate from the Run menu, or click the equivalent button. F9 © 2007 TechTools 39 40 PicTools Manual 3.0 3.1.10 Watching the Program Run The screen should look something like this. The green highlighted line should be stepping through the program, and the two new windows (Watch & Special Registers) should be updated and values highlighted as they change. © 2007 TechTools TechTools Design Environment Step 17: After a few seconds, click the Stop button to stop execution of the program. F6 3.1.11 Resetting the Emulator, Setting Breakpoints Step 18: Select Reset from the Run menu, or click the equivalent button. F10 © 2007 TechTools 41 42 PicTools Manual 3.0 This causes the emulator to reset the PIC’s Program Counter (PC). The reset value of the Program Counter may vary with different PICs. In the case of the 16C74, the reset value is 000h, so program execution will st art at 000h whenever a reset occurs. After you select Reset, the green highlighted line should move to the beginning of the program. Step 19: Scroll to the last line in the program, and then double-click to the left of the line. This sets a breakpoint on the last line. If the emulator enc ounters a breakpoint while running a program, it will stop execution, update any information on the screen and highlight any changed values (variables, registers, etc). Note that lines with breakpoints are highlighted in red. If the "current execution line" (green) lands on a breakpoint line, the resulting color will be blue (green + red = blue). © 2007 TechTools TechTools Design Environment To disable a breakpoint, just double-click in the left column again. 3.1.12 Finishing the Project Step 20: Select Animate from the Run menu, or click the equivalent button. F9 © 2007 TechTools 43 44 PicTools Manual 3.0 The emulator should step through each line of the program, stopping on the last line (normally, it would loop back to the start of the program). Because the last line is the current execution line and a breakpoint line, it should be highlighted in blue. Step 21: At this point, the sample project is done. If you want to take a coffee break, select Exit from the File menu. All project info will be saved automatically. 3.2 TDE Details The following pages describe the various features of ClearView’s TDE software. Unlike the previous pages, this section includes a detailed description of each software function. The following topics are covered : Project and File Operations · · · · · · · · · · 45 Creating a Single-file Project Creating a Multiple-file Project 50 Adding Files 51 Mode of Operation 55 Watch Dog Timer 57 Breaking on Stack Over/Underflow Device Settings 59 Trace buffer settings 60 Environment Settings 62 Resetting the emulator 66 46 57 © 2007 TechTools TechTools Design Environment · Printing 67 Compiling and Executing Code · · · · · · · · · 68 Building the project Executing code at full speed 70 Halting execution 71 Single-step , step-over and step-out execution 71 Animation-mode and "Animate Over" execution 74 Showing the execution point 75 Resetting the emulated PIC 76 Setting the program counter (execution point 77 ) Using breakpoints 78 68 Using TDE's Windows · · · · · · · · 45 Window basics Text editor window 82 Build Log Window 93 Code window 95 Special registers window File registers window 105 Watch list window 108 Trace buffer window 116 80 80 97 Data Breakpoints 118 · · · · · 3.2.1 Enable and Break On options File Register options 120 Match On options 121 Include Constants option 123 Breaking on Data 124 120 Project and File Operations The following sections explain how to create single and multi-file projects, how to work with various file formats, and how to select device and emulator settings. · · · · · · · · · · · Creating a Single-file Project 46 Creating a Multiple-file Project 50 Adding Files 51 Mode of Operation 55 Watch Dog Timer 57 Breaking on Stack Over/Underflow Device Settings 59 Trace buffer settings 60 Environment Settings 62 Resetting the emulator 66 Printing 67 57 All compile or debug sessions in TDE require a project name. This next section explains how to create a single-file project using the included TechTools © 2007 TechTools 46 PicTools Manual 3.0 PICmicro Assembler ( CVASM16 ). As mentioned in the sample project section, a "project" is a control file that stores all the information needed to integrate your work with the emulator. In addition to source code, the project file contains setup and environment information. When you close a project or exit from TDE, these extra settings are saved in a separate file with the ".tpr" extension. When you later open an existing project, TDE loads these settings, so you don’t have to re-establish the emulator type, oscillator speed, editor settings, etc. 3.2.1.1 Creating a Single-file Project To create a new project, select New Project from the Project menu. TDE will open the Project file dialog. Here you can type a new project name. For this example we will use the name " Newprog1". If the file does not exist, TDE will ask if it is ok to create this new project filename. After you click "OK", a dialog will appear like the one below. © 2007 TechTools TechTools Design Environment The highlighted item "Project", is the main Node in your project file. You can now select the tool you would like to use for your project by clicking on the Tool drop-down list under Node Build Settings.This tool selection lets TDE know how to handle the build process. © 2007 TechTools 47 48 PicTools Manual 3.0 As shown above, you can select your favorite compiler or specify a particular file type such as a COD file. 3.2.1.1.1 Adding a File Project => Setup => Now that we have selected CVASM16 as the tool for our Project Node, lets add a file. Click on the ADD button and a dialog will appear similar to the one shown below. Here you can select an existing file, or just type a new filename and TDE will create the file for you. © 2007 TechTools TechTools Design Environment After selecting a file, your Project Dialog should resemble the graphic below. Now we can choose the appropriate tool for the selected file. Since we have chosen CVASM16 as our Project Node Tool, we will select NONE as the File Node Tool. This will pass the file to the Project Tool for processing. © 2007 TechTools 49 50 PicTools Manual 3.0 At this time you can either double-click on the File Node or select the Open button to open the file into TDE's editor window. 3.2.1.2 Creating a Multiple-file Project To create a multi-file project, select New from the Project menu. TDE will open the Project file dialog. Here you can type a new project name. For this example we will use the name " BCtest". TDE will verify that the name does not al ready exist in the selected directory. After you click "OK", a dialog will appear like the one below. For this example we will select By tecraft Linker as our Project tool. © 2007 TechTools TechTools Design Environment 51 The highlighted item Project is the main Node in your project fi le. You can now select the tool you would like to use for your project by clicking on the Tool drop-down list under Node Build Settings. This tool selection lets TDE know how to handle the build process. 3.2.1.2.1 Adding Files Setup => Project => Now that we have selected Bytecraft Linker as the tool for our Project Node, let's add a couple of files. Click on the ADD button and a dialog will appear similar to the one shown here. We have selected an existing file, but you can just type a new filename and TDE will create the file for you. Multiple files could also be selected by using the ctrl or shift keys. © 2007 TechTools 52 PicTools Manual 3.0 After selecting a file, your Project Dialog should resemble the graphic below. Now we can choose the appropriate tool for each file added to the project. Since we have chosen Bytecraft Linker as our Project Node Tool, AND added a 'C' source file, we will select Bytecraft C to OBJ as the File Node Tool. © 2007 TechTools TechTools Design Environment 53 At this time you can either double-click on the highlighted File Node or select the Open button to open the file into TDE's editor window. NOTE: The first file added to the project will be the last file processed during build operations. Likewise, the last file added to the project will be the first file processed. After selecting OK, the Project Dialog will close and your Edit window should resemble the graphic below. © 2007 TechTools 54 PicTools Manual 3.0 Now we need to create a "Link" file for the Bytecraft Linker. Since the Link file is simply a text file, we can create it using the TDE editor. Choose the New option from the File menu. This will popup a File Open Dialog. From here a new filen ame can be specified and TDE will create an empty text file and open it in the Editor window. You will want to reference the Bytecraft Linker documentation for complete information regarding the requirements of the link file, however an exam ple is shown below. © 2007 TechTools TechTools Design Environment You can now edit, compile and debug your project. NOTE: There is one restriction when using a link file with TDE: Link files must have the extension of ".LNK". 3.2.1.3 Mode of Operation Setup => Project => Before closing the Project Setup Window, you will want to verify a few o ther project options (These options can always be changed at a later time by selecting the Project option from the Setup menu in TDE). © 2007 TechTools 55 56 PicTools Manual 3.0 First, select the Emulator tab. Now you can select the serial com port the emulator is connected to, as well as the baud rate for communication with the PC. Mode of Operation Mathias: Full Emulation mode with Mathias attached. Virtual Mathias: This allows you to start experiencing all of TDE and Mathias's features - even if you do not have a Mathias connected. © 2007 TechTools TechTools Design Environment 57 Off Line: Editing and compiling mode. Even if you have not designed your target yet, you can sti ll choose Mathias Mode and begin your development ( Note: If the Emulator Mode is set to Mathias, the software will attempt to find an emulator on the specified port when this dialog is closed. If an emulator is found, TDE will show the message "Status: Ready"; otherwise, it will indicate that no emulator was found.) If you do not have a Mathias connected, you can work in offline mode or use Virtual Mathias mode to start experiencing all of TDE and Mathias's features. 3.2.1.4 Watch Dog Timer Setup => Project => We recommend that you disable the WDT until the rest of your code is debug ged. When it is time to add the code necessary to keep the Watch Dog Timer satisfied ( or to "kick the dog" ), you will find the 'Break on Timeout' feature very time saving. This feature stops the program execution whenever the Watch Dog times out, al lowing you to evaluate the portion of code that needs to clear the WDT. Disabled: Turns the Watch Dog Timer OFF. Reset on Timeout: Allows the Watch Dog Timer to reset the PIC whenever a timeout occurs. Break on Timeout:* This new feature will halt program execution and display the current program line in the Editor window whenever a timeout occurs. (Always RESET the program after a Break on Timeout). * Break on Stack Over/Underflow, and WDT Break on Timeout are not available on 12bit or 16C5X devices 3.2.1.5 Break on Stack Over/Underflow Setup => Project => © 2007 TechTools 58 PicTools Manual 3.0 If enabled, this feature will halt program execution anytime the stack is "pushed" beyond its capacity or "popped" too many times. The first line in the stack window keeps tra ck of the stack depth. When the stack is full, this line turns yellow. If an additional CALL is executed, this line turns RED, the program is halted and you receive the message "Stack OverFlow". If too many RETURNs are executed, the message will read "Stack UnderFlow", and the stack window may show new return addresses. These new addresses actually exist in the stack and are left-over from previous CALLs. When the stack is "empty" and a RET is executed, the stack pointer moves from the top of the stack to the bottom of the stack. So the underflow actually copies whatever value is located at the bottom of the stack into the program counter; which could be garbage or a real address from a previous stack operation. The items listed in the Stack Window beneath the Depth line are the RETURN ADDRESSES that have been pushed onto the stack. This will help you track down the cause of a stack overflow. However, if further analysis is required on a stack underflow, a Trace Buffer Module 116 is required ( part #CVMT2 ). This will give you an execution history, making it possible to back-track the code flow. Note: Stack Viewing is only available with 14bit device emulation and Mathias firmware Version 2.1 or higher and Break on Stack Over/Underflow is not available on 12bit or 16C5X devices. © 2007 TechTools TechTools Design Environment 3.2.1.6 59 Device Settings Setup => Project => Next, select the Device tab. Here you can select the actual PIC device and oscillator frequency you wish to emulate. Device Type The device pulldown lists all available device types supported by the Mathias hardware. The items marked with an asterisk (*) are the devices supported by your current Module combination. If you have changed your com port settings, and the TDE software has not communicated with the Mathias yet, you may not see any marked devices. In this case, just select the proper device that you wish to emulate and proceed with the rest of your settings. Frequency The Mathias hardware is capable of operating at any frequency from 32 KHz to 25 MHz, with certain limitations. Certain "Bondout" combinations may be limited to 20 or even 10 MHz. © 2007 TechTools 60 PicTools Manual 3.0 Bondouts and Speed Limitations Bondouts are specially manufactured forms of the PIC production silicon that make it possible to access internal control signals. These bondout chips are installed in the Mathias Family and Member modules, making it possible to accurately emulate the production PIC. Microchip Technology Incorporated produces these bondouts and specifies their speed ratings. This speed rating sets the maximum frequency at which the production PIC can be emulated. Currently all 12bit or 16C5x devices can be emulated at a full 20Mhz; the maximum production rating. However, depending on which 14bit Family Module you have installed, you may be limited to an emulation speed of 10Mhz on 16Cxx devices. Our original 14bit Family Module ( part # CVMXXF ) contained Microchip bondout part #16C02-ME/L, which is limited to 10 MHz operation. If you require the ability to emulate a 20Mhz PIC, the newer 25Mhz PICs or would like the new feature of Data Breakpoints, we now offer an Advanced Family Module for 14bit devices: part #CVM03F. 3.2.1.7 Trace Buffer Setup => Project => If you have a Trace Buffer Module ( part #CVMT2 ), select the Trace tab. © 2007 TechTools TechTools Design Environment Note: The functions shown here are only available if the trace buffer module is installed. Execution History: If this is enabled, TDE keeps a record of each instruction executed. This record is stored in memory on the optional trace buffer module. For each instruction, the record shows the location in the trace buffer, the value of the program counter, the state of external trace inputs, and the original line of source code. External Break: If this is enabled, the emulator will halt execution if the external Break input goes low. External Inputs: There are eight external trace inputs, shown at the end of the hardware installation section. © 2007 TechTools 61 62 PicTools Manual 3.0 Trace Size: To prevent extra delays when execution is halted, we have added a selectable Trace Size option. Many of our customers requested the ability to view only the most recent trace information when a breakpoint was encountered, but wanted to keep the full trace ability for more "in depth" analysis when needed. As a result, you can now set the Trace Size as small as 1K or as large as 16K with several sizes in between. You can now click the OK button and TDE will save these settings. The Trace Size option is only available with Mathias firmware Version 2.1 or higher. To determine the firmware version of your Mathias hardware, select the About option from the Help menu. When the About dialog is activated, TDE will retrieve the hardware version information from Mathias and display it at the bottom of the window. 3.2.1.8 Environment Preferences Environment Preferences can be mod ified by selecting the Environment option from the Setup menu in TDE. This option allows you to set general features that affect all editing/debugging sessions. Environment Option Groups · Editor 63 · General 64 · Build 65 · Debug 65 © 2007 TechTools TechTools Design Environment · Programmer_Preferences 66 3.2.1.8.1 Editor Preferences Font Options Clicking the Select button will open a Font options dialog. A list of available Fixed Width Fonts will be displayed on the left. You can select any of these fonts and other options to customize how your code is printed and displayed. Tab Width Choose the number of spaces to skip when the Tab key is pressed in the Editor window. Auto Indent When this option is enabled, a carriage-return will automatically space over the beginning of the next line to match the one above it. Auto Backup TDE will automatically create a backup copy of modified files and use the extension '.bak', before saving changes made from the editor window. © 2007 TechTools 63 64 PicTools Manual 3.0 Tab Style USE TAB - A TAB character is inserted in the editor when the Tab Key is pressed. USE Spaces - Space characters are inserted in the editor when the Tab Key is pressed. Smart Spaces - Space characters are inserted in the editor when the Tab Key is pressed. However, the Tab position is determined by th e text position in the previous line, providing "smart" tab positions that line up with existing text columns. Current Line Position This option chooses the positio ning of the current source line in relationship to the borders of the Debugging window. When single stepping, animating or halting program execution; TDE will use this setting to show the current execution line. 3.2.1.8.2 General preferences Show Hints This option toggles the extra 'fly-out' hints that appear when the mouse pauses over an item in TDE. Retain Z Order Retaining the Z order will force the active windows in TDE to reappear in the same 'front to back' order when TDE is opened, the program is reset or when a halt is encountered. Randomize File Registers TDE automatically sets all Special Registe r values to their default power-up or reset state. When the Randomize option is selected, TDE will randomize the General Purpose registers on a power-up or manual reset. This insures true PIC emulation and helps expose any hidden dependencies on previous register values. Auto Load last Project If this option is enabled, TDE will automatically load the project that was active the last time TDE was closed. Beep on Errors Whenever an error is encountered by TDE, the PC speaker will emit a short beep. Beep on Stop © 2007 TechTools TechTools Design Environment Whenever program execution is halted, the PC speaker will emit a short beep. Animation Step Delay During single-stepping and animating, it may be desirable to slow down the execution speed in order to view the changes taking place, without having to halt the program. This option gives you a sliding scale to set the minimum delay from 100 msec to 999 msec. Note: Delays can be longer than this setting, depending on the speed of the computer running the TDE software. However, this option doe s set the minimum delay, preventing these modes from running faster; even if other, heavily updated windows are closed. 3.2.1.8.3 Build Preferences Always Build All When selected, ALL project files will be built whenever any of the Editor files have been updated. When NOT selected, only modified files will be re-built. Verbose Build log When selected, additional information will display in the build log during the build process, providing a detailed view of events. Log Warnings When selected, warning messages will be included in the Build Log. Abort After Build will abort if the number of warnings or error messages exceed the numbers specified here. 3.2.1.8.4 Debug Preferences Run To MAIN on reset When Selected, Mathias will execute all code from the reset vector of the Emulated PICmicro MCU at Full speed until a "MAIN" function or Label is encountered. If NOT selected, Mathias will halt at the reset vector. Halt ONLY on Source Lines If Selected, Mathias will continue to run on a halt request until a source line reference is found for the code being executed. If NOT selected, Mathias will halt immediately when requeste d. Step OUT of unknown code When selected, any STEP operation will run full speed through compiled code that does not have a source line reference. © 2007 TechTools 65 66 PicTools Manual 3.0 Step OVER calls to unknown code When selected, any STEP operation will run full speed through calls that do not have a source line reference (effectively performing a STEP OVER when stepping). Show File Register Mirrors When selected, the General Purpose Register window (file registers), will display memory locations that are mirrored with other locations in ano ther bank. This also means that multiple locations can change when the data in a "mirrored" location changes . When NOT selected, mirrored locations will not be displayed. Debugging with Stale Source Code Ask Me What to Do - If the source code has been modified, TDE will ask whether to rebuild the source before continuing or continue without rebuilding (stale debugging information). Build and restart debugging - If the source code has been modified, TDE will rebuild the source and reset the microcontroller before continuing. (fresh debugging information). Continue Debugging with stale data - If the source code has been modified, TDE will continue without rebuilding or resetting the microcontroller (stale debugging information). 3.2.1.8.5 Programming Preferences Enable Program Button This option Enables or Disables the QuickWriter programming button on TDE's main Application bar, next to the Status area. Make before Launch When Selected, the current project will be rebuilt before passing the resulting HEX file to the QuickWriter application. Auto Program and Close When launched, the QuickWriter software will automat ically program and close. If an error occurred while programming, the application will stay open so that all error information can be seen. 3.2.1.9 Resetting the Emulator Sometimes, it may be necessary to reset the emulator hardware. For instanc e, there may be a communications error between the PC and the emulator, which will require a reset. To reset the emulator, select Reset Mathias from the File menu. © 2007 TechTools TechTools Design Environment Please note that this is much different from the Reset 76 option found in the Run menu. The reset described here resets all of the emulato r hardware, much like turning the emulator off and on. The reset option in the Run menu just resets the emulated PIC. If you want to simulate a PIC reset cycle, the proper reset to use is the one in the Run menu. 3.2.1.10 Printing At times, it may be helpful to print a copy of your work. TDE allows you to print from two windows: the editor and the trace buffer. To print from either window, just click on the window and then select Print from the File menu. TDE will display the Print dialog box: © 2007 TechTools 67 68 PicTools Manual 3.0 From this dialog box, you can choose what you want to print, how man y copies to print, etc. If everything is correct, click OK to start printing. If you need to change settings that aren’t shown, click the Setup button. The Print Setup dialog box will appear, which allows you to select different printers, paper sizes, etc. 3.2.2 Compiling and Executing Code The following sections explain how to assemble or compile source code, and then execute that code in the emulator. · · · · · · · · · 3.2.2.1 Building the project 68 Executing code at full speed 70 Halting execution 71 Single-step , step-over and step-out execution 71 Animation-mode and "Animate Over" execution 74 Showing the execution point 75 Resetting the emulated PIC 76 Setting the program counter (execution point 77 ) Using breakpoints 78 Building the Project The process of assembling or compiling source code is called "building." When you tell TDE to build the project, it calls upon the selected tools to assemble/compile the each node in the project.* To build the project, select Build from the Project menu, or click the corresponding button, or press F4. F4 © 2007 TechTools TechTools Design Environment If no errors are encountered, then the resulting hex code can be run in the emulator. Note the message "Project Build Complete" shown below: If errors are encountered, then TDE will display an error list: To see a corresponding error in the source code, just click on the error in the error listing; the original source code line will be highlighted: © 2007 TechTools 69 70 PicTools Manual 3.0 * The assembler/compiler is selected by using the Project the Setup menu. 3.2.2.2 46 option in Executing Code at Full Speed To execute code at full speed in the emulator, select Go from the Run menu, or click the corresponding button, or press F5. F5 © 2007 TechTools TechTools Design Environment Code will be executed at the speed chosen when the project was started ( for more information, see the Device 59 tab of the Project option of the Setup menu ). Execution speeds vary from 30 kHz to 25 MHz or up to the maximum ratings of the modules. During full-speed execution, very little occurs with TDE. After downloading the code to the emulator, TDE simply waits for a breakpoint or for user input. Because full-speed execution occurs too quickly for the PC to keep up, TDE does not update any of its windows until execution is stopped (by a breakpoint or by you). 3.2.2.3 Halting Execution To halt code execution, select Halt from the Run menu, or click the corresponding button, or press F6. F6 Execution will be halted and TDE will update information in any open windows. 3.2.2.4 Single-Step Execution To execute one line or instruction, select Single Step from the Run menu, or click the corresponding button, or press F8. F8 © 2007 TechTools 71 72 PicTools Manual 3.0 If the editor window is the active window, then the emulator will execute one line of source code. If the code window is the active window, then the emulator will execute one instruction of code. When using the TechTools assembler or any C compiler, one line of source code may be multiple instructions. Single-stepping is very useful when you suspect that a part of your code contains an error, but you’re not sure which instruction is the cause. 3.2.2.5 Step OUT Execution To execute a step-out command, select Step Out from the Run menu, or click the corresponding button. © 2007 TechTools TechTools Design Environment Step-out execution will "Step Out" of a subroutine if the current execution point has already progressed into one. The remaining portion of the routine will execute at full speed until a return is encountered, then execution will be halted. 3.2.2.6 Step Over Execution To execute in step-over mode, select Step Over from the Run menu, or click the corresponding button, or press F7. The emulator will execute one instruction, and then TDE will update any open windows. F7 © 2007 TechTools 73 74 PicTools Manual 3.0 Step-over execution is similar to single-step 71 execution. In this mode, the emulator executes one instruction at a time, just like single-step mode. However, step-over mode jumps over calls to subroutines (subroutines are still executed, but not shown on the screen). This is useful when you’re debugging a particular routine, but you don’t want to study each subroutine in the same detail. 3.2.2.7 Animation-Mode Execution To execute in animation mode, select Animate from the Run menu, or click the corresponding button, or press F9. F9 Animation mode is a repeating version of single-stepping. In this mode, the emulator executes one instruction, then waits for TDE to update its windows, and then executes the next instruction. Execution speed varies with the speed your PC and the baud rate selected for communication with the emulator. On a typical 486-based PC, the emulator will execute 1-2 instructions per second. If Animate runs too fast, you can set the maximum rate by choosing the Environment 62 option from the Setup menu. 3.2.2.8 Animate Over Execution To execute in animation mode, select Animate Over from the Run menu, or press "Shift" and click the Animate button, or press "Shift" and F9. Shift + F9 © 2007 TechTools TechTools Design Environment 75 Animate Over is a modified Animate function. When Animate Over is selected, the emulator executes one instruction, waits for TDE to update its windows then executes the next instruction. However if the instruction is a "CALL", the emulator will execute at full speed until a "RET" is processed, then resume its single instruction stepping. Since Animate Over relies on Stack Viewing capability, this mode of execution is not available when emulating a 16C5x device. 3.2.2.9 Showing the Execution Point To show the execution point, select Show Execution Point from the Run menu. The execution point will be indicated by a green highlighted line in the text editor window. © 2007 TechTools 76 PicTools Manual 3.0 At first, this option may seem a bit strange. The execution line is always indicated by a green highlighted line in the text editor window, so you might ask why you would need to specifically ask to see the execution line. Well, if execution has been stopped, and you’ve spent the las t few minutes scrolling around in a long program, you may have forgotten where the execution point is; in such a situation, you can ask TDE to quickly take you back. 3.2.2.10 Resetting the Emulated PIC To reset the PIC, select Reset from the Run menu, or click the corresponding button, or press F10. F10 © 2007 TechTools TechTools Design Environment 77 This resets the emulated PIC, as though a hardware reset had occurred. The program counter is reset, and all internal registers are set to their power-on state (or they are randomized, if you selected that option in the TDE Environment settings 62 ). This is different from the Reset ClearView 66 option in the File menu, which resets the emulator hardware itself. 3.2.2.11 Setting the Program Counter Sometimes, you may wish to set the program counter (the execution point) to an arbitrary location in your program. To do this, click on the line where you wish to set the program counter: After clicking on the new line, select Set PC from the Run menu. © 2007 TechTools 78 PicTools Manual 3.0 The highlighted line will move to the new line, indicating the new program counter value: 3.2.2.12 Using Breakpoints One very useful debugging method is the use of breakpoints. Break points are flags that you set on one or more lines in your program. During execution, the emulator stops on breakpoints, allowing you to see the status of registers, I/O pins, etc. To set a breakpoint, just double-click in the left margin of the desired line. The line will be highlighted in red, indicating the presence of a breakpoint. To remove the breakpoint, just double-click in the left margin of the same line. If you prefer, you can also use the keyboard and menu options shown below. © 2007 TechTools TechTools Design Environment Note that you can set breakpoints in the text editor window and in the code window. Any change in one window will be reflected in the other window, as well. Red highlighting shows the location of a breakpoint. © 2007 TechTools 79 80 PicTools Manual 3.0 Clearing All Breakpoints If you want to clear all breakpoints, there’s an easier way than clearing each one individually. Instead, you can use the Clear All Breakpoints function. To clear all breakpoints, select Clear All Breakpoints from the Run menu, or press Ctrl-F9. 3.2.3 Using the Various TDE Windows The following section begins with the "basics" of using TDE's windows, then covers the specifics of how to implement particular features of various windows. · · · · · · · · 3.2.3.1 Window basics 80 Text editor window 82 Build Log window 93 Code w indow 95 Symbols window 96 File registers window 105 Watch list window 108 Trace buffer window 116 Window Basics Before we examine any particular window, let’s review the basics concernin g all windows: things like scroll bars, close boxes, etc. If you already understand such things, you may want to skip to the Editor Window section. © 2007 TechTools TechTools Design Environment The window below is like most windows in TDE; it happens to be the editor window, but for thi s discussion, it could be almost any window. A couple of things that may not be obvious are how to move a window and how to change its size . To move a window, click and hold the mouse button on the window’s "Title bar" while moving the mouse. To change its size, click and hold the mouse button on one of the window’s edges or corners while moving the mouse. Pop-up menu: © 2007 TechTools 81 82 PicTools Manual 3.0 Most TDE functions have one or two ways to access them. Some of the Window functions have a third way: by pop-up menu. To see the pop-up menu, press the right mouse button while the cursor is in the window. Once the pop-up menu is visible, use the mouse (with the usual left button) to make your selection. The image below shows an example of the Editor pop-up menu: 3.2.3.2 Editor Window The editor window is the central w indow in any project; it is used to enter and edit source code, to watch execution, and to set breakpoints. The editor acts like a simple word processor, complete with functions to cut/copy/paste, search/replace, mark routines, etc. If you’ve read many of the preceding sections, you’ve already seen and worked with the editor window. So far, however, you haven’t seen a detailed description of how the editor works. This section covers the editor in more detail. · · · · · · Enter source code 85 Set and clear breakpoints Cut, copy, and paste 85 Undo and redo 88 Search and replace 89 Place markers 91 85 There are several ways to see the editor window: Open an existing or new project, OR open an existing or new file. Then: © 2007 TechTools TechTools Design Environment · Select Edit from the View menu OR, · Select Open from the Files tab 51 of the Setup->Project option, OR... · Double-click on a File-node from the Files tab 51 of the Setup->Project option. The open editor window looks like this: © 2007 TechTools 83 84 PicTools Manual 3.0 NOTE: "Cycles and Time" and "Total cycles" are only available if the Trace Buffer 60 or Timing Module is installed. © 2007 TechTools TechTools Design Environment 85 3.2.3.2.1 Enter source code The editor works much like a word processor. If you already have source code on disk, use New Project and ADD the existing file to the new project. Then select Open, for editing. If you need to create a new source code file: 1. Open or Create a project, 2. Select ADD from the Files 51 tab of the Project Dialog When prompted for the file name, enter the desired name and TDE will create the new file for you. 3.2.3.2.2 Set and clear breakpoints To set or clear a Code breakpoint, just double-click in the left margin of the desired line. The line will be highlighted in red, indicating the presence of a breakpoint. If a breakpoint already exists on the line, then it will be cleared. Note that if the execution point (green) is present on the same line as a breakpoint (red), the resulting color is blue (green + red = blue). For more information on breakpoints, see the breakpoints 78 discussion at the end of the previous section. Data Breakpoints (DBP) are only available if the Advanced xx Family Module is installed. For details on configuring Data Breakpoints 118 , see the Data Breakpoints Section at the end of this Chapter. 3.2.3.2.3 Cut, copy, and paste These functions are fairly standard on most editors, and work in the same manner. The editor maintains a "clipboard," which is a special buffer used for editing. When you cut or copy text, the text is stored in the buffer. Later, you can paste the buffer text into another part of your source code. Cut: Highlight the desired text, and then select Cut from the Edit menu, or select Cut from the © 2007 TechTools 86 PicTools Manual 3.0 pop-up menu, or press Ctrl-X. The highlighted text will be removed and stored in the buffer. Copy: Highlight the desired text, and then select Copy from the Edit menu, or select Copy from the pop-up menu, or press Ctrl-C. A copy of the highlighted text will be stored in the buffer (the text will not be removed from its current location, though). Paste: Place the cursor where you’d like to insert the text from the buffer (text that was previously cut or copied), and then select Paste from the Edit menu, or select Paste from the pop-up menu, or press Ctrl-V. The following example shows a simple copy-and-paste operation: Step 1: highlight text to copy Place the mouse at the beginning of the text, and then click and hold the mouse button while moving the mouse to the end of the text. Step 2: copy text to clipboard memory Select Copy from the Edit menu. Step 3: place cursor at new location © 2007 TechTools TechTools Design Environment 87 Move the mouse to the new location, and then click the mouse button. The cursor will appear at the new location. Step 4: insert the copied text Select Paste from the Edit menu. The copied text will appear where the cursor was placed in step 3. Notice the new pair of CLC and RR instructions. © 2007 TechTools 88 PicTools Manual 3.0 3.2.3.2.4 Undo and redo Like cut, copy, and paste 85 , these functions are fairly standard on most editors, and work in the same manner. The editor maintains a record of changes you make, so that changes can be reversed (undone) if you decide to do so. A change is anything that was recently typed or deleted, but the return key separates one change from the next. Also, the return key itself is a change. So, if you type "abc" on one line, and then you type "xyz" on the next line, there are three changes: 1) abc, 2) return key, and 3) xyz. © 2007 TechTools TechTools Design Environment 89 Undo: Select Undo fro m the Edit menu, or press Ctrl-Z. The editor will undo the last change made in the editor. Redo: Select Redo from the Edit menu. The editor will redo (replace) the last "undone" item. The editor maintains an 8K buffer for storing changes to the file, so a lot of things can be undone and redone. However, changes are stored sequentially, so it may take some time to reach a change that happened a long time ago. For instance, if you delete one line and then type ten new lines, and then decide that you want the first line restored, you will have to undo the last eleven changes (which will erase the last ten lines). 3.2.3.2.5 Search and replace This function allows you to easily find text in the editor, and to replace the text with something new (if you want to). You can also perform global search and replace, in which the editor replaces every occurrence of the text. The search function only searches text after the cursor location, so be sure to place the cursor a ccordingly. If you want to search the entire editor, you must place the cursor at the beginning of the file before starting the search. To start a search, select Search from the Edit menu, or press Ctrl-F; after doing so, you’ll see the following window: © 2007 TechTools 90 PicTools Manual 3.0 The search window has the following controls: Find what: This is the text to search for. Replace with: This is the text which will replace the text found in the search. If you just want to find something without replacing it, you can leave this field blank. Match whole word: If this box is checked, then the search function will only find occurrences of the exact text to be found. If this box is not checked, then the search function may find words that simply contain the search text (for instance, if searching for "and," the function will find "band"). Match case: If this box is checked, then the search function will only find occurrences with the same case. If this box is not checked, then the search function will ignore case (for instance, if searching for "value," the function will find "Value"). Find Next: Click this button to search for the next occurrence of the search text. If a match is found, then it will be highlighted in the editor. Replace: Click this button to replace the last found text with the replacement text. This only applies to if a search has been performed, and if the search found a match. Replace All: Click this button to replace all occurrences of the search text with the replacement text. This is really useful if you decide to change the name of a variable or other item throughout your program. Cancel: Click this button to exit the window. © 2007 TechTools TechTools Design Environment A related function is Search Again. This function uses settings from the most recent search, but does not show the normal search window. It’s useful for performing the same search over and over. To activate the search-again function, select Search Again from the Edit menu, or press F3. 3.2.3.2.6 Place markers Markers are used to mark locations in the editor, so that they may be found later. Only ten markers are allowed, so they are normally used to mark important routines which are under development. Later, when you want to find a marked location, you just use the pop-up menu 80 . To set or clear a marker on the current line (the line where the cursor is), click the right mouse button to see the editor’s pop-up menu, then select Toggle Marker, and then select the marker number you want to use (0-9). © 2007 TechTools 91 92 PicTools Manual 3.0 1. If the chosen marker is not already present, then it will be placed on the line. 2. If the chosen marker is already present, then it will be removed. To find a marker that was placed earlier, select Go to Marker fr om the pop-up menu 80 , and then select the marker you want to find. The editor will move to the line where the marker was placed. © 2007 TechTools TechTools Design Environment 3.2.3.3 Build Log If errors are encountered when TDE tries to assemble or compile your source code, then they will be shown in the Build Log window. The Build Log is automatically shown if TDE encounters errors. However, if you would like to see the Build Log (if it’s behind another window), just select Build Log from the View menu; the following window will appear: © 2007 TechTools 93 94 PicTools Manual 3.0 Each line in the Build Log marked "error", corresponds to an error in the source code. To see a corresponding error in the source code, just click on the error in the errors window; the original source code line will be highlighted: © 2007 TechTools TechTools Design Environment 3.2.3.4 Code Window The code window shows the actual Microchip hex code that runs in the emulator. Hex code is the result after source code is assembled or compiled. To see the code window, select Code from the View menu. In most cases, you’ll work with source code in the editor window. Most users prefer to work with source code, since it’s easier to read and edit. However, there may be times when you need to emulate code that only exists as hex code (the source code may have been lost, etc). In such cases, you can load the hex file by adding it to your project using the Project option of the Setup menu ( explained earlier in " Creating a Single-file Project 46 " ). Whether the hex code came from an internal operation (assembly or compilation), or from an external file, it will be available in the code window. However, if the hex file was loaded from disk, then the code window will be the only window in which you can execute and manipulate the code. Like the editor window, the code window shows the execution point and any breakpoints; breakpoints can be set and cleared by double-clicking on any executable line. © 2007 TechTools 95 96 PicTools Manual 3.0 Breakpoint (red): Indicates a breakpoint; double-click to set or clear a breakpoint. Execution point (green): Shows the instruction being executed. If execution is stopped, then this line will be executed when execution is resumed. Selected line (navy): A Single-click will highlight the selected line in the Code Window as well as the corresponding source-line in the Editor Window 82 . This feature helps the user to navigate and quickly cross-reference the source to the actual compiled Opcode/Operands. 3.2.3.5 Symbols Window The Symbols window contains several special windows important to Editing and Debugging. · Special Registers 97 · Variables 99 · Labels 103 · Files 105 To see the symbols window, select Symbols from the View menu. © 2007 TechTools TechTools Design Environment 3.2.3.5.1 Special Registers Window This window allows you to see and modify the emulated PIC’s special registers. Special registers include the W register, Indirect addressing register, Option register, Program Counter, Status register, I/O port registers, etc. Special Register Viewing Options: At the top of the special register window are several buttons that control what items are displayed and how they are displayed. A - Toggles displaying of the Address Column. H - Toggles displaying of the HEX Column. D - Toggles displaying of the Decimal Column. B - Toggles displaying of the Binary Column. C - Toggles displaying of the ASCII (Character) Column. A-Z Sorts the registers by NAME 0-9 Sorts the registers by ADDRESS To modify the value in a register, just double-click on the value; the following register modification window will appear: © 2007 TechTools 97 98 PicTools Manual 3.0 Some registers and bits of registers are write-only. Such registers and bits cannot be modified. Registers that will be affected by READING, display an ' * ' instead of the actual dat a (as seen above in the RCREG and SSPBUFF registers). This provides the user with the option of forcing a read by DBL-Clicking on the register. From this window, you can enter a new register value in hex, binary, or decimal. You can also use the handy register modification pop-up menu. To use the pop-up menu, click the right mouse button; you’ll see the pop-up menu as shown here. © 2007 TechTools TechTools Design Environment The pop-up menu gives you several useful editing functions, including undo, cut, copy, and paste. These functions work just as their counterparts in the editor window. In fact, the cut, copy, and paste functions use the same buffer memory as the cut, copy, and paste functions in the editor. Therefore, you can copy a value from the editor to a register, or from a register to the editor. Of course, you can also copy values from register to register. If you’re not sure what these functions do, please see the editor window description 82 earlier in this section. After making any necessary changes, click OK to accept the changes, or click Cancel to disregard them. 3.2.3.5.2 Variables Window This window allows you to see and modify Defined RAM Locations, including the special registers if selected. From this window register values can be edited, variable display characteristics can be modified and items can be added to the Watch Window. © 2007 TechTools 99 100 PicTools Manual 3.0 Variables Window Viewing Options: At the top of the special register window are several buttons that control what items are displayed and how they are displayed. A - Toggles displaying of the Address Column (Val). V - Toggles displaying Defined General Purpose RAM locations (Variables). K - Toggles displaying Defined Constants. b - Toggles displaying of Defined Bits. S - Toggles displaying of the Special Registers. A-Z Sorts the registers by NAME 0-9 Sorts the registers by ADDRESS Modifying a Register Value and Display Format: To modify the value in a register or to change the display format, just double-click © 2007 TechTools TechTools Design Environment 101 on the value and the modification dialog will appear: Integer Options: Radix: - Select HEX, Binary or Decimal formatting. Length: - Group the selected number of bits as a single value (consecutive). Signed: - Display as a signed value. Big Endian: - If the Length is greater than 8 bits, this option will display the MSB first when selected. Repeat Count - Treat as an array of the above settings with the specified number of elements. © 2007 TechTools 102 PicTools Manual 3.0 String Options: Format: - Select the desired string type. Max Chars - Enter the maximum number of characters to associate with this string. Repeat Count - Treat as an array of the above settings with the specified number of elements. Float Options: © 2007 TechTools TechTools Design Environment 103 Format - Choose the desired float format. Precision - choose from 24 or 32 bit precision. Big Endian - If selected, value will be displayed MSB first. Repeat Count - Treat as an array of the above settings with the specified number of elements. Fixed Options: Format - Choose from 16.8 or 16.16 format. Big Endian - If selected, value will be displayed MSB first. Repeat Count - Treat as an array of the above settings with the specified number of elements. Adding Watches: Watches can be added to the watch window three ways. First, select one or more registers by using the left mouse button (and optionally the Shift or Control keys for multiple selections). Then, either Drag & Drop the selected items onto the Watch Window, or click the Add button at the top of the window (+). The third method is to enter the address manually in the edit box at the top of the window and then press the Enter key (or click the add button). With this method, the address must be specified in HEX, proceeded by ' 0x '. For example, address 127 must be entered a s 0x7F. 3.2.3.5.3 Labels Window From this window, you can jump to the position of a specific label in your source code. Double-Click on any label in this window and the associated source code line will be © 2007 TechTools 104 PicTools Manual 3.0 brought into view and highlighted yellow. Local labels are grouped with its Global label as seen with the label ' FIFO ' above. FIFO is a global label that has two local labels defined as PAD and PUSH. © 2007 TechTools TechTools Design Environment 3.2.3.5.4 Files Window The Files Window will reflect all files referenced in the debugging information provided by the assembler or compiler. This information is refreshed after each successful build. Double-Click on any file in this window and it will be displayed in the source code editor. If the file has not been opened since the start of your session, TDE will open the file for you. 3.2.3.6 File Registers Window This window allows you to see and modify the emulated PIC’s file registers. Most file registers serve as general-purpose storage space for variables and program data. To see the file registers window, select File Registers from the View menu; the window below will appear. © 2007 TechTools 105 106 PicTools Manual 3.0 Color Legend: White - Defined ram location that has NOT changed since the last Halt. Aqua - Defined ram location that has changed since the last Halt. Gray - Undefined ram location that has NOT changed since the last Halt. Yellow - Undefined ram location that has changed since the last Halt. The file register window works just like the previously-discussed special registers window. To modify the value in a register, just double-click on the value; the following window will appear: © 2007 TechTools TechTools Design Environment From this window, you can enter a new register value in hex, binary or decimal. You can also use the register modification pop-up menu to cut, copy or paste values. After making any necessary changes, click OK to accept the changes, or click Cancel to disregard them. The File Registers window has additional options that are accessible by a POPUP Menu: FILL ALL - Select this option to fill all general purpose ram locations with a specific value. Watch - Select this option to add the ram location (or its label if defined) to the watch window. © 2007 TechTools 107 108 3.2.3.7 PicTools Manual 3.0 Watch List Window This window maintains a list of variables and/or registers that you’d like to watch. By placing items in this window, you can easily see their values as your program runs. You could do the same thing by watching the appropriate locations in the Special Registers 97 , Variable Window 99 and File Registers windows 105 , but using the Watch List window can speed up your debugging by grouping items of interest. This section covers the following procedures: · Adding items from Source Code 108 · Adding items from the Variables Window · Modifying Values of watched items 112 · Watch List Options 115 109 To see the watch list window, select Watch List from the View menu or click the View Watches Button. 3.2.3.7.1 Adding Watch items by Highlighting Items can be added to the Watch Window directly from the source code editor. To add a watch, simply Highlight the item to watch, then Right-Click in the editor and select Add Watch Selected from the popup menu. © 2007 TechTools TechTools Design Environment The item will be added to the currently visible Watch Group in the Watch Window. If you have not added a watch group, then the item will be placed in the Default Watch Group. 3.2.3.7.2 Add Watch Dialog Adding Watches: Watches can be added to the Watch wind ow from the Variables Window in the three ways described below. To select which items are visible in the Variables Window, see: Symbols - Variables Window 99 . Select and Add - First, select one or more registers by using the left mouse button © 2007 TechTools 109 110 PicTools Manual 3.0 (and optionally the Shift or Control keys for multiple selections). Then, click the Add button at the top of the window (+). Select and Drag & Drop - First, select one or more registers by using the left mouse button (and optionally the Shift or Control keys for multiple selections). Then, Drag & Drop the selected items onto the Watch Window. © 2007 TechTools TechTools Design Environment Edit and Add - Enter the Name of the item or its address in the edit box at the top of the window and press the Enter key (or click the add button). If entering an address, it must be specified in HEX, proceeded by ' 0x '. For example, address 127 must be entered as 0x7F. © 2007 TechTools 111 112 PicTools Manual 3.0 Note 1: You can watch a specific bit of a symbol by declaring Symbol.Bit, where Symbol is the name and Bit is a bit number from 0-7. Note 2: You can watch a symbol by giving its address, rather than its name. To do so, declare it as 0xhhh, where ‘hhh’ is the hexadecimal address of the symbol. This must be done in some cases, such as when watching a local symbol from the MPC or CCS compilers. This notation is also valid when setting the File Reg ister options 120 in the Data Breakpoints Dialog 118 . 3.2.3.7.3 Modifying Watch item values In addition to watching items in the Watch Window, you can modify the item's value and display characteristics as well. To change the properties of an item, double-click on the item in the watch list: Modifying a watched item or changing its display format: To modify the value in a register or to change the display format, just double-click on the value and the modification dialog will appear: Integer Options: Radix: - Select HEX, Binary or Decimal formatting. Length: - Group the selected number of bits as a single value (consecutive). © 2007 TechTools TechTools Design Environment 113 Big Endian: - If the Length is greater than 8 bits, this option will display the MSB first when selected. Repeat Count - Treat as an array of the above settings with the specified number of elements. String Options: Format: - Select the desired string type. Max Chars - Enter the maximum number of characters to associate with this string. Repeat Count - Treat as an array of the above settings with the specified number of elements. © 2007 TechTools 114 PicTools Manual 3.0 Float Options: Format - Choose the desired float format. Precision - cho ose from 24 or 32 bit precision. Big Endian - If selected, value will be displayed MSB first. Repeat Count - Treat as an array of the above settings with the specified number of elements. © 2007 TechTools TechTools Design Environment 115 Fixed Options: Format - Choose from 16.8 or 16.16 format. Big Endian - If selected, value will be displayed MSB first. Repeat Count - Treat as an array of the above settings with the specified number of elements. 3.2.3.7.4 Watch List Options The Watch Window has several options for changing how items are displayed. All of these options are available from the popup menu. To access the popup menu, Right-Click in the Watch Window. Sort Items can be sorted by NAME, ADDRESS or No Sorting. These three options are also available as speed buttons on the toolbar (A-Z = Name Sort, 0-9 = Address Sort, No = No Sort). To sort manually, simply Drag & Drop the item to the desired position. This is accomplished by holding the mouse down on the column to the left of the item and then releasing the mouse when the cursor is at the desired destination. Delete Watch Deletes the currently selected watch item. Show Address Toggles displaying of the Address Column Default Radix Sets the RADIX (HEX, Decimal or Binary) for all items that have not been customized (see: Modifying 112 Watch Item Values 112 ). © 2007 TechTools 116 PicTools Manual 3.0 Clear Formats Clears all special formatting on customized items (indicated by the color yellow in the first column) and sets them to default format (see: Modifying 112 Watch Item Values 112 ). The window may have to be closed and re-opened in order for the changes to take effect if the customized item is not already selected. Watch Group New groups can be added from this menu option or the current watchgroup can be deleted. Show Toolbar This option toggles the toolbar display. 3.2.3.8 Trace Buffer Window This window shows the contents of the trace buffer memory. It is only available if the optional trace buffer 60 module is installed. The trace buffer keeps a record of each instruction executed by the emulator. For each instruction, the record shows the locat ion in the trace buffer, the value of the program counter, the state of external trace inputs, and the original line of source code. The trace buffer memory is 16K "deep," resulting in a capacity of approximately 16,384 Microchip instructions . Some instructions, such as JMP and GOTO, take two processor cycles, and therefore take two locations in the trace buffer memory. In addition, some TechTools instructions utilize two or three Microchip instructions, and will therefore take multiple locations in the trace buffer (this is also true of high-level compiled languages, such as C). To see the trace buffer window, select Trace from the View menu. © 2007 TechTools TechTools Design Environment The following window will appear: Like several other windows, the trace window has a pop-up menu; to see it, place the mouse over the trace window and then press the right mouse button: The pop-up menu has four options; to select a function, just move the mouse to the desired option and then click the left mouse button. The options are described below: Clear trace buffer Select this option to erase the trace buffer. © 2007 TechTools 117 118 PicTools Manual 3.0 Enable/disable trace Select this option to enable or disable the trace function. If already enabled, then the pop-up menu will show "disable trace." If already disabled, then "enable trace" will be shown. The trace function can also be controlled from the Trace 60 tab in the Project option of the Setup menu , but the pop-up menu is usually much easier. If the trace function is disabled, t hen the window titles will be shown in italic letters. Show Externals This option toggles the External Input Display. An external input connector is located on each member module for attaching the trace cable (which has mini-clip connectors for attaching to your circuit). When selected, the eight external inputs are displayed in binary form. Show Disassembly This option toggles the Disassembly display. If selected, the trace window also displays the execution history in Microchip assembly format. Note 1: The trace window is only available if the trace buffer module is installed. For questions regarding the trace hardware, please see the end of the Hardware Installation section. Note 2: The trace buffer memory is arran ged as a FIFO (first-in first-out) buffer. After 16K of history is recorded, the oldest records are lost to make room for new records. 3.2.4 Data Breakpoints Data Breakpointing is a very productive and timesaving feature available with the Advanced XX Family Module. Sometimes a simple execution breakpoint and Watch window do not yield enough information to determine which line of code is changing a variable. It could take hours or even days to find the mistake. TDE's Data Breakpoints will help you find this kind of problem almost immediately. This section covers the following details: · Enable and Break On options 120 · File Register options 120 · Match On options 121 · Include Constants option 123 · Breaking on Data 124 © 2007 TechTools TechTools Design Environment To open the Data Breakpointing Dialog, select Data Breakpoints from the Setup menu. NOTICE: Some MCUs have a "Self Modifying Code" feature. This option must be disabled in order to enable Data Breakpoints. Disable the self modifying features by selecting "Setup - Project - Emulator", then selecting "Ignored" for the Code Read and Code Write options. © 2007 TechTools 119 120 3.2.4.1 PicTools Manual 3.0 DBP Enable and Break On options After Selecting Data Breakpoints from the Setup menu, a dialog similar to the one below should appear. If the options are not available, then you may not have the Advanced Family Module or you need to disable the Self Modifying Code Features (see: Data Breakpoints 118 ). Enable: Disables or Enables a specific Data Breakpoint. Break On: Select the type of activity to monitor: Read - Break If a match occurs when your program reads the register. Write - Break If a match occurs when your program writes to the register. Read or Write - Break If a match occurs when your program writes to OR reads from the register. 3.2.4.2 DBP File Register options The "File Register" option refers to any Special Register 97 or General Purpose Register 105 (also see: Variables Window 99 ) your code has access to. The data at this location will be the focus of the criteria in the Match On 121 option. Select a predefined symbol from the drop down list as shown here, or enter an absolute address as shown in the examples below : © 2007 TechTools TechTools Design Environment Monitor the data at the absolute HEX address BF: Monitor bit 6 of the absolute HEX address BF: Monitor bit 5 of the STATUS register: Notice: An ' ! ' (exclamation point) or ' 0x ' should be used prior to the HEX value to indicate an Absolute address. This notation is also used in the Add Watch Dialog 109 . 3.2.4.3 DBP Match On options Select one of the three options to specify the data "Match" to break on. Any Data: When this option is selected, the data value is ignored. A Match is determined by the Break On 120 selection, without any further qualifiers. © 2007 TechTools 121 122 PicTools Manual 3.0 Specific Data: This option will qualify the breakpoint with a specific data value. When this option is selected, a break will occur ONLY if the data matches the specified value exactly. Bit Pattern: This option allows you to define specific bits which should be ignored during the match evaluation. Each bit has three possible states; on, off and don't care. 1 = ON 0 = OFF X = Don't Care © 2007 TechTools TechTools Design Environment In the example on the above, we selected specific values for the bit positions in the upper nibble, and don't car e for each bit in the lower nibble. Using this bit pattern as a qualifier, a break will occur whenever your program writes any of the following HEX values to the "this_task" register: A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, AA, AB, AC, AD, AE, AF Or in binary; any value from: 10100000 through 10101111. Any combination of 1's, 0's and X's is valid. 3.2.4.4 DBP Include Constants © 2007 TechTools 123 124 PicTools Manual 3.0 When this opti on is not selected, TDE will filter out all data types defined as Constant by the compiler. Note that some compilers define all symbols as constants, and selecting this option forces TDE to display Constant Data Types in the File Register list 120 . 3.2.4.5 Breaking on data When TDE encounters a valid Data Breakpoint 118 , execution will be halted and the display line updated to reflect the breakpoint details as shown below. To view the actual code line responsible for the Data breakpoint, right-click in the editor window 82 and select Go to Data Breakpoint. This will move the cursor to the correct code line. If the code line is located in another file, TDE will bring that file into view before moving the cursor. The correct code line is also identified in the status bar as shown above. © 2007 TechTools TechTools Design Environment Due to the PIC's pipeline architecture, one to two instructions will be executed after the data breakpoint occurs. 3.3 Compiler Integration Notes This section contains Hints on integrating popular compilers and assemblers with TDE. · · · · · · · © 2007 TechTools How We Do It 126 CVASM16 127 SPASM 127 MPASM 127 MPLINK 128 Bytecraft C 128 Bytecraft Linker 128 125 126 PicTools Manual 3.0 · · · · · MPLABC 129 Hi-Tech C 129 CCS - PCB and PCM COD Only 131 HEX Only 131 130 This information is included to give you some insight as to HOW we integrate with each of these compilers, any assumptions we make and any common installation mistakes we are aware of. Most TOOLS strongly recommend that you include their directory in your path. If you forgot to (or chose not to) set your system PATH to include the compiler directory, you may optionally choose to specify the path in the TOOL PATH option box in the project NODE setup. This MAY not work with some TOOLS. NOTE: We include CVASM16 with TDE. We also include SUPPORT for all of these other compilers and assemblers. HOWEVER, WE DO NOT SUPPLY THESE THIRD PARTY TOOLS WITH TDE. YOU MUST OWN THESE OTHER TOOLS IN ORDER TO USE THEM. This may seem obvious but we have had MANY tech-support calls asking why a particular compiler is not working. Eventually we find that the customer thought that we were somehow providing the functionality of all of these commercial compilers with our own software. 3.3.1 How we do it In general, we spawn the third-party compiler or assembler in a separate console window and capture its output. We wait for it to complete and then analyze the resultant files to determine if it was successful. If errors are found, we display them and show you the source line that caused the error. If the TOOl was successful, we read the resulting symbol table, line references and HEX data into an internal database for debugging. While we are building the project, you will see a console ICON on the task bar. If the project build seems to stall, click on this ICON and you will see the state of the project build. In a few cases, some tools will pause and ask you to hit a key before it continues. This causes TDE to appear to 'lock-up'. In reality, TDE is just waiting on the project build process to complete. The process is waiting on you to press a key but its window is minimized so you never see the message. Unfortunately, not all compilers and assemblers can be forced to ALWAYS log errors rather than pause for input from you. The good news is that this situation is very rare. It usually only happens if the compiler has a critical error. The following sections describe each compiler we currently support. If you are using a TOOL that we do not list here, let us know. TOOLs that generate standard symbol formats are easy to integrate. © 2007 TechTools TechTools Design Environment 127 NOTE: TDE is preconfigured to work with these compilers. You should not have to make any concessions or exceptions to the normal compiler installation or configuration to operate with TDE. In other words, install and configure your compiler as directed by its manufacture and it should operate with TDE. 3.3.2 CVASM16 CVASM16 is include with the TDE installation. It should operate properly as installed. TDE expects CVASM16.EXE to reside in the same directory as TDE.exe. PLEASE LEAVE IT THERE. CVASM16 is a SINGLE SOURCE FILE type tool. You can NOT specify multiple source file NODEs in the project. However, you can 'include' as many files as you wish into the main source file. This does not reduce your ability to debug. You can set breakpoints and single step through included files exactly the same as the main file. A typical CVASM project would specify CVASM16 as the TOOL in the PROJECT node. A single file NODE would be added to indicate the main source file. Its TOOL would be set to NONE. No path or options are required. NOTE: Beginning with the release of CVASM 6.0, an additional Project Tool selection has been added to distinguish between 6.0 and earlier versions of CVASM. To assemble source code written for pre 6.0 CVASM or any version of SPASM, select the CVASM 5.x Project Tool. This will call CVASM 5.8 which is included with the installation named as "CVASM_.EXE". You will find this file in TDE's directory ("C:\PicTools" by default). 3.3.3 SPASM Starting with release 4.0, TDE will invoke CVASM16 when you select SPASM. CVASM16 is fully source code compatible with SPASM. In addition, CVASM16 supports newer PIC chips and generates more complete symbolic information for the debugger. This additional information is critical to proper debugging. See the CVASM16 127 section for details. 3.3.4 MPASM MPASM can operate in two different modes. It can assemble a SINGLE SOURCE FILE to completion, generating an executable code image and debugging information. Alternatively, MPASM can also be used to create an OBJECT file suitable for LINKING with other modules. Each approach is discussed below. SINGLE FILE MODE: This is the traditional mode, similar to CVASM16. A typical project would specify MPASM as the TOOL in the PROJECT node. A single file NODE would be added to indicate the main source file. Its TOOL would be NONE. © 2007 TechTools 128 PicTools Manual 3.0 COMPILE TO OBJECT: This mode compiles a source NODE to an OBJECT module. This is used in conjunction with MPLINK 128 to produce a complete image file. In this mode, MPASM-to-OBJ is used as the TOOL on each SOURCE NODE to convert source files to OBJECT files. MPLINK is specified as the TOOL for the PROJECT NODE. 3.3.5 MPLINK MPLINK is used to combine multiple OBJECT files to a single executable file. Microchip assemblers can generate object files. MPLINK links these together. Set the PROJECT NODE's TOOL to MPLINK. MPASM to OBJ, can be used as TOOLS for each source file NODE. TDE will compile each source file node to objects, then run the PROJECT node tool(MPLINK) to link them together. 3.3.6 Bytecraft C The Bytecraft C compiler can operate in two modes. It can compile a single source file to a complete executable image, or it can generate OBJECT modules, suitable linking with the Bytecraft LINKER 128 . Both modes are discussed below. SINGLE FILE MODE: In this approach, you would specify the Bytecraft C compiler as the tool selection for the project node. You would them add a single source file NODE to the project to indicate which file should be compiled. This NODE would have its TOOL selection set to NONE. You can INCLUDE additional files IN THE SOURCE file if you wish. COMPILE TO OBJECT MODE: This mode allows you to specify several source files in the project. You would select the Bytecraft C to obj TOOL for each source file NODE. You would then select the Bytecraft LINKER for the PROJECT NODE. This setup compiles each source file to an object file, and then uses the linker to combine them into an executable image. A simpler approach to working with a multi-file project is to set up a single file project as discussed above. Then 'INCLUDE' multiple files into a single source file. This does not limit your ability to debug in any way. It may affect the way you use GLOBALS and STATICS but eliminates the need for a LINKER file. 3.3.7 Bytecraft LINKER When working with multiple source file projects, you must select the Bytecraft LINKER for the PROJECT NODE. © 2007 TechTools TechTools Design Environment 129 You must also create a LINKER file to tell the linker which header files the source files used, and which object files it should link. Failure to define a proper linker file will result in the linker failing to complete. An incorrect LINKER file may generate seemingly unrelated error messages or cause the build to stall, making TDE appear to hang. If the build seems to be taking too long, click on the console ICON on the task bar to see what the compiler is doing. It may be waiting on you to acknowledge that you have read a critical error message. A typical LINKER file follows: compiler = mpc.exe #include #include OBJECT = file1, file2 OBJECT = file3, file4 When running under TDE, the LINKER file MUST have a '.LNK' extension. You also MUST type the link file NAME, WITHOUT EXTENSION in the OPTIONs box of the PROJECT NODE. For example, you might create a LINKER file called myprj.LNK. You would then type "myprj" (without the quotes..of course) in the OPTIONs box of the PROJECT NODE. HINT: You can use TDE's FILE/OPEN to create and maintain this file just like any other file in your project. 3.3.8 MPLABC MPLABC is a SINGLE SOURCE FILE type tool. You can NOT specify multiple source file NODEs in the project. However, you can 'include' as many files as you wish into the main source file. This does not reduce your ability to debug. You can set breakpoints and single step through included files exactly the same as the main file. A typical MPLABC project would specify MPLABC as the TOOL in the PROJECT NODE. A single file NODE would be added to indicate the main source file. Its TOOL would be set to NONE. No path or options are required. 3.3.9 Hi-Tech C The Hi-Tech C compiler can be used in several modes. If you are compiling a single file, you can set up a simple project that compiles and links in a single step. In this case, you would specify Hi-Tech C for the PROJECT NODE TOOL. Then ADD your source file and specify 'NONE' for its tool. © 2007 TechTools 130 PicTools Manual 3.0 If your project consists of several files, you have two choices. The first choice is to specify multiple source files, each with a TOOL setting of 'NONE'. You can also add LIBRARY or OBJECT files to the project, again specifying tool settings of 'NONE'. This causes all source files to be passed to the PROJECT NODE TOOL. The PROJECT NODE TOOL (Hi-Tech C) would then compile and link them all together. The second approach is to specify the "Hi-Tech C to OBJ" tool for each SOURCE FILE NODE. This approach causes the Hi-Tech C compiler to be invoked for EACH source file. The resulting OBJECT files are then LINKED together by the Hi-Tech C compiler TOOL specified on the PROJECT NODE. You can even mix the two approaches; compiling some of the source NODEs directly and others at LINK time. What makes this all work is the fact that the Hi-Tech C compiler will accept a mixture of source, library and OBJECT files. It compiles what needs compiled and then links them all together. 3.3.10 CCS CCS - PCB (Base: 12 bit compiler) CCS - PCM (Mid-range: 14 bit compiler) These are SINGLE SOURCE FILE type tools. You can NOT specify multiple source file NODEs in the project. However, you can 'include' multiple files into the main source file. This does not reduce your ability to debug. You can set breakpoints and single-step through included files exactly the same as the main file. A typical project would specify PCB or PCM as the TOOL in the PROJECT node (depending on whether your are compiler for a 12bit or a 14bit device). A single file NODE would be added to indicate the main source file. Its TOOL would be set to NONE. No path or options are required unless you failed to set your system path during installation of the compiler. If your system path is not set, you can specify the PATH to the compiler executable in the TOOL PATH option box. We can not force PCB or PCM to generate COD format debugging information with command-line parameters. Instead, the compiler looks for this information in a file called PC.DEF in the project's local directory each time it is invoked. Each time we start a BUILD, we copy a PC.DEF file from the TDE install directory into your project directory, insuring that the compiler is properly instructed to generate the necessary information for debugging. If CCS changes the format of this file in the future, simply replace the one in the TDE directory with an updated version. TDE will then use the new PC.DEF file for all future builds. © 2007 TechTools TechTools Design Environment 3.3.11 COD ONLY This tool allows full debugging from a COD file. This is useful if you only have the COD file or if you wish to do your compiling from some other environment and then use TDE for debugging. Some prefer to use their own MAKE programs or IDEs. If your source files are available when the COD file is read in, TDE will do full source-level debugging. You will be able to step through the code, set breakpoints on source lines,..etc. To setup this work flow, simply select the COD ONLY tool for the PROJECT NODE and add a single source file node. The source file node should be the COD file. Set its tool to NONE. Now, each time TDE 'rebuilds' the project, he will copy your COD file to his own internal databases and begin debugging. 3.3.12 HEX ONLY This TOOL allows you to do debugging, even if you have nothing more than a HEX file. Of course, HEX files contain NO DEBUGGING information, so TDE will not be able to show you symbols or let you single-step through source code. It WILL allow you to watch registers, single-step through CODE and set breakpoints in the CODE window (a disassembled dump of the code space). To use this workflow, specify 'HEX ONLY' as the tool for the PROJECT NODE. ADD your HEX file to the project and specify 'NONE' for its TOOL. Whenever you update the HEX file, simply press TDE's BUILD button or press F4 or select the BUILD menu item and TDE will update Mathias. © 2007 TechTools 131 ClearView Assembler Part IV ClearView Assembler 4 133 ClearView Assembler If you already know how to use an assembler, you’ll probably find our’s to be quite simple. However, if you have little or no experience with assemblers, you should read the following pages before attempting to use the assembler. Assembler Reference 134 Instruction Set 144 Sample Projects 186 When you write programs for PIC microcontrollers, you will use a text editor to create source code. Source code is the format that you’re accustomed to looking at; it contains English-like labels, instructions, and data. Before your source code can be used by a programmer, emulator, or other development tool, it must be converted into hex code. Hex code is the "machine-readable" version of source code; it contains instructions and data in the form of hexadecimal data, which can be executed by the PIC. An assembler is a piece of software that converts source code into hex code. For instance, this line of source code: CALL SENDBYTE ;Call send routine assembles into just two bytes of hex code: 2420h It’s possible to write programs directly in hex code, using the individual machine codes that make up each instruction. However, most people find it preferable to use an assembler. The TechTools assembler (CVASM16 ) is unique in its ability to accept two instruction sets: our own 8051-like instruction set, and the original Microchip instruction set. Many customers appreciate the TechTools instruction set, because it resembles other processors. However, there are certainly customers who prefer the Microchip instructions. If you plan to use source code in the Microchip format, please note that while our assembler will accept their basic instructions, it will not accept various other aspects of their source code. The syntax of numbers is sometimes different, and our assembler does not recognize Microchip assembler directives and macros. If you plan to write a lot of code in the Microchip format, then you may wish to use the Microchip assembler (MPASM). © 2007 TechTools 134 4.1 PicTools Manual 3.0 CVASM16 Reference · · · · · · · · · · · · · · · 4.1.1 Software Installation 134 Running the Assembler 134 Generating Assembly Listings 135 Command-Line Options 135 Assembler Basics 135 Addressing Definitions 136 Data Types 136 Expressions 138 Symbols & Labels 138 Local Labels 139 Default Symbol Tables 139 Comments 140 Assembler Directives 140 Source Code Formatting 142 CVASM16 Error Messages 142 Software Installation If you installed our TDE or PICwriter software, CVASM was automatically installed into the TDE directory (PicTools), and you can skip this step. Insert the CD in your CDROM drive. If you have "auto run" enabled, the CD menu will launch automatically, or run the "Tech_cd.exe" program to launch the CD menu. After the CD menu has started, select the "PICTools" option , this will install TDE, the assembler and Include files, PICwriter software and create a Program Group called "PIC Tools". The CVASM16 assembler is a DOS executable which requires command-line parameters and can be executed by opening a DOS prompt and typing CVASM16 or selecting CVASM as your Project Tool in TDE. 4.1.2 Running the Assembler To assemble your source code into a hex file, type the following command at the DOS prompt: CVASM16 filename Assembles text file filename.src into hex file filename.obj. As shown above, only the name of the source file is given. The assembler uses the same name for the hex file, but replaces the extension with .obj. If you do not specify an extension as part of the source file name, the assembler will assume that the extension is .src. An example is shown below: © 2007 TechTools ClearView Assembler 135 CVASM16 EXAMPLE The assembler would produce a hex file called EXAMPLE.OBJ from the source file called EXAMPLE.SRC. 4.1.3 Generating Assembly Listings It is possible to have the assembler create an "assembly listing" of your program. An assembly listing is a duplicate of the source code, but with hex code information (line number, address, opcode, & data) preceding each original line. To have the assembler create a listing file, simply add "/L" after the filename: CVASM16 filename /L Assembles text file filename.src into hex file filename.obj and creates a listing file called filename.lst. 4.1.4 Command-Line Options The PIC assembler has several options which can be invoked when it is run. These command-line options are shown below: CVASM16 filename Assembles text file file name.src into hex file filename.obj. CVASM16 filename.xxx Assembles text file filename.xxx into hex file filename.obj. CVASM16 filename /L Assembles text file filename.src into hex file filename.obj and creates a listing file called filename.lst. CVASM16 filename /M Assembles text file filename.src into hex file filename.hex. This option will output a Microchip compatible HEX file suitable for Microchip tools and third-party programmers. CVASM16 filename /S Assembles text file filename.src into hex file filename.obj but suppresses additional information. This option is use ful for other tools that won’t accept any Device or Fuse information embedded in the hex file. 4.1.5 Assembler Basics The purpose of the assembler is to convert assembly language source code into hex code. The assembler accomplishes its task in two passes: © 2007 TechTools 136 PicTools Manual 3.0 Pass 0 - The source code is scanned in an attempt to resolve all symbols. This is possible if all origin, define space, and equate directives can be resolved (equated symbols may be referenced by origin or define space). All other symbols can be resolved by byte-offsets which are determined by the mnemonic/operand combinations. If Pass 0 is successful, the assembler will advance to Pass 1. If Pass 0 is unsuccessful, a list of errors will be shown and assembly will be aborted. Pass 1 - The source code is scanned once more in order to assemble the hex code. Since all symbols were resolved in Pass 0, all instructions and miscellaneous directives can be fully resolved in Pass 1. If Pass 1 is successful, a hex file containing the assembled code will be created. If Pass 1 is not successful, a list of errors will be shown and assembly will be aborted. In addition to a hex file, the assembler can be used to generate an assembly listing. An assembly listing shows line numbers, equated values, addresses, data, and original source code (for more information, see the section Generating Assembly Listings 135 ). 4.1.6 Addressing Definitions Throughout your programs, you’ll refer to bits and bytes by their addresses. Depending on the instruction being used and the item being referred to, the address will be given in one of the following forms: · addr8 page). · addr9 · addr11 memory). · addr12 memory). · addr13 memory). · bit · fr · rel · literal 4.1.7 An 8-bit address (on 16C5x devices, the lower half of the current 512-word A 9-bit address (on 16Cxx devices, within the current 512-word page). An 11-bit address (anywhere in program memory in a device with 2K of A 12-bit address (anywhere in program memory in a device with 4K of A 13-bit address (anywhere in program memory in a device with 8K of An address for bitwise operations. Example: PortC.3 = bit 3 of port C A file register (RAM) address. A relative address ranging from -7Fh to +80h. An immediate 8-bit value. Data Types Eight data types are allowed in the assembler. These data types are: · Symbol/label · Binary value · Local symbol/label · ASCII value · Decimal value · Assembly address (origin) · Hex value · EEPROM address (origin) © 2007 TechTools ClearView Assembler The examples below show various data types: 100 Decimal value 100 18h Hex value 18 0A7h Hex value A7 1011b Binary value 1011 'A' ASCII value for the letter A (65 decimal) Start Label called Start :loop Local label called :loop $ Current assembly address (Program Counter) % Current EEPROM address In addition to single-character text, entire strings can be generated using the RETW instruction: retw 'The fox jumped over the lazy dog' NOTE: The above example will assemble into multiple RETLW instru ctions. This instruction can be used as a "Look-up" table by moving a value into 'W', then doing a 'CALL' to the beginning of the table. The table should begin with a JMP PC+W (at this point, W should hold the intended offset into the string of cha racters). It is recommended to begin the table at a '00' address (such as 100h, 200h, 300h, etc. ) to avoid jumping to an unexpected address. PC+W is a calculated jump which is limited to an 8 bit calculation. If the calculated result is greater than 256 then the value in PCL will be rolled over causing execution to begin at an unexpected address. EXAMPLE: org 00h GETCHAR ; MOV character. W,myoffset ; RAM location 'myoffset' is the 'index' of the desired CALL TABLE1 ; calls code at label 'TABLE1' MOV achar,W ; stores the character in RAM location 'achar' ; ; org 200h TABLE1 JMP PC+W RETW 'The fox jumped over the lazy dog' © 2007 TechTools 137 138 4.1.8 PicTools Manual 3.0 Expressions Mathematical expressions are used in many instructions. These expressions may be created using the following operators: &Logical AND / Divide | Logical OR > Shift right + Add < High byte - Subtract > Low byte * Multiply . Bit address Some example expressions: setb PortA.0 ;Set bit 0 on port A. mov Count+3,#88h ;Store 88h in location Count+3. ds N*2 ;Define empty space of Nx2 bytes. All expressions are resolved strictly from left to right. Please make note of th is, since it may affect the result of expressions. For instance, the expression 5+2*4 would normally be resolved as (2*4)+5, for a result of 13. Since our assemblers resolve expressions strictly from left to right, however, the example would be resolved as (5+2)*4, for a result of 28. 4.1.9 Symbols & Labels Symbols are used to name locations and values within your program. Many people refer to address symbols as "labels", but both have the same effect. For instance, by assigning a symbol to the start of an important routine, you can later call that routine by its name, rather than its address. And by giving a symbol to a common value, you can refer to it by its name. Rather than typing "212" many times in your program, you can type HOT = 212 at the beginning of your program, and then use HOT wherever you need it. This is also quite handy if your idea of what’s "hot" changes. By changing the symbol definition, you can easily redefine HOT to be a different temperature. Symbols may be up to 32 character long. They must begin with a letter or underscore (_) © 2007 TechTools ClearView Assembler 139 and must contain only letters, numbers, underscores, and colons. Further, if you’re labeling an address (such as the start of a routine), the label must start at the beginning of the line. Here are some examples of valid symbols: min_count = 20h maximum_count = 21h begin min_count,#05h mov 4.1.10 Local Labels By default, labels are global, which means that they can be "seen" from anywhere in your program. Sometimes, however, you may want to use a local label, which can only be "seen" within a limited part of your program (the area in which the local labe l can be seen starts at the preceding global label, and continues up to the following global label). Local labels have the same syntax rules as global labels, except they must begin with a colon (:), and must be referenced with a colon. Local labels can be referenced from outside their normal area by referring to preceding global label name:local label name. The following code demonstrates how to use the local label :loop for common looping purposes within two globally-labeled routines. Routine1 :loop Routine2 :loop Routine3 mov call djnz ret mov call djnz ret count,#100 (global label Routine1) send_a (local label :loop) count,:loop (jump to line 2) mov jmp count,#250 Routine2:loop count,#200 (global label Routine2) send_b (local label :loop) count,:loop (jump to line 6) (global label R outine3) (jump to line 6) A Local label can be called from outside its usual area as demonstrated in the line: jmp Routine2:loop (jump to line 6) 4.1.11 Default_Symbol_Tables When the assembler is started, its symbol table is initialized with various PIC symbols, such as C for the Carry register, RA for Port A, etc. This saves you from having to define © 2007 TechTools 140 PicTools Manual 3.0 every register and bit in the PIC. As the number of different PICs has grown, it has become necessary to have separate symbol tables for each PIC. At the beginning of your program, you must tell the assembler which PIC is being used. This is done with the INCLUDE directive (explained later in this chapter). If you’d like to see the symbol table for a particular PIC, please refer to the device include files installed with the assembler (default location = C:\PicTools\*.inc). These files are named according to the targeted device. 4.1.12 Comments Comments can be placed anywhere in your source code, beginning at any point on a line and continuing to the end. A semicolon initiates a comment. The following are example comments: ; ; Move literal value 61h into w ; Input = 10h Output = 11h mov Input,#61h ; Load 61h into Input mov Output,#10h ; Load 10h into Output call talk_host ; Call routine to communicate with host Blank lines can be used to provide space between lines and make the code more readable. 4.1.13 Assembler Directives Assembler directives are instructions that direct the assembler to do something. Directives do many things; some tell the assembler to set aside space for variables, others tell the assembler to include additional source files, and others establish the start address for your program. T he directives available are shown below: = Assigns a value to a symbol (same as EQU) EQU Assigns a value to a symbol (same as =) ORG Sets the current origin to a new value. This is used to set the program or register address during assembly. For example, ORG 0100h tells the assembler to assemble all subsequent code starting at address 0100h. © 2007 TechTools ClearView Assembler 141 DS Defines an amount of free space. No code is generated. This is sometimes used for allocating variable space. ID Sets the PIC’s identification bytes. PIC16C5x chips have two ID bytes, which can be set to a 2-byte value. Newer PICs have four 7-bit ID locations, which can be filled with a 4-character text string. INCLUDE Loads another source file during assembly. This allows you to insert an additional source file into your code during assembly. Included source files usually contain common routines or data. By using an INCLUDE directive at the beginning of your program, you can avoid re-typing common information. Included files may not contain other included files. NOTE: The Device Include directive (i.e. INCLUDE 'C:\PicTools\16F877.inc' ) for the targeted device MUST be at the beginning of your source code. FUSES NOTE that FUSE CONFIGURATIONs can be '&' together on a single line and/or spread between multiple lines. ALL FUSES directives are ANDed together to create the composite FUSE CONFIGURATION. (view the device "include" file for specific fuse syntax) IF Assembles code if expression evaluates to TRUE. IFNOT Assembles code if expression evaluates to FALSE. ELSE Assembles code if preceeding evaluation is rejected. ENDIF Ends conditional evaluation. RESET Sets the reset start address. This address is where program execution will start following a reset. A jump to the given address is inserted at the last location in memory. After the PIC is reset, it starts executing code at the last location, which holds the jump to the given address. RESET is only available for PIC16C5x chips. EEORG Sets the current data EEPROM origin to a new value. This is used to set the data EEPROM address during assembly. This directive usually precedes EEDATA. EEORG is only available for PICs that have EEPROM memory . EEDATA Loads data EEPROM with given values. This provides a means of automatically storing values in the data EEPROM when the PIC is programmed. This is handy for storing configuration or start-up information. EEDATA is only available for PICs that have EEPROM memory. Assembler Directive Examples © 2007 TechTools 142 PicTools Manual 3.0 Include 'C:\PICTOOLS\16C877.inc' ; loads default symbols for the targeted device. FUSES _WD_OFF&_LP_OSC ; specify multiple fuse settings using the '&' operator. FUSES _CP_ON ; Specifies 1 fuse s etting per line. Digit = 43h ; Assign value 43h to Digit Max EQU 1Ah ; Assign value 1Ah to Max ORG 10h Count DS ; Set assembly address to 10h 2 ; Define 2 bytes at 10h & 11h ; Bytes can be referred to ; later as Count and Count+1 ID 1234h ; Set 16C5x ID to 1234h ID ‘ABCD’ ; Set newer PIC ID to 'ABCD' INCLUDE ‘KEYS.SRC’ ; Include KEYS.SRC file at ; point of insertion RESET Start ; Set 16C5x reset jump to ; location at Start Start mov Count,#00 ; This will be executed when a '5X PIC is reset EEORG 10h ; Set EEPROM address to 10h EEDATA 02h,88h,34h ; Store 3 bytes in EEPROM 4.1.14 Source Code Formatting We recommend that you format your source code with evenly spaced tabs, pr eferably 8 spaces each, since this will lend consistency to assembly listings. The assemblers are not case sensitive (except in the instance of strings), so you may follow your own convention for using upper and lower case. 4.1.15 CVASM16 Error Messages During assembly, any syntax errors will be brought to your attention. © 2007 TechTools ClearView Assembler 143 You can pause an error list by typing CTRL-S; you can also press ESC or CTRL-C to abort the error list. The following error messages may occur during assembly. They will always be preceded by "ERROR filename xxx", where filename is the file and xxx is the line number where the error occurred. Address limit of xxxxh was exceeded: Data was assembled at an address which exceeded the limit for the given PIC. Attempt to divide by 0: An attempt was made to divide a quantity by zero. Bit number must be from 0 to 7: A bit-address expression attempted to use a bit number greater than 7. Data was already entered at location xxxxh: An object code location which had already been assigned data, was written to again. Equate directive must be preceded by a symbol: An "EQU" or "=" directive was not preceded by a necessary symbol. Illegal mnemonic: The assembler encountered an unknown directive or instruction. Include files cannot be nested: An INCLUDE directive was found in an included file. Syntax error in operand: The operand contained an expression which did not follow proper syntax. Invalid filename for include file: An invalid filename was given in an INCLUDE directive. Line cannot exceed 256 characters: Line length exceeded the line limit of 256 characters. Mnemonic field cannot exceed 7 characters: More than 7 characters were in the mnemonic (instruction) field. Illegal mnemonic/operand combination: The operand structure did not match the instruction’s or directive’s possibilities. © 2007 TechTools 144 PicTools Manual 3.0 Literal value must be from 0 to 0FFh: A value which needed to be from 0 to 255, was greater than 255. Operand field cannot exceed 256 characters: More than 256 characters were in the operand field after expansion by the assembler. Redefinition of symbol xxxx: An attempt was made to redefine a symbol that was already defined. Symbol field cannot exceed 32 characters: More than 32 characters were in the symbol field. (operand) symbol must contain only letters, numbers, ‘_’, and ‘:’: A symbol contained illegal characters. (operand) symbol is a reserved word: A symbol was identical to a reserved word. The symbols you define must not be reserved words. (operand) symbol is too long: A symbol referenced in the operand exceeded 32 characters. (operand) symbol must begin with a letter or ‘_’: A symbol started with an illegal character. Symbol table full: The symbol table’s 16K limit was exceeded. Use of unknown symbol xxxx: A symbol was referenced in the operand, which was never declared earlier in your program. 4.2 TechTools Instruction Set For a listing of the Microchip Instruction set and the equivalent CVASM16 instruction; see the next section, "Microchip to CVASM16 145 " ADD, ADDB 148 AND 150 CALL 151 CJA, CJAE 152 CJB, CJBE 153 © 2007 TechTools ClearView Assembler CJE 154 CJNE 155 CLR 156 CLRB, CLC, CLZ 157 CSA, CSAE 157 CSB, CSBE 159 CSE 160 CSNE 161 DEC, DECSZ, DJNZ 162 IJNZ, INC, INCSZ 163 JB, JC 164 JMP 164 JNB, JNC 165 JNZ, JZ 166 LCALL, LJMP, LSET 166 MOV [to register] 169 MOV [to OPTION] 169 MOV [to I/O Control] 171 MOV [to W] 172 MOV [using Expressions] MOVB 174 MOVSZ 175 NOP 175 NOT 176 OR 176 RET, RETW 178 RL, RR 179 SB, SC, SZ 179 SETB, STC, STZ 180 SKIP 181 SLEEP 181 SNB, SNC, SNZ 182 SUB, SUBB 183 SWAP 184 TEST 184 XOR 185 4.2.1 172 Microchip to CVASM16 This table is designed to help the CVASM16 user to understand source code written in Microchip format. It can also be a valuable reference when converting source to TechTools format. When doing this, keep in mind that CVASM16 will accept ALL of Microchip's instruction set, but not Microchip's directives and macros. f = File Register w = Working Register or "W" Microchip Description TechTools Equivalent ____________________________________________ Byte-oriented File Register operations ____________________________________________ ADDWF © 2007 TechTools f,0 Add f into w ADD 148 W,f 145 146 PicTools Manual 3.0 ADDWF ANDWF ANDWF CLRF CLRW COMF COMF DECF W,--f DECF DECFSZ W,--f DECFSZ INCF W,++f INCF INCFSZ W,++f INCFSZ IORWF IORWF MOVF MOVF MOVWF NOP RLF W,f RRF SUBWF W,f-W SUBWF SWAPF W,f SWAPF XORWF XORWF f,1 f,0 f,1 f 148 f,0 f,1 f,0 Add W into f And f into w And W into f Clear f Clear W Complement f, store in w Complement f, store in f Decrement f, store in w ADD AND AND CLR CLR MOV NOT MOV f,1 f,0 Decrement f, store in f Decrement f into w, skip if 0 DEC 162 MOVSZ 175 f,1 f,0 Decrement f into f, skip if 0 Increment f into w DECSZ 162 MOV 172 f,1 f,0 Increment f into f Increment f into w, skip if 0 INC 163 MOVSZ 175 f f,1 f,0 f,1 f,0 f,1 f INCSZ 163 OR 176 OR 176 MOV 172 TEST 184 MOV 169 NOP 175 MOV 172 f W,f f,W W,f f f,W f,0 Increment f into f, skip if 0 Or W and f into w Or W and f into f Move f into w Move f to itself Move W to f No operation Rotate f left w/carry, in w f,1 f,0 Rotate f left w/carry, in f Rotate f right w/carry, in w RL 179 MOV 172 f f,1 f,0 Rotate f right w/carry, in f Subtract W from f in w RR 179 MOV 172 f f,1 f,0 Subtract W from f in f Swap nibbles of f in w SUB MOV f,1 f,0 f,1 Swap nibbles of f in f Xor W and f in w Xor W and f in f SWAP 184 XOR 185 XOR 185 f W,f f,W CLRB 157 SETB 180 SNB 182 SB 179 bit bit bit bit 150 150 156 156 172 176 f,w W,f f,w f W W,/f f 172 172 f f f,W 172 __________________________________________ Bit-oriented File Register operations* __________________________________________ BCF BSF BTFSC BTFSS f,b f,b f,b f,b Bit Bit Bit Bit clear f set f test f, skip if clear test f, skip if set ____________________________________ Literal and Control operations ____________________________________ ADDLW W,#lit ANDLW W,#lit CALL addr8 lit Add literal into W lit And literal into W addr Call to address ('xx) ('5x) ADD 148 AND 150 CALL 151 © 2007 TechTools ClearView Assembler addr11 CLRWDT GOTO addr9 addr11 IORLW W,#lit MOVLW W,#lit OPTION !OPTION,W RETFIE RETLW RETURN SLEEP SUBLW W,#lit-W TRIS !port,W XORLW W,#lit addr Clear WDT and prescaler Go to address 151 ('xx) CALL CLR JMP 156 ('5x) ('xx) JMP 164 176 lit Or literal into W OR lit Move literal into W MOV 172 MOV 169 Move W into OPTION ('5x) lit Return from interrupt ('xx) Return with literal in W Return, clearing W ('5x) Return from subroutine ('xx) Clear WDT and enter sleep mode Subtract W from literal ('xx) RETI 178 RETW 178 RET 178 RET 178 SLEEP 181 MOV 172 port Move W into port's TRIS MOV 171 lit Xor literal into W XOR 185 lit ('5x) WDT 164 lit ____________________________________ Special Instructions ____________________________________ ADDCF ADDCF ADDDCF ADDDCF B addr9 addr11 BC addr9 addr11 BDC DC,addr9 DC,addr11 BNC addr9 addr11 BNDC DC,addr9 DC,addr11 BNZ addr9 addr11 BZ addr9 © 2007 TechTools f,0 f,1 f,0 f,1 k k k k k k k Add carry Add carry Add digit Add digit Branch to f, to f, carry carry store in w store in f to f,store to f,store ¹ ¹ in w ¹ in f ¹ ('5x) ADDCF ADDB 148 ADDDCF ADDB 148 JMP 164 ('xx) JMP ('5x) JC 164 ('xx) JC 164 ('5x) JB 164 ('xx) JB 164 ('5x) JNC 165 ('xx) JNC 165 Branch on No Digit Carry ¹ ('5x) JNB 165 ('xx) JNB 165 ('5x) JNZ 166 ('xx) JNZ 166 ('5x) JZ Branch on Carry ¹ Branch on Digit Carry ¹ Branch on No Carry ¹ Branch on No Zero ¹ Branch on Zero ¹ 164 166 f,0 f,C f,0 f,DC 147 148 PicTools Manual 3.0 addr11 CLRC CLRDC CLRZ LCALL addr11 addr13 LGOTO addr11 addr13 MOVFW NEGF NEGF SETC SETDC SETZ SKPC SKPDC SKPNC SKPNDC SKPNZ SKPZ SUBCF SUBCF f,C SUBDCF SUBDCF f,DC TSTF k k Clear Carry Clear Digit Carry Clear zero Long Call ¹ Long Goto ¹ 166 ('xx) JZ ('5x) CLC 157 CLRB 157 CLZ 157 LCALL 166 ('xx) LCALL ('5x) LJMP 166 ('xx) LJMP 166 DC 166 MOV 172 NEGF NEGF STC 180 SETB 180 STZ 180 SC 179 SB 179 SNC 182 SNB 182 SNZ 182 SZ 179 SUBCF SUBB 183 W,f f,0 f,1 f,0 f,1 Move f into W Negate f, store in w ¹ Negate f, store in f ¹ Set carry Set digit carry Set zero Skip if carry Skip if digit carry Skip if not carry Skip if not digit carry Skip if not zero Skip if zero Subtract carry from f, in w ¹ Subtract carry from f, in f ¹ f,0 f,1 Sub digit carry from f, in w ¹ Sub digit carry from f, in f ¹ SUBDCF SUBB 183 f,0 f Test TEST 184 f k f,0 f,1 f DC DC DC f,0 * (alternate for bit operand) bit = file register.bit ¹ multiple opcode instruction 4.2.2 ADD, ADDB ADD fr,#literal Words: 2 Add literal into fr Cycles: 2 Affects: W, C, DC, Z Operation: Literal is added into fr via W. C will be set if an overflow occurs; otherwise, C will be cleared. DC will be set or cleared depending on whether or not an overflow occurs in the lower nibble. Z will be set if the result is 0; otherwise, Z will be cleared. W is left holding the literal value. Coding: MOV W,#lit (MOVLW lit) ADD fr,W (ADDWF fr,1) © 2007 TechTools ClearView Assembler ADD fr1,fr2 Words: Add fr2 into fr1 2 Cycles: 2 Affects: W, C, DC, Z Operation: Fr2 is added into fr1 via W. C will be set if an overflow occurs; otherwise, C will be cleared. DC will be set or cleared depending on whether or not an overflow occurs in the lower nibble. Z will be set if the result is 0; otherwise, Z will be cleared. W is left holding the contents of frb. Coding: MOV W,fr2 (MOVF fr2,0) ADD fr1,W (ADDWF fr1,1) ADD fr,W Words: Add W into fr 1 Cycles: 1 Affects: C, DC, Z Operation: W is added into fr. C will be set if an overflow occurs, otherwise C will be cleared. DC will be set or cleared depending on whether or not an overflow occurs in the lower nibble. Z will be set if the result is 0, otherwise Z will be cleared. Coding: ADDWF ADD W,fr Words: 145 fr,1 Add fr into W 1 Cycles: 1 Affects: C, DC, Z Operation: Fr is added into W. C will be set if an overflow occurs, otherwise C will be cleared. DC will be set or cleared depending on whether or not an overflow occurs in the lower nibble. Z will be set if the result is 0, otherwise Z will be cleared. Coding: ADDWF ADDB fr,bit Words: fr,0 Add bit into fr 2 Operation: © 2007 TechTools 145 Cycles: 2 Affects: Z If bit is set, fr is incremented. If fr is incremented, Z will be set if the 149 150 PicTools Manual 3.0 result is 0; otherwise, Z will be cleared. This instruction is useful for adding the carry into the upper byte of a double-byte sum after the lower byte has been computed. Coding: SNC bit (BTFSC bit) INC fr 4.2.3 (INCF fr,1) AND AND fr,#literal Words: 2 Operation: will be cleared. AND literal into fr Cycles: 2 Affects: W, Z Literal is AND’d into fr via W. Z will be set if the result is 0; otherwise, Z Coding: MOV W,#lit (MOVLW lit) AND fr,W AND fr1,fr2 Words: (ANDWF fr,1) AND fr2 into fr1 2 Operation: will be cleared. Cycles: 2 Affects: W, Z Fr2 is AND’d into fr1 via W. Z will be set if the result is 0; otherwise, Z Coding: MOV W,fr2 (MOVF fr2,0) AND fr1,W (ANDWF fr1,1) AND fr,W Words: AND W into fr 1 Operation: cleared. Cycles: 1 Affects: Z W is AND’d into fr. Z will be set if the result is 0; otherwise, Z will be Coding: ANDWF 145 fr,1 © 2007 TechTools ClearView Assembler AND W,#literal Words: 1 AND literal into W Cycles: 1 Affects: Z Operation: Literal is AND’d into W. Z will be set to 1 if the result was 0, otherwise Z will be cleared to 0. Coding: ANDLW AND W,fr Words: literal AND fr into W into fr 1 Operation: be cleared to 0. Cycles: 1 Affects: Z Fr is AND’d into W. Z will be set to 1 if the result was 0, otherwise Z will Coding: ANDWF 4.2.4 145 145 fr,0 CALL CALL addr8 Words: Call subroutine ('5x) 1 Cycles: 2 Affects: none '5x Operation: The next instruction address is pushed onto the stack and addr8 is moved to the program counter bits 0-7(PC ). The 9th bit of the program counter will always be cleared. Therefore, calls are only allowed to the first half of any 512-word page. The CALL instruction can be anywhere, but the address being called MUST be an 8bit address. If the device you are targeting has more than 512 words of code space, you will need to load the page pre-select bits ( status 5,6) to the proper value before executing the CALL. See LCALL 166 , LSET 166 for '5x devices. Coding: CALL CALL addr11 Words: © 2007 TechTools 145 addr8 Call subroutine ('xx) 1 Cycles: 2 Affects: none 151 152 PicTools Manual 3.0 'xx Operation: The next instruction address is pushed onto the stack and addr11 is moved to the program counter bits 0-10 (PC ). The upper bits (11,12) of the program counter will be loaded from PCLATH (3,4). Therefore, it is up to the user to pre-load PCLATH with the correct values BEFORE a CALL is initiated. This can be done easily by using the LSET 166 instruction (for 'xx devices ) before CALL, or simply using the LCALL 166 instruction ( in place of CALL ), which will set the PCLATH bits for you. If your program appears to 'jump' to the wrong code page when executing a call, your PCLATH bits are probably incorrect. Coding: CALL 4.2.5 addr11 145 CJA, CJAE CJA fr,#literal,addr9 Compare fr to literal and jump if above Words: 4 Cycles: 4 or 5 (jump) Affects: C, DC, Z Operation: Fr is compared to literal via W. If fr is greater than literal, a jump to addr9 is executed. Coding: MOVLW literal^0FFh ADDWF CJA fr,0 BTFSC 3,0 GOTO addr9 fr1,fr2,addr9 Compare fr1 to fr2 and jump if above Words: 4 Operation: is executed. Cycles: 4 or 5 (jump) Fr1 is compared to fr2 via W. If fr1 is greater than fr2, a jump to addr9 Coding: MOVF fr1,0 SUBWF CJAE fr2,0 BTFSS 3,0 GOTO addr9 fr,#literal,addr9 Affects: W, C, DC, Z Compare fr to literal and jump if above or equal © 2007 TechTools ClearView Assembler Words: 4 Cycles: 4 or 5 (jump) Affects: C, DC, Z Operation: Fr is compared to literal via W. If fr is greater than or equal to literal, a jump to addr9 is executed. Coding: MOVLW SUBWF CJAE literal fr,0 BTFSC 3,0 GOTO addr9 fr1,fr2,addr9 Compare fr1 to fr2 and jump if above or equal Words: 4 Cycles: 4 or 5 (jump) Affects: C, DC, Z Operation: Fr1 is compared to fr2 via W. If fr1 is greater than or equal to fr2, a jump to addr9 is executed. Coding: MOVF fr2,0 SUBWF 4.2.6 fr1,0 BTFSC 3,0 GOTO addr9 CJB, CJBE CJB fr,#literal,addr9 Compare fr to literal and jump if below Words: 4 Operation: is executed. Cycles: 4 or 5 (jump) Fr is compared to literal via W. If fr is less than literal, a jump to addr9 Coding: MOVLW SUBWF CJB © 2007 TechTools literal fr,0 BTFSS 3,0 GOTO addr9 ad fr1,fr2,addr9 Affects: C, DC, Z Compare fr1 to fr2 and jump if below 153 154 PicTools Manual 3.0 Words: 4 Operation: executed. Cycles: 4 or 5 (jump) Fr1 is compared to fr2 via W. If fr1 is less than fr2, a jump to addr9 is Coding: MOVF fr2,0 SUBWF CJBE fr1,0 BTFSS 3,0 GOTO addr9b a fr,#literal,addr9 Words: 4 Affects: C, DC, Z Compare fr to literal and jump if below or equal Cycles: 4 or 5 (jump) Affects: C, DC, Z Operation: Fr is compared to literal via W. If fr is less than or equal to literal, a jump to addr9 is executed. Coding: MOVLW ADDWF CJBE literal fr,0 BTFSS 3,0 GOTO addr9 fr1,fr2,addr9 Compare fr1 to fr2 and jump if below or equal Words: 4 Cycles: 4 or 5 (jump) Affects: C, DC, Z Operation: Fr1 is compared to fr2 via W. If fr1 is less than or equal to fr2, a jump to addr9 is executed. Coding: MOVF fr1,0 SUBWF 4.2.7 fr2,0 BTFSS 3,0 GOTO addr9 CJE CJE fr,#literal,addr9 Compare fr to literal and jump if equal © 2007 TechTools ClearView Assembler Words: 4 Operation: executed. Cycles: 4 or 5 (jump) Fr is compared to literal via W. If fr is equal to literal, a jump to addr9 is Coding: MOVLW SUBWF CJE literal fr,0 BTFSC 3,2 GOTO addr9 fr1,fr2,addr9 Compare fr1 to fr2 and jump if equal Words: 4 Operation: executed. Cycles: 4 or 5 (jump) Affects: C, DC, Z Fr1 is compared to fr2 via W. If fr1 is equal to fr2, a jump to addr9 is Coding: MOVF fr2,0 SUBWF 4.2.8 Affects: C, DC, Z fr1,0 BTFSC 3,2 GOTO addr9 CJNE CJNE fr,#literal,addr9 Compare fr to literal and jump if not equal Words: 4 Cycles: 4 or 5 (jump) Affects: C, DC, Z Operation: Fr is compared to literal via W. If fr is not equal to literal, a jump to addr9 is executed. Coding: MOVLW SUBWF CJNE © 2007 TechTools literal fr,0 BTFSS 3,2 GOTO addr9 fr1,fr2,addr9 Compare fr1 to fr2 and jump if not equal 155 156 PicTools Manual 3.0 Words: 4 Cycles: 4 or 5 (jump) Operation: executed. Fr1 is compared to fr2 via W. If fr1 is not equal to fr2, a jump to addr9 is Coding: MOVF fr2,0 SUBWF 4.2.9 Affects: C, DC, Z fr1,0 BTFSS 3,2 GOTO addr9 CLR CLR fr Words: Clear fr 1 Cycles: 1 Operation: Coding: CLRF CLR W Words: Fr is cleared to 0. Z is set to 1. Clear W 1 Coding: CLRW WDT Words: fr 145 Operation: CLR Affects: Z Cycles: 1 Affects: Z W is cleared to 0. Z is set to 1. 145 Clear watchdog timer 1 Cycles: 1 Affects: TO, PD Operation: The watchdog timer is cleared, along with the prescaler, if assigned. TO and PD are set to 1. Coding: CLRWDT 145 © 2007 TechTools ClearView Assembler 4.2.10 CLRB, CLC, CLZ CLRB bit Words: Clear bit 1 Cycles: 1 Operation: Coding: BCF Affects: none Bit is cleared to 0. 145 bit Note: The TechTools assemblers define a bit as port.bitposition, as in the following examples: RA.3 = bit 3 of port A PortB.0 = bit 0 of port B CLC Clear carry Words: 1 Cycles: 1 Operation: Coding: BCF CLZ Affects: C C is cleared to 0. 145 3,0 Clear zero Words: 1 Cycles: 1 Operation: Coding: BCF Affects: Z Z is cleared to 0. 145 3,2 4.2.11 CSA, CSAE CSA fr,#literal Words: © 2007 TechTools 3 Compare fr to literal and skip if above Cycles: 3 or 4 (skip) Affects: C, DC, Z 157 158 PicTools Manual 3.0 Operation: Fr is compared to literal via W. If fr is greater than literal, the following instruction word is skipped. Coding: MOVLW ADDWF BTFSS literal fr,0 3,0 Note: Only one word is skipped by this instruction. To avoid strange results, make sure that any instruction following CSA is a single-word instruction. CSA fr1,fr2 Compare fr1 to fr2 and skip if above Words: 3 Cycles: 3 or 4 (skip) Affects: C, DC, Z Operation: Fr1 is compared to fr2 via W. If fr1 is greater than fr2, the following instruction word is skipped. Coding: MOVF fr1,0 SUBWF BTFSC fr2,0 3,0 Note: Only one word is skipped by this instruction. To avoid strange results, make sure that any instruction following CSA is a single-word instruction. CSAE fr,#literal Words: 3 Compare fr to literal and skip if above or equal Cycles: 3 or 4 (skip) Affects: C, DC, Z Operation: Fr is compared to literal via W. If fr is greater than or equal to literal, the following instruction word is skipped. Coding: MOVLW SUBWF BTFSS literal fr,0 3,0 Note: Only one word is skipped by this instruction. To avoid strange results, make sure that any instruction following CSAE is a single-word instruction. © 2007 TechTools ClearView Assembler CSAE fr1,fr2 Compare fr1 to fr2 and skip if above or equal Words: 3 Cycles: 3 or 4 (skip) Affects: C, DC, Z Operation: Fr1 is compared to fr2 via W. If fr1 is >= fr2, the following instruction word is skipped. Coding: MOVF fr2,0 SUBWF BTFSS fr1,0 3,0 Note: Only one word is skipped by this instruction. To avoid strange results, make sure that any instruction following CSAE is a single-word instruction. 4.2.12 CSB, CSBE CSB fr,#literal Words: 3 Compare fr to literal and skip if below Cycles: 3 or 4 (skip) Affects: C, DC, Z Operation: Fr is compared to literal via W. If fr is less than literal, the following instruction word is skipped. Coding: MOVLW SUBWF BTFSC literal fr,0 3,0 Note: Only one word is skipped by this instruction. To avoid strange results, make sure that any instruction following CSB is a single-word instruction. CSB fr1,fr2 Compare fr1 to fr2 and skip if below Words: 3 Cycles: 3 or 4 (skip) Affects: C, DC, Z Operation: Fr1 is compared to fr2via W. If fr1 is less than fr2, the following instruction word is skipped. © 2007 TechTools 159 160 PicTools Manual 3.0 Coding: MOVF fr2,0 SUBWF BTFSC fr1,0 3,0 Note: Only one word is skipped by this instruction. To avoid strange results, make sure that any instruction following CSB is a single-word instruction. CSBE fr,#literal Words: 3 Compare fr to literal and skip if below or equal Cycles: 3 or 4 (skip) Affects: C, DC, Z Operation: Fr is compared to literal via W. If fr is less than or equal to literal, the following instruction word is skipped. Coding: MOVLW ADDWF BTFSC literal fr,0 3,0 Note: Only one word is skipped by this instruction. To avoid strange results, make sure that any instruction following CSBE is a single-word instruction. CSBE fr1,fr2 Compare fr1 to fr2 and skip if below or equal Words: 3 Cycles: 3 or 4 (skip) Affects: C, DC, Z Operation: Fr1 is compared to fr2 via W. If fr1 is less than or equal to fr2, the following instruction word is skipped. Coding: MOVF fr1,0 SUBWF BTFSS fr2,0 3,0 Note: Only one word is skipped by this instruction. To avoid strange results, make sure that any instruction following CSBE is a single-word instruction. 4.2.13 CSE CSE fr,#literal Compare fr to literal and skip if equal © 2007 TechTools ClearView Assembler Words: 3 Cycles: 3 or 4 (skip) Affects: C, DC, Z Operation: Fr is compared to literal via W. If fr is equal to literal, the following instruction word is skipped. Coding: MOVLW SUBWF BTFSS literal fr,0 3,2 Note: Only one word is skipped by this instruction. To avoid strange results, make sure that any instruction following CSE is a single-word instruction. CSE fr1,fr2 Compare fr1 to fr2 and skip if equal Words: 3 Cycles: 3 or 4 (skip) Affects: C, DC, Z Operation: Fr1 is compared to fr2 via W. If fr1 is equal to fr2, the following instruction word is skipped. Coding: MOVF fr2,0 SUBWF BTFSS fr1,0 3,2 Note: Only one word is skipped by this instruction. To avoid strange results, make sure that any instruction following CSE is a single-word instruction. 4.2.14 CSNE CSNE fr,#literal Words: 3 Compare fr to literal and skip if not equal Cycles: 3 or 4 (skip) Affects: C, DC, Z Operation: Fr is compared to literal via W. If fr is not equal to literal, the following instruction word is skipped. Coding: MOVLW SUBWF BTFSC © 2007 TechTools literal fr,0 3,2 161 162 PicTools Manual 3.0 Note: Only one word is skipped by this instruction. To avoid strange results, make sure that any instruction following CSNE is a single-word instruction. CSNE fr1,fr2 Compare fr1 to fr2 and skip if not equal Words: 3 Cycles: 3 or 4 (skip) Affects: C, DC, Z Operation: Fr1 is compared to fr2 via W. If fr1 is not equal to fr2, the following instruction word is skipped. Coding: MOVF fr2,0 SUBWF BTFSC fr1,0 3,2 Note: Only one word is skipped by this instruction. To avoid strange results, make sure that any instruction following CSNE is a single-word instruction. 4.2.15 DEC, DECSZ, DJNZ DEC fr Words: Decrement fr 1 Operation: be cleared to 0. Coding: DECF DECSZ fr Words: Cycles: 1 Affects: Z Fr is decremented. Z will be set to 1 if the result was 0, otherwise Z will fr,1 145 Decrement fr and skip if zero 1 Operation: result was 0. Cycles: 1 or 2 (skip) Affects: none Fr is decremented. The next instruction word will be skipped if the Coding: DECFSZ 145 fr,1 © 2007 TechTools ClearView Assembler Note: Only one word is skipped by this instruction. To avoid strange results, make sure that any instruction following DECSZ is a single-word instruction. DJNZ fr,addr9 Decrement fr and jump if not zero Words: 2 Cycles: 2 or 3 (jump) Operation: Affects: none Fr is decremented. If the result is not 0, a jump to addr9 is executed. Coding: DECFSZ fr,1 GOTO addr9 4.2.16 IJNZ, INC, INCSZ IJNZ fr,addr9 Increment fr and jump if not zero Words: 2 Cycles: 2 or 3 (jump) Operation: Affects: none Fr is incremented. If the result is not 0, a jump to addr9 is executed. Coding: INCFSZ fr,1 GOTO addr9 INC fr Words: Increment fr 1 Operation: cleared. Coding: INCF INCSZ fr Words: Affects: Z Fr is incremented. Z will be set if the result was 0, otherwise Z will be 145 fr,1 Increment fr and skip if zero 1 Operation: © 2007 TechTools Cycles: 1 Cycles: 1 or 2 (skip) Affects: none Fr is incremented. The next instruction word will be skipped if the result 163 164 PicTools Manual 3.0 was 0. Coding: INCFSZ 145 fr,1 Note: Only one word is skipped by this instruction. To avoid strange results, make sure that any instruction following INCSZ is a single-word instruction. 4.2.17 JB, JC JB bit,addr9 Words: Jump if bit 2 Cycles: 2 or 3 (jump) Operation: If bit is set, a jump to addr9 is executed. Coding: BTFSC JC bit GOTO addr9 addr9 Jump if carry Words: Affects: none 2 Cycles: 2 or 3 (jump) Operation: Affects: none If the carry bit is set, a jump to addr9 is executed. Coding: BTFSC 3,0 GOTO addr9 addr9 Jump to address 4.2.18 JMP JMP Words: 1 Cycles: 2 Affects: none Operation: The lower 9-bits of the literal addr9 is moved into the program counter. The upper bits of the Program counter are loaded from bits 3 & 4 of PCLATH. Coding: GOTO 145 addr9 © 2007 TechTools ClearView Assembler JMP PC+W Words: Jump to PC+W 1 Cycles: 2 Affects: C, DC, Z Operation: W+1 is added into the program counter. The 9th bit of the program counter is always cleared to 0, so the jump destination will be in the first 256 words of any 512-word page. This instruction is useful for jumping into lookup tables comprised of RETW data, or jumping to particular routines. The flags are set as they would be by an ADD instruction. Coding: ADDWF JMP W 145 2,1 Jump to W Words: 1 Cycles: 2 Affects: none Operation: W is moved into the program counter. The 9th bit of the program counter is always cleared to 0, so the jump destination will be in the first 256 words of any 512-word page. This instruction is useful for jumping into lookup tables comprised of RETW data, or jumping to particular routines. Coding: MOVWF 2 145 4.2.19 JNB, JNC JNB bit,addr9 Words: 2 Operation: Jump if not bit Cycles: 2 or 3 (jump) If bit reads 0, a jump to addr9 is executed. Coding: BTFSS GOTO Affects: none bit addr9 Note: The TechTools assemblers define a bit as port.bitposition, as in the following examples: RA.3 = bit 3 of port A PortB.0 = bit 0 of port B © 2007 TechTools 165 166 PicTools Manual 3.0 JNC addr9 Words: Jump if not carry 2 Operation: Cycles: 2 or 3 (jump) If C is 0, a jump to addr9 is executed. Coding: BTFSS GOTO Affects: none 3,0 addr9 4.2.20 JNZ, JZ JNZ addr9 Words: Jump if not zero 2 Operation: Cycles: 2 or 3 (jump) If Z is 0, a jump to addr9 is executed. Coding: BTFSS JZ 3,2 GOTO addr9 addr9 Jump if zero Words: 2 Operation: Cycles: 2 or 3 (jump) Affects: none If Z is 1, a jump to addr9 is executed. Coding: BTFSC GOTO Affects: none 3,2 addr9 4.2.21 LCALL, LJMP, LSET LCALL addr11 Long call ('5x) Words: 1-3 Cycles: 2-4 Affects: none '5x Operation: Depending on the device size, from zero to two BCF/BSF instructions will be assembled to point the page pre-select bits (STATUS 5,6) to addr11’s page. The bit set/clear instructions are followed by a CALL to addr8. Long calls can be made to any page, but the routine that is being called MUST be located in the lower half of that page. © 2007 TechTools ClearView Assembler 167 This is due to the fact that bit 9 of the program counter is ALWAYS cleared when processing a CALL instruction on '5x devices (see CALL 151 for '5x devices ). This instruction is only useful for PICs with more than 512 words. Coding: (BCF/BSF (BCF/BSF 3, 6) CALL addr8 3, 5) Note: Please note that LCALL does not set the page select bits upon returning to the calling routine. Therefore, your program must set these bits. This can be done using LSET $, which sets the page select bits to the current page. LCALL addr13 Long call ('xx) Words: 1-3 Cycles: 2-4 Affects: none 'xx Operation: Depending on the device size, from zero to two BCF/BSF instructions will be assembled to load the PCLATH bits to addr13’s page. The bit set/clear instructions are followed by a CALL to addr11. This instruction is only useful for PICs with more than 2K words. Coding: (BCF/BSF (BCF/BSF 0A , 4) CALL addr11 0A ,3) Note: Please note that LCALL does not set the PCLATH bits upon returning to the calling routine. Therefore, your program must set these bits. This can be done using LSET $, which sets the page select bits to the current page. LJMP addr11 Long jump ('5x) Words: 1-3 Cycles: 2-4 Affects: none '5x Operation: Depending on the device size, from zero to two BCF/BSF instructions will be assembled to point the page pre-select bits (STATUS 5,6) to addr11’s page. The bit set/clear instructions are followed by a jump to addr8. This instruction is only useful for PICs with more than 512 words. Coding: (BCF/BSF (BCF/BSF © 2007 TechTools 3, 6) 3, 5) 168 PicTools Manual 3.0 GOTO addr8 LJMP addr13 Long jump ('xx) Words: 1-3 Cycles: 2-4 Affects: none 'xx Operation: Depending on the device size, from zero to two BCF/BSF instructions will be assembled to load the PCLATH bits to addr13’s page. The bit set/clear instructions are followed by a jump to addr11. This instruction is only useful for PICs with more than 2K words. Coding: (BCF/BSF (BCF/BSF 0A ,3) 0A , 4) GOTO addr11 LSET addr11 Long set ('5x) Words: 0-2 Cycles: 0-2 Affects: none '5x Operation: Depending on the device size, from zero to two BCF/BSF instructions will be assembled to point the page pre-select bits (STATUS 5,6) to addr11’s page. This instruction is only useful for PICs with more than 512 words. Coding: (BCF/BSF (BCF/BSF LSET 3, 5) 3, 6) addr13 Long set ('xx) Words: 0-2 Cycles: 0-2 Affects: none 'xx Operation: Depending on the device size, from zero to two BCF/BSF instructions will be assembled to load the PCLATH bits to addr13’s page. This instruction is only useful for PICs with more than 2K words. Coding: (BCF/BSF (BCF/BSF 0A ,3) 0A , 4) © 2007 TechTools ClearView Assembler 4.2.22 MOV [to register] MOV fr,#literal Words: 2 Operation: Move literal into fr Cycles: 2 Literal is moved into fr via W. Coding: MOVLW MOVWF MOV Affects: none literal fr fr1,fr2 Move fr2 into fr1 Words: 2 Cycles: 2 Affects: Z Operation: Fr2 is moved into fr1 via W. Z will be set to 1 if the value moved was 0, otherwise Z will be cleared to 0. Coding: MOVF fr2,0 MOVWF MOV fr,W Words: fr1 Move W into fr 1 Operation: Cycles: 1 Affects: none W is moved into fr. Coding: MOVWF 145 fr 4.2.23 MOV [to OPTION] NOTE: Since the OPTION register on 'xx devices is readable and writable, it can be accessed as a normal File Register. To maintain upward compatibility with future devices, these instructions should not be used when coding for 'xx devices. MOV !OPTION,#literal Words: © 2007 TechTools 2 Move literal into OPTION Cycles: 2 Affects: none 169 170 PicTools Manual 3.0 Operation: Literal is moved into OPTION via W. Coding: MOVLW literal OPTION Note: On 16C5x parts, you must use the explanation mark (!) before the word OPTION; this causes the assembler to assemble an OPTION instruction. On 16Cxx parts, the mark (!) is optional. Microchip added an OPTION register to the newer parts, so a regular MOV is possible, as long as your program is in the proper bank (usually bank 1). Microchip may remove the OPTION instruction in newer PICs, so they recommend against using the ‘ ! ’ MOV !OPTION,fr Words: 2 Move fr into OPTION Cycles: 2 Affects: Z Operation: Fr is moved into OPTION via W. Z will be set to 1 if the value moved was 0, otherwise Z will be cleared to 0. Coding: MOVF fr,0 OPTION Note: On 16C5x parts, you must use the explanation mark (!) before the word OPTION; this causes the assembler to assemble an OPTION instruction. On 16Cxx parts, the mark (!) is optional. Microchip added an OPTION register to the newer parts, so a regular MOV is possible, as long as your program is in the proper bank (usually bank 1). Microchip may remove the OPTION instruction in newer PICs, so they recommend against using the ‘ ! ’ MOV !OPTION,W Words: 1 Operation: Move W into OPTION Cycles: 1 Affects: none W is moved into OPTION. Coding: OPTION 145 Note: On 16C5x parts, you must use the explanation mark (!) before the word OPTION; this causes the assembler to assemble an OPTION instruction. On 16Cxx parts, the mark (!) is optional. Microchip added an OPTION register to the newer parts, so © 2007 TechTools ClearView Assembler 171 a regular MOV is possible, as long as your program is in the proper bank (usually bank 1). Microchip may remove the OPTION instruction in newer PICs, so they recommend against using the ‘ ! ’ 4.2.24 MOV [to I/O Control] NOTE: Since TRIS registers on 'xx devices are readable and writable, they can be accessed as a normal File Register. To maintain upward compatibility with future devices, the " ! " qualifier should not be used when coding for 'xx devices. MOV !port_fr,#literal Move literal into port_fr’s I/O control register Words: 2 Cycles: 2 Affects: none Operation: Literal is moved into the I/O control register of port_fr via W. A "1" bit in W disables the corresponding port pin’s output buffer, allowing input use, while a "0" bit enables the output buffer for high or low output. Port_fr must be (at Address) 5, 6, or 7. Coding: MOVLW TRIS MOV !port_fr,fr Words: 2 literal port_fr Move fr into port_fr’s I/O control register Cycles: 2 Affects: Z Operation: Fr is moved into the I/O control register of port_fr via W. A "1" bit in W disables the corresponding port pin’s output buffer, allowing input use, while a "0" bit enables the output buffer for high or low output. Z will be set to 1 if the value moved was 0, otherwise Z will be cleared to 0. Port_fr must be (at Address) 5, 6, or 7. Coding: MOVF fr,0 MOV TRIS port_fr6 !port_fr,W Move W into port_fr’s I/O control register Words: 1 Cycles: 1 Affects: none Operation: W is moved into the I/O control register of port_fr. A "1" bit in W disables the corresponding port pin’s output buffer, allowing input use, while a "0" bit enables the output buffer for high or low output. Port_fr must be (at Address) 5, 6, or 7. © 2007 TechTools 172 PicTools Manual 3.0 Coding: TRIS port_fr 145 4.2.25 MOV [to W] MOV W,#literal Words: 1 Operation: Move literal into W Cycles: 1 Literal is moved into W. Coding: MOVLW MOV W,fr Words: Affects: none 145 literal Move fr into W 1 Cycles: 1 Affects: Z Operation: Fr is moved into W. Z will be set to 1 if the value moved was 0, otherwise Z will cleared to 0. Coding: MOVF 145 fr,0 4.2.26 MOV [using Expressions] MOV W,/fr Words: Move not fr into W 1 Cycles: 1 Affects: Z Operation: The one’s complement of fr is moved into W. Z will be set to 1 if the result was 0, otherwise Z will cleared to 0. Coding: COMF MOV 145 fr,0 W,fr-W Move fr-W into W Words: 1 Cycles: 1 Affects: C, DC, Z Operation: W is subtracted from fr and the result is stored in W. C will be cleared to 0 if an underflow occurred, otherwise C will be set to 1. DC will be cleared or set © 2007 TechTools ClearView Assembler depending on whether or not an underflow occurred in the least-significant nibble. Z will be set to 1 if the result was 0, otherwise Z will be cleared to 0. Coding: SUBWF MOV fr,0 145 W,++fr Move the incremented value of fr into W Words: 1 Cycles: 1 Affects: Z Operation: The incremented value of fr is moved into W. Z will be set to 1 if the result was 0, otherwise Z will be cleared to 0. Coding: INCF MOV W,--fr Words: fr,0 145 Move the decremented value of fr into W 1 Cycles: 1 Affects: Z Operation: The decremented value of fr is moved into W. Z will be set to 1 if the result was 0, otherwise Z will be cleared to 0. Coding: DECF MOV fr,0 145 W,fr Move the right-rotated value of fr into W Words: © 2007 TechTools 145 1 Cycles: 1 Affects: C 173 174 PicTools Manual 3.0 Operation: The right-rotated value of fr is moved into W. On entry, C must hold the value to be shifted into the most-significant bit of the fr value. On exit, C will hold the previous least-significant bit of the fr value. Coding: RRF MOV fr,0 145 W,fr Move the nibble-swapped value of fr into W Words: 1 Operation: Coding: SWAPF Cycles: 1 Affects: none The nibble-swapped value of fr is moved into W. fr,0 145 4.2.27 MOVB MOVB bit1,bit2 Words: 4 Operation: Move bit2 to bit1 Cycles: 4 Affects: none Bit2 is moved to bit1. Coding: BTFSS bit2 BCF bit1 BTFSC bit2 BSF bit1 Note: The TechTools assemblers define a bit as port.bitposition, as in the following examples: RA.3 = bit 3 of port A MOVB bit1,/bit2 Words: 4 Operation: PortB.0 = bit 0 of port B Move not bit2 to bit1 Cycles: 4 Affects: none The complement of bit2 is moved to bit1. © 2007 TechTools ClearView Assembler 175 Coding: BTFSC bit2 BCF bit1 BTFSS bit2 BSF bit1 Note: The TechTools assemblers define a bit as port.bitposition, as in the following examples: RA.3 = bit 3 of port A PortB.0 = bit 0 of port B 4.2.28 MOVSZ MOVSZW,++fr Words: Move the incremented value of fr into W and skip if zero 1 Cycles: 1 or 2 (skip) Affects: none Operation: The incremented value of fr is moved into W. The next instruction word will be skipped if the result was 0. Coding: INCFSZ 145 fr,0 Note: Only one word is skipped by this instruction. To avoid strange results, make sure that any instruction following MOVSZ is a single-word instruction. MOVSZW,--fr Words: Move the decremented value of fr into W and skip if zero 1 Cycles: 1 or 2 (skip) Affects: none Operation: The decremented value of fr is moved into W. The next instruction word will be skipped if the result was 0. Coding: DECFSZ 145 fr,0 Note: Only one word is skipped by this instruction. To avoid strange results, make sure that any instruction following MOVSZ is a single-word instruction. 4.2.29 NOP NOP © 2007 TechTools No operation 176 PicTools Manual 3.0 Words: 1 Cycles: 1 Operation: Coding: NOP Affects: none none 145 4.2.30 NOT NOT fr Words: Not fr 1 Cycles: 1 Affects: Z Operation: Fr is converted into its one’s complement value. Z will be set to 1 if the result was 0, otherwise Z will be cleared to 0. Coding: COMF NOT W Words: 145 fr,1 Not W 1 Cycles: 1 Affects: Z Operation: W is converted into its one’s complement value. Z will be set to 1 if the result was 0, otherwise Z will be cleared to 0. Coding: XORLW 145 0FFh 4.2.31 OR OR fr,#literal Words: 2 OR literal into fr Cycles: 2 Affects: Z Operation: Literal is OR’d into fr via W. Z will be set to 1 if the result was 0, otherwise Z will be cleared to 0. Coding: MOVLW IORWF literal fr,1 © 2007 TechTools ClearView Assembler OR fr1,fr2 OR fr2 into fr1 Words: 2 Cycles: 2 Affects: Z Operation: Fr2 is OR’d into fr1 via W. Z will be set to 1 if the result was 0, otherwise Z will be cleared to 0. Coding: MOVF OR IORWF fr1,1 fr,W OR W into fr Words: OR fr2,0 1 Cycles: 1 Affects: Z Operation: be cleared to 0. W is OR’d into fr. Z will be set to 1 if the result was 0, otherwise Z will Coding: IORWF 145 W,#literal Words: 1 fr,1 OR literal into W Cycles: 1 Affects: Z Operation: Literal is OR’d into W. Z will be set to 1 if the result was 0, otherwise Z will be cleared to 0. Coding: IORLW OR W,fr Words: © 2007 TechTools 145 literal OR fr into W 1 Cycles: 1 Affects: Z Operation: be cleared to 0. Fr is OR’d into W. Z will be set to 1 if the result was 0, otherwise Z will Coding: IORWF 145 fr,0 177 178 PicTools Manual 3.0 4.2.32 RET, RETFI, RETW RET Return from subroutine Words: 1 Cycles: 2 Affects: none Operation: The next stack value is moved into the program counter. On '5x devices, W is cleared to 0. Coding: '5x 'xx RETLW RETURN RETI 145 0 145 Return from Interrupt Words: 1 Cycles: 2 Affects: none Operation: The next stack value is moved into the program counter. Interrupts are enabled by setting the Global Interrupt Enable bit, GIE (INTCON.7). Coding: 'xx RETFIE RETW literal1,literal2,... Words: ? 145 Assemble RET’s which load W with literal data Cycles: 2 per RETLW Affects: none Operation: A list of RET’s with literal data in the W area is assembled, which can be accessed by JMP PC+W or JMP W instructions. This is useful for lookup tables. Coding: RETLW 145 (RETLW literal2) (RETLW ...) Example: jmp pc+w literal1 ;Jump to byte at location pc+w retw 00100011b ;Return with w holding appropriate retw 00h,01h,02h,03h retw ’Enter cycle count’ ;value © 2007 TechTools ClearView Assembler 4.2.33 RL, RR RL fr Words: Rotate fr left 1 Cycles: 1 Affects: C Operation: Fr is rotated left. On entry, C must hold the value to be shifted into the least-significant bit of the fr value. On exit, C will hold the previous most-significant bit of the fr value. Coding: RLF RR fr Words: fr,1 145 Rotate fr right 1 Cycles: 1 Affects: C Operation: Fr is rotated right. On entry, C must hold the value to be shifted into the most-significant bit of the fr value. On exit, C will hold the previous least-significant bit of the fr value. Coding: RRF fr,1 145 4.2.34 SB, SC, SZ SB bit Words: Skip if bit 1 Cycles: 1 or 2 (skip) Affects: none Operation: If bit reads 1, the following instruction word is skipped. Coding: BTFSS 145 bit Note: Only one word is skipped by this instruction. To avoid strange results, make sure that any instruction following SB is a single-word instruction. Note: The TechTools assemblers define a bit as port.bitposition, as in the following examples: RA.3 = bit 3 of port A © 2007 TechTools PortB.0 = bit 0 of port B 179 180 PicTools Manual 3.0 SC Skip if carry Words: 1 Cycles: 1 or 2 (skip) Affects: none Operation: If C is 1, the following instruction word is skipped. Coding: BTFSS 145 3,0 Note: Only one word is skipped by this instruction. To avoid strange results, make sure that any instruction following SC is a single-word instruction. SZ Skip if zero Words: 1 Cycles: 1 or 2 (skip) Affects: none Operation: If Z is 1, the following instruction word is skipped. Coding: BTFSS 145 3,2 Note: Only one word is skipped by this instruction. To avoid strange results, make sure that any instruction following SZ is a single-word instruction. 4.2.35 SETB, STC, STZ SETB bit Words: Set bit 1 Cycles: 1 Operation: Coding: BSF Affects: none Bit is set to 1. 145 bit Note: The TechTools assemblers define a bit as port.bitposition, as in the following examples: RA.3 = bit 3 of port A PortB.0 = bit 0 of port B © 2007 TechTools ClearView Assembler STC 181 Set carry Words: 1 Cycles: 1 Operation: Coding: BSF Affects: C C is set to 1. 3,0 145 STZ Set zero flag Words: 1 Cycles: 1 Operation: Coding: BSF Affects: Z Z is set to 1. 3,2 145 4.2.36 SKIP SKIP Skip the following instruction word Words: 1 Cycles: 2 Affects: none Operation: The following instruction word is skipped. Coding: BTFSS 145 4,7 Note: Only one word is skipped by this instruction. To avoid strange results, make sure that any instruction following SKIP is a single-word instruction. 4.2.37 SLEEP SLEEP Words: Enter sleep mode 1 Cycles: 1 Affects: TO, PD Operation: The watchdog timer is cleared and the oscillator is stopped. TO is set to 1. PD is cleared to 0. Coding: SLEEP © 2007 TechTools 145 182 PicTools Manual 3.0 4.2.38 SNB, SNC, SNZ SNB bit Words: Skip if not bit 1 Cycles: 1 or 2 (skip) Affects: none Operation: If bit reads 0, the following instruction word is skipped. Coding: BTFSC 145 bit Note: Only one word is skipped by this instruction. To avoid strange results, make sure that any instruction following SNB is a single-word instruction. Note: The TechTools assemblers define a bit as port.bitposition, as in the following examples: RA.3 = bit 3 of port A SNC PortB.0 = bit 0 of port B Skip if not carry Words: 1 Cycles: 1 or 2 (skip) Affects: none Operation: If C is 0, the following instruction word is skipped. Coding: BTFSC 145 3,0 Note: Only one word is skipped by this instruction. To avoid strange results, make sure that any instruction following SNC is a single-word instruction. SNZ Skip if not zero Words: 1 Cycles: 1 or 2 (skip) Affects: none Operation: If Z is 0, the following instruction word is skipped. Coding: BTFSC 145 3,2 © 2007 TechTools ClearView Assembler Note: Only one word is skipped by this instruction. To avoid strange results, make sure that any instruction following SNZ is a single-word instruction. 4.2.39 SUB, SUBB SUB fr,#literal Words: 2 Subtract literal from fr Cycles: 2 Affects: C, DC, Z Operation: Literal is subtracted from fr via W. C will be cleared to 0 if an underflow occurred, otherwise C will be set to 1. DC will be cleared or set, depending on whether or not an underflow occurred in the least-significant nibble. Z will be set to 1 if the result was 0, otherwise Z will be cleared to 0. Coding: MOVLW literal SUBWF SUB fr,1 fr1,fr2 Subtract fr2 from fr Words: 2 Cycles: 2 Affects: C, DC, Z Operation: Fr2 is subtracted from fr1 via W. C will be cleared to 0 if an underflow occurred, otherwise C will be set to 1. DC will be cleared or set, depending on whether or not an underflow occurred in the least-significant nibble. Z will be set to 1 if the result was 0, otherwise Z will be cleared to 0. Coding: MOVF fr2,0 SUBWF SUB fr,W Words: fr1,1 Subtract W from fr 1 Cycles: 1 Affects: C, DC, Z Operation: W is subtracted from fr. C will be cleared to 0 if an underflow occurred, otherwise C will be set to 1. DC will be cleared or set, depending on whether or not an underflow occurred in the least-significant nibble. Z will be set to 1 if the result was 0, otherwise Z will be cleared to 0. Coding: SUBWF © 2007 TechTools 145 fr,1 183 184 PicTools Manual 3.0 SUBB fr,bit Words: Subtract bit from fr 2 Cycles: 2 Affects: Z Operation: If bit reads 0, fr is decremented. If fr was decremented, Z will be set to 1 if the result was 0, else Z will be cleared to 0. This instruction is useful for subtracting the carry from the upper byte of a double-byte value after the lower byte has been subtracted. Coding: BTFSS 3,0 DECF fr,1 Note: The TechTools assemblers define a bit as port.bitposition, as in the following examples: RA.3 = bit 3 of port A PortB.0 = bit 0 of port B 4.2.40 SWAP SWAP fr Words: Swap nibbles in fr 1 Cycles: 1 Operation: Affects: none The high- and low-order nibbles in fr are swapped. Coding: SWAPF 145 fr,1 4.2.41 TEST TEST fr Words: Test fr for zero 1 Cycles: 1 Affects: Z Operation: Fr is read and copied back to itself. Z will be set to 1 if the value moved was 0, otherwise Z will be cleared to 0. Coding: MOVF 145 fr,1 © 2007 TechTools ClearView Assembler TEST W Words: Test W for zero 1 Cycles: 1 Affects: Z Operation: Z will be set to 1 if W is 0, otherwise Z will be cleared to 0. Coding: IORLW 145 0 4.2.42 XOR XOR fr,#literal Words: 2 XOR literal into fr Cycles: 2 Affects: Z Operation: Literal is XOR’d into fr via W. Z will be set to 1 if the result was 0, otherwise Z will be cleared to 0. Coding: MOVLW XORWF XOR literal fr,1 fr1,fr2 XOR fr2 into fr1 Words: 2 Cycles: 2 Affects: Z Operation: Fr2 is XOR’d into fr1 via W. Z will be set to 1 if the result was 0, otherwise Z will be cleared to 0. Coding: MOVF XORWF XOR fr,W Words: fr1,1 XOR W into fr 1 Operation: be cleared to 0. © 2007 TechTools fr2,0 Cycles: 1 Affects: Z W is XOR’d into fr. Z will be set to 1 if the result was 0, otherwise Z will 185 186 PicTools Manual 3.0 Coding: XORWF XOR W,#literal Words: 1 Operation: be cleared. W,fr Words: Cycles: 1 Affects: Z Literal is XOR’d into W. Z will be set if the result was 0, otherwise Z will 145 literal XOR fr into W 1 Operation: be cleared to 0. Cycles: 1 Affects: Z Fr is XOR’d into W. Z will be set to 1 if the result was 0, otherwise Z will Coding: XORWF 4.3 fr,1 XOR literal into W Coding: XORLW XOR 145 145 fr,0 Sample Projects This Section contains three sample projects: · Simple Project 187 · Table Project 190 · Bargraph Project 194 These are not complex projects meant to show off the capabilities of PICs. Instead, they are designed to help new PIC users become familiar with PICs. The first two projects use the venerable PIC16C54, and show how to accomplish very simple tasks, such as monitoring a button and lighting an LED Display. The third project uses the more complex, and very popular, PIC16C74. This last project shows how to read an analog input and then display the result on an 8-segment bargraph. Each sample project is located in the APPS subdirectory of the TDE installation. After opening the project in TDE (Project->Open), you can select the Project option from the Setup menu to customize project settings. © 2007 TechTools ClearView Assembler 4.3.1 Simple.tpr PIC Project #1: "Simple.tpr" This project gives you a very simple introduction to the PIC. The PIC flashes an LED at one speed and then, if the button is pressed, speeds up the flashing. The PIC itself requires only two parts to operate: a resistor and capacitor to form its RC oscillator. The remaining four parts are the button, the LED, and their resistors. Before continuing, build the circuit shown below. Only seven parts are necessary, so the task shouldn’t be too laborious. If you don’t have exactly what’s called for, you can substitute a close match (the 4.7K resistor and 20 pF capacitor should not be substituted with smaller values, however). © 2007 TechTools 187 188 PicTools Manual 3.0 Note: When using the ClearView Mathias emulator, you can select any frequency from 32 KHz to 25 MHz using its programmable on-board oscillator. ( For this project we suggest using a frequency between 1 and 4 MHz. ) The following listing is the source code for the project Simple.tpr. It’s contained in a file called SIMPLE.SRC, which is located in the APPS subdirectory of the TDE installation. © 2007 TechTools ClearView Assembler ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; 189 PIC EXAMPLE PROGRAM: SIMPLE.SRC June 8, 1992 This 16-word program is a very simple PIC application. Its only purpose is to flash an LED at one of two rates. Normally, the LED flashes slowly. However, if bit 0 of port A (RA0) is grounded, the LED flashes roughly twice as fast. As the program is written, it expects to run on a PIC16C54-RC/P. A push button connects RA0 to ground (don’t forget a pull-up resistor from RA0 to Vdd, perhaps 10K). A current-limited LED is connected from RA1 to ground (330 ohms work well). For an oscillator, a 20 pF capacitor to ground and a 4.7K resistor to Vcc are connected to OSC1 (OSC2 is left open). RTCC and MCLR should be tied high. Lastly, power and ground are connected to Vdd and Vss, respectively. If you’re looking for a simple introduction to the PIC, this program should help. Among other things, it shows the following basic concepts: * * * * * Setting device options Setting the reset vector Setting I/O pins as inputs or outputs Using global labels Using local labels (see “:Loop” below) After you build the circuit described above, open the project file and select Run, the LED should start flashing as soon as TDE's status line displays "Running". ; START OF PROGRAM ; Set the device type, oscillator type, watchdog timer status, and code ; protect status DEVICE PIC16C54,RC_OSC,WDT_OFF,PROTECT_OFF RESET Count0 equ Count1 equ 10h 11h clr clr clr Start mov Start ;Set reset vector to address at Start ;(PIC will jump to this when reset) ;Assign labels to registers 10h & 11h Count0 Count1 RA ;Clear port before setting direction ;register !RA,#00000001b ;Set data direction register for port A ;(make bit 0 an input) ; ; Loop 65536 times, then invert the LED ; :Loop djnz Count0,:Loop ;Decrement Count0 until it reaches zero djnz Count1,:Loop ;Decrement Count1. If it’s not zero, ;jump back to :Loop xor RA,#00000010b ;Invert the LED (bit 1 of port A) ; ; Check button status. If it’s pressed, skip the additional delay and jump ; back to the first loop ; ChkBtn jnb © 2007 TechTools RA.0,Start:Loop ;Jump to 1st loop if button is pressed 190 PicTools Manual 3.0 ;(button is low when pressed) :Loop djnz Count0,:Loop ;Decrement Count0 until it reaches zero djnz Count1,:Loop ;Decrement Count1. If it’s not zero, ;jump back to :Loop jmp Start:Loop ;Jump back to first loop The first step is to assemble the source code into hex code. To assemble the program, click the Build button on the menu bar or select the build option from the Run menu. If the assembler finds any errors, it will give the line number and description of each error. Before continuing, you’ll need to correct any errors and reassemble the program (of course, this should not occur, unless you typed the program yourself and perhaps made a typo). If the program assembles correctly, the assembler will produce a hex file, called SIMPLE.OBJ, in the Apps sub-directory. After running your program satisfactorily, you are ready to program your PIC with the HEX file : SIMPLE.OBJ. Once you have successfully programmed the PIC, you're ready to try it in your circuit. Make sure the power to your circuit is off, and then plug in the PIC. When you turn the power on, the LED should be flashing. If you push the button, the LED should blink more quickly. If your project appears "dead", double-check the circuit (power, RC oscillator, connections, etc). 4.3.2 Table.tpr PIC Project #2: "Table.tpr" Like the first project, this project gives you a simple introduction to the PIC. But, it also demonstrates the useful topics of how to debounce push button inputs and how to make a lookup table. The schematic below shows the circuit. Whenever the button is pressed, the value shown on the 7-segment display increments. © 2007 TechTools ClearView Assembler The PIC itself requires only two parts to operate: a resistor and capacitor to form its RC oscillator. The remaining four parts are the button, the 7-segment display (common cathode), a 10K resistor, and a resistor pack (330-ohm, 8 isolated resistors). Note: When using the ClearView Mathias emulator, you can select any frequency from 32 KHz to 25 MHz using its programmable on-board oscillator. ( For this project we suggest using a frequency between 1 and 4 MHz. ) The following listing is the source code for the project Table.tpr. It’s contained in a file called TABLE.SRC, which is located in the APPS sub-directory of the PIC Tools Diskette. © 2007 TechTools 191 192 PicTools Manual 3.0 ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; PIC EXAMPLE PROGRAM: TABLE.SRC August 19, 1992 This 44-word program is a simple PIC application that shows some useful routines. Its purpose is to monitor a button and display a digit on a 7-segment display. When the button is pressed, the digit increments. As the program is written, it expects to run on a PIC16C54-RC/P. A push button connects RA0 to ground (don’t forget a pull-up resistor from RA0 to Vcc, perhaps 10K). A 7-segment display (common cathode) is connected to port B (segment A to bit 0, segment B to bit 1, etc.). For an oscillator, a 20 pF capacitor to ground and a 4.7K resistor to Vcc are connected to OSC1 (OSC2 is left open). RTCC and MCLR should be tied high. Lastly, power and ground are connected to Vdd and Vss, respectively. Among other things, this program shows the following basic concepts: * * * * * * Setting device options Setting the reset vector Setting I/O pins as inputs or outputs Using labels Debouncing a push button input Reading from a lookup table If you build the circuit as described above, the display should show a “0” when you select t ; START OF PROGRAM ; Set the device type, oscillator type, watchdog timer status, and code ; protect status DEVICE RESET PIC16C54,RC_OSC,WDT_OFF,PROTECT_OFF Start ;Set reset vector to address at Start ;(PIC will jump to this when reset) Count0 equ Count1 equ Number equ 10h 11h 12h ;Register labels Flag Button equ Display equ RA.0 equ 13h.0 Start clr clr clr clr Number Flag RA RB mov !RA,#00000001b ;Set data direction register for port A ;(make bit 0 an input) mov !RB,#00000000b ;Set data direction register for port B ;(make all bits outputs) mov W,Number call mov GetPattern Display,W ;Get bit pattern for digit ;Show digit jnb Flag,UpLoop ;If flag is clear, check for 2048 reads RB ;Bit label (bit 0 of register 13h) ;Port labels (bit 0 of port A) ;(entire port) ; Main loop Digit ;Move Number into W © 2007 TechTools ClearView Assembler 193 ;of button not pressed jb Button,Digit ;Jump if flag set, but button not ;pressed ; If button pressed after not being pressed for 2048 reads, then increment number Clear clr inc cjne Number ;Increment number Number,#10,Clear clr Number Flag jmp Digit ;If Number reached 10, reset to 0 ; Set flag if button not pressed for 2048 reads. Faster oscillator speeds ; may require more than 2048 reads to properly debounce button inputs. UpLoop clr Count0 mov Count1,#08 Loop jnb djnz djnz setb jmp Button,Digit ;If button pressed before 2048 reads, Count0,Loop ;jump back to main loop Count1,Loop Flag ;Set flag if button not pressed Digit ; 7-segment lookup table GetPattern ; jmp PC+W ;Jump to appropriate bit pattern, ;load W with pattern, and then return ;to calling routine. retw retw retw retw 3Fh,06h,5Bh 4Fh,66h,6Dh 7Dh,07h,7Fh 6Fh retw ’This is text’ ;Sample text lookup table (not used by ;this program) ;Bit patterns for digits 0-9 The first step is to assemble the source code into hex code by selecting Build from TDE's Run menu. If the assembler finds any errors, it will give the line number and description of each error. Before continuing, you’ll need to correct any errors and re-assemble the program (of course, this should not occur, unless you typed the program yourself and perhaps made a typo). If the program assembles correctly, the assembler will produce a hex file, called TABLE.OBJ, in the APPS directory. You can now select Run, and your circuit will operate as if you had already inserted a programmed PIC. © 2007 TechTools 194 PicTools Manual 3.0 Once everything is operating to your satisfaction, you can program your PIC with the HEX file : TABLE.OBJ. Once you have programmed the PIC, you're ready to try it in your circuit. Make sure the power to your circuit is off, and then plug in the PIC. When you turn the power on, the display should show "0". If you push the button, the value on the display should increment. If your project appears "dead", double-check the circuit (power, RC oscillator, connections, etc). 4.3.3 Bargraph.tpr PIC Project #3: "Bargraph.tpr" This project is relatively simple, but it uses the more complex PIC16C74. The ’74 has many good features, which have made it a popular device. This project demonstrates how to read a single analog input and then display the result on an 8-segment LED bargraph. The schematic below shows the circuit. The PIC itself requires just three parts to operate: a 4-MHz crystal and two capacitors to form its oscillator. The remaining three parts are a 10K potentiometer, a 330-ohm resistor, and an 8-segment LED bargraph (common anode). © 2007 TechTools ClearView Assembler Note: When using the ClearView Mathias emulator, you can select any frequency from 32 KHz to 25 MHz using its programmable on-board oscillator. ( For this project we suggest using a frequency of 4 MHz. ) The following listing is the source code for the project. It’s contained in a file called BARGRAPH.SRC, which is located in the APPS directory of the PIC Tools Diskette. ; ; ; ; ; ; ; ; ; ; ; ; ; ; SAMPLE PROGRAM: BARGRAPH.SRC February 9, 1996 This program uses a PIC16C74 to convert an analog value into a reading on an 8-segment LED bargraph. The analog input is connected to AN0 (pin 2) on the ’74. The LEDs are active-low, and are connected to Port B (pin 33 is first LED, pin 34 is second LED, etc). The program is written to only light one LED at a time, but could easily be changed to light multiple LEDs (all LEDs up to the reading). Having only one LED on insures low current draw, which may be important if you’re powering the circuit with an emulator. DEVICE PIC16C74,WDT_OFF,XT_OSC © 2007 TechTools 195 196 PicTools Manual 3.0 Value Count equ equ Init Main Check Loop Leds jb 20h 21h ;Define two bytes for later use org jmp 000h Init ;Set up reset vector at location 000h ;On reset, jump to beginning of program org 005h ;Program must begin at/after location 005h setb mov mov mov clrb RP0 ADCON1,#00h TRISA,#0FFh TRISB,#00h RP0 ;Switch to register bank 1 ;Make port A all analog ;Make port A all inputs ;Make port B all outputs ;Switch back to register bank 0 mov setb ADCON0,#00h ADCON0.0 ;Set ADC channel, conversion speed, etc. ;Activate ADC setb ADCON0.2 ADCON0.2,Check mov Value,ADRES ;Start analog conversion ;Loop until conversion done ;Copy analog value into Value clc rr clc rr clc rr clc rr clc rr ;Divide Value by 32. ;analog readings of 0-255. Value Gives 0-7 for Value Value Value Value mov cje clc rl dec jmp Count,#01h Value,#00h,Leds ;Start Count at first bit position (bit 0) ;Jump if Value is 0 Count Value Loop ;Rotate Count left one bit ;Decrement Value ;Loop until Value is 0 xor mov Count,#0FFh PortB,Count ;LEDs are active-low, so invert Count ;Output Count on port B LEDs jmp Main ;Repeat the process The first step is to assemble the source code into hex code. To assemble the program, choose Build from TDE's Run menu. If the assembler finds any errors, it will give the line number and description of each error. Before continuing, you’ll need to correct any errors and re-assemble the program (of course, this should not occur, unless you typed the program yourself and perhaps made a typo). If the program assembles correctly, the assembler will produce a hex file, called BARGRAPH.OBJ, in the APPS directory. You can now select Run, and your circuit will operate as if you had already inserted a © 2007 TechTools ClearView Assembler programmed PIC. Once everything is operating to your satisfaction, you can program your PIC with the HEX file : BARGRAPH.OBJ. Once you have programmed the PIC, you're ready to try it in your circuit. Make sure the power to your circuit is off, and then plug in the PIC. When you turn the power on, any one of the LEDs might be turned on, depending upon the position of the potentiometer. If you turn the potentiometer, then you should see a corresponding change on the LEDs. For a quick test, you can also just connect the analog input to GND or to +5V, in which case the first or last LED should turn on. If your project appears "dead", double-check the circuit (power, RC oscillator, connections, etc). © 2007 TechTools 197 ClearView Mathias Hardware Part V ClearView Mathias Hardware 5 ClearView Mathias Hardware · · · · · · · · 5.1 ClearView Mathias 199 System Requirements 200 Packing List 200 Hardware Features 201 Hardware Installation 201 Power Supply Considerations MCLR Pull-Up Resistor 204 Optional Modules 205 203 ClearView Mathias ClearView Mathias is an in-circuit emulator for PIC16Cxx micro-controllers. It plugs in place of a PIC in a target circuit, and allows you to run your code in-circuit at full hardware speeds. ClearView Mathias supports full debugging features, such as stepping, breakpoints, register modification, and trace. These features allow you to see and affect the internal operation of the PIC, while it executes code. ClearView Mathias supports 16C5x and 16Cxx parts. This is accomplished through the use of modules that select the family (5x/xx) and family "member" (16C54, 16C57, © 2007 TechTools 199 200 PicTools Manual 3.0 16C74, 16F877, etc). The use of modules allows us to keep the emulator affordable, while still offering the options people want. If you started with the 5x module, for instance, you can later add 16C74 support without spending too much. 5.2 System Requirements To use ClearView Mathias, you will need the following items: · · · · · · 5.3 IBM AT or compatible computer with mouse VGA or higher Display CDROM drive Serial port 2 megabytes of RAM (minimum + O/S requirements) Windows 9x, NT, 2000, XP, XPpro Packing List The ClearView package should contain the following items. If any are missing, please let us know. 1. ClearView Mathias base unit 2. 1 or more PIC family modules (5x or xx family module) as ordered. 3. 1 or more PIC member modules (5x, 61, 74, 84, etc...) as ordered. 4. Trace buffer module (optional) 5. Timing module (optional) 6. 18-pin ribbon cable 7. 28-pin ribbon cable 8. 40-pin ribbon cable 9. Serial cable (DB-9 male to DB-9 female) 10.DB25 to DB9 serial adapter 11.Power supply * 12.TechTools CDROM 13.PIC16Cxx Development Tools Manual (this manual) * Power supplies are only shipped with orders to the United States, Canada, and Japan. If your order was shipped to another country, you will need to obtain a power supply with the proper output voltage and current: 7-8 VDC, 500 mA ( outer conductor = Ground ) © 2007 TechTools ClearView Mathias Hardware 5.4 Hardware Features Power Jack: Accepts power from power supply 203 (7-8 VDC, 500 mA). Status LED: Red when emulation is stopped, green when running. Also used in power-up test sequence: green when power is applied, red when unit is ready to use. Trace Buffer Slot: Connector for optional trace buffer and timing modules 205 . Member Module Connector: Connector for PIC member module. Provides emulation for specific PIC (5x, 61, 71, 84, etc). Family Module Slot: Connector for PIC family module. Family module determines if ClearView will emulate 16C5x (12 bit core) or 16Cxx (14 bit core) parts. DB-9 Connector (female): Connects to PC serial port. 5.5 Hardware Installation To install ClearView, follow these steps: © 2007 TechTools 201 202 PicTools Manual 3.0 1) If you purchased the optional trace buffer module or timing module, plug it into ClearView’s trace buffer slot. When plugged in properly, the components on the module should face the words "ClearView Mathias" on the emulator. 2) Plug a "5x" or "xx" family module into ClearView’s family module slot. As with the trace buffer module, the components on the module should face the words "ClearView Mathias." 3) Plug a PIC member module into the right side of the emulator. If the member module is for "5x" PICs, then you must have a "5x" family module plugged into the family slot (see step #2). If the member module is for any "xx" PIC (61, 71, 84,...), then you must have an "xx" module plugged into the family slot. 4) Plug an appropriate ribbon cable onto the member module. The module will have connectors for 18-, 28-, and/or 40-pin cables. The type of cable used will depend on which PIC you plan to emulate (for 16C61, an 18-pin cable; for 16C73, a 28-pin cable; etc). © 2007 TechTools ClearView Mathias Hardware 5) Plug the power supply into an AC outlet. 6) Plug the power supply cord into ClearView’s power jack. The LED on ClearView should be green when power is applied. After a few seconds of internal testing, the LED should change to red; this indicates that the unit is in emulation mode, but that execution is stopped. 7) Plug the female end of the serial cable into an available serial port on your PC. If your serial port has a DB-25 connector, you’ll need to use a DB-25 to DB-9 adapter. 8) Plug the male end of the serial cable into ClearView’s DB-9 connector. Your ClearView should now be ready to use. If you need to change any of the plug-in modules, please be sure to disconnect any power source before making the change. Failure to disconnect power before replacing modules can result in damage to the modules, emulator, and/or target circuit. 5.6 Power Supply Considerations Every Mathias Member Module provides a simple jumper which may be used to short the power plane of both emulator and target together. This may be useful if you need to power a small target circuit from the emulator, or if you want to power the emulator from the target circuit. In either case, please note the following current limitations and requirements: when powering a target circuit, the emulator cannot provide more than approximately 50 mA; conversely, when powering the emulator from a target circuit, the emulator needs approximately 500 mA. © 2007 TechTools 203 204 PicTools Manual 3.0 To power target circuit from emulator or to power emulator from target circuit: (power supplies connected) To connect the power planes of both devices together, insert the power jumper in the position on the right. If both systems are connected and providing power, damage to the emulator and/or target circuit may result. To power each device independently: (power supplies not connected) To power the emulator and target independently, isolate their power planes. Either remove the jumper or store it in the left position. 5.7 MCLR Pull-Up Resistor ClearView Mathias has a 100K pull-up resistor on the MCLR input. This ensures that the MCLR input will be inactive when it’s not specifically driven low, thus preventing random resets of the emulated PIC. © 2007 TechTools ClearView Mathias Hardware 5.8 205 Optional Modules As mentioned in the hardware installation text, there are two optional modules for ClearView Mathias; these modules are described below: Trace Buffer Module: This module keeps a record of each instruction executed by the emulator. For each instruction, the record shows the location in the trace buffer memory, the value of the program counter, the state of external trace inputs, and the original line of source code. The trace module also provides information about how many cycles and how much time is taken by each instruction. The trace buffer memory is 16K "deep," resulting in a capacity of approximately 16,384 Microchip instructions. Some instructions, such as JMP and GOTO, take two processor cycles, and therefore take two locations in the trace buffer memory. In addition, some TechTools instructions utilize two or three Microchip instructions, and will therefore take multiple locations in the trace buffer (this is also true of high-level compiled languages, such as C). On the hardware side, the trace buffer adds eight external trace inputs. The status of the eight trace inputs is recorded along with each instruction in the trace buffer. By connecting these inputs to your circuit, you can record the activity of your circuit as it relates to the emulated PIC. In addition to eight trace inputs, the trace module adds one more signal: an external break input. This input acts like an interrupt, and may be connected to your circuit. If the external break input transitions from high to low, then the emulator will halt execution. Please note, however, that it takes the emulator two or three cycles to react to an external break. This is because it takes one or two cycles to recognize the input, and another cycle to halt the emulator (to be recognized in the first instruction cycle, the break input must be valid at least 60ns before the start of the cycle). The hardware inputs described above are present on the trace input header, which is found on every PIC member module 201 . A pin-out of this header is shown below: © 2007 TechTools 206 PicTools Manual 3.0 The trace buffer module includes micro-grabber test leads which can be attached to the trace header on any of our member modules. Timing Module: This module is a subset of the trace module; it provides execution cycle and time information, just like the trace module. However, the timing module does not include any of the other trace functions (execution history, external inputs, etc). Since it does not support any external inputs, the timing module does not include a 14-conductor cable. The timing module is much less expensive than the trace module, and many customers are happy with the functions it provides. © 2007 TechTools Index G 17 H 9 N 17 O 6 S 15 Alt+R R 19 S 17 analog input 194 AND 150 AND fr2 into fr1 150 AND literal into fr 150 AND literal into W 150 AND W into fr 150 ANDLW 145 ANDWF 150 Animate 74 Animate Over Execution 74 Animation 36 Animation Step Delay 62 Animation-Mode Execution 74 Any Data 121 Assemble RET’s which load W with literal assembler 126 Auto Backup 62 Auto Increment 17 Auto Indent 62 Auto Load last Project 62 Auto Run 23 AutoRun 23 Index -!! 120 -..obj 5 .QWC 5 -77-segment display 190 -88-segment LED bargraph 194 -AADD 148 Add a Varible to the Watch Window 36 Add fr2 into fr1 148 Add literal into fr 148 Add W into fr 148 Add Watch button 108 Add Watch Selected 108 ADDB 148 ADDCF 145 ADDDCF 145 Adding a File 48 Adding Files 51 Adding items by Highlighting 108 Adding items from Source Code 108 Adding Items from the Variables Window ADDLW 145 ADDWF 145, 148, 164 Advanced 20 Alt+E I 13 S 17 W 15 Alt+O © 2007 TechTools -B- 108, 109 B 145 basic functions 27 baud rate 55 BC 145 BCF 145, 157 BDC 145 Beep on Errors 62 Beep on Stop 62 binary 97, 105, 112 Bit Pattern 121 bit-oriented file register operations 145 BNC 145 BNDC 145 BNZ 145 Bondouts and Speed Limitations 59 207 178 208 PicTools Manual 3.0 Break On 120 Break on Stack Over/Underflow 57 Break on Timeout 57 Breaking on data 124 Breakpoint 95 Breakpoints 78 BSF 145, 180 BTFSC 145, 182 BTFSS 145, 179, 181 BUILD 68, 131 Building the Project 32, 68 button 187 Bytecraft C 128 Bytecraft C to obj 128 Bytecraft LINKER 128 byte-oriented file register operations 145 BZ 145 -Ccable connector 23 Cable Pinout 20 call 145, 151, 190 Call subroutine 151 CCS 130 Changing the radix of items 115 Child Nodes 25 CJA 152 CJAE 152 CJB 153 CJBE 153 cje 154, 194 cjne 155, 190 clc 157, 194 Clear 156 Clear bit 157 Clear carry 157 Clear trace buffer 116 Clear W 156 Clear watchdog timer 156 Clear zero 157 Clearing All Breakpoints 78 clr 156, 187, 190 clrb 157, 194 CLRC 145 CLRDC 145 CLRF 145, 156 CLRW 145, 156 CLRWDT 145, 156 CLRZ 145 CLZ 157 COD 130, 131 COD ONLY 131 Code Protection 15 Code Window 95 com port 55 COMF 145, 172, 176 Command-line Operation 23 COMPILE TO OBJECT 127 COMPILE TO OBJECT MODE 128 compiler 126, 128, 129 Compiling and Executing Code 44, 68 Configuration Word 15 control file 14 Copy 85 Creating a Multiple-file Project 50 Creating a Single-file Project 46 CSA 157 CSAE 157 CSB 159 CSBE 159 CSE 160 CSNE 161 Ctl+R 19 Ctrl-C 85 Ctrl-F 89 Ctrl-F9 78 Ctrl-V 85 Ctrl-X 85 Ctrl-Z 88 current execution line 62 Current Line Position 62 Cut 85 and paste 85 CVASM_OLD 127 CVASM16 127 -DData Breakpoints 44, 118, 120 DBP 118, 120, 121, 123, 124 debounce push button inputs 190 Debouncing a push button input 190 dec 162, 194 DECF 145, 162, 172 DECFSZ 145, 162, 175 © 2007 TechTools Index decimal 97, 105, 112 Decrement fr 162 Decrement fr and jump if not zero 162 Decrement fr and skip if zero 162 DECSZ 162 DEVICE 23, 32, 187, 190, 194 Device Settings 32, 59 Device Type 59 Disable EE Data Editor 7 Disable Option Editing.. 14 Disable Option Editing... 7 Disable Read Functions 7 Disable Task Confirmation Messages 7 Disabled 57 djnz 162, 187, 190 -EEdit 82 Edit - Configuration Word 15 Edit - ID Locations 13 Edit and Add 109 Edit menu 85, 88, 89 Editor Window 82 Emulator 55 Enable 120 Enable and Break On options 120 Enable Blank Check 6 Enable Calibration 6 Enable Code 6 Enable EE Data 6 Enable Erase 6 Enable Fuses 6 Enable ID Locations 6 enable option editing 14 Enable Serial Numbering 10 Enable Verify 6 Enable/disable trace 116 Encode as RETLW 10 Enter sleep mode 181 Enter source code 85 Environment Preferences 62 equ 187, 190, 194 error list 68 Error List Window 93 Errors 93 exclamation point 120 Executing Code at Full Speed 70 © 2007 TechTools Execution History 60 Execution point 77, 95 Exit Code 23 Exit Codes 24 External Break 60 External Inputs 60 -FF10 41, 76 F3 89 F4 32, 68, 131 F5 34, 70 F6 34, 36, 40, 71 F7 73 F8 35, 71 F9 36, 38, 43, 74 File menu 51, 66, 67 file node 51, 127, 128, 129, 130, 131 File Node Tool 48, 51 File Register options 120 File Registers Window 105 Filename 23 Files Window 105 FILL ALL 105 Find Next 89 Find what 89 Finishing the Project 43 FLASH Programming Pulse Width 12 Font Options 62 forcing a read 97 Frequency 59 -Ggang 17 Go 70 Go to Data Breakpoint Go to Marker 91 GOTO 145, 164 124 -HHalt 71 Halting Execution 71 Hardware Control Signal (TVDDEN) Hardware Settings 31 21 209 210 PicTools Manual 3.0 hex 5, 97, 105, 112 HEX ONLY 131 highlighted yellow 103 Hi-Tech C 129 -IICP 20 ID locations 7, 13 Ignore EE DATA 9 Ignore FUSE record 9 Ignore ID record 9 Ignore MCU record 9 IJNZ 163 inc 163, 190 INCF 145, 163, 172 INCFSZ 145, 163, 175 In-Circuit Programming 20 In-Circuit Programming Cable Pinout 20 Include Calibration Data 9 Include Constants 123 Include EE Data 9 Include FUSE Settings 9 Include MCU Type 9 Increment fr 163 Increment fr and jump if not zero 163 Increment fr and skip if zero 163 INCSZ 163 INHX32 5 INHX8M 5 INS 108 IORLW 145, 176, 184 IORWF 145, 176 -Jjb 164, 190, 194 JC 164 jmp 164, 187, 190, 194 jnb 165, 187, 190 JNC 165 JNZ 166 jump if above 152 jump if above or equal 152 jump if below 153 jump if below or equal 153 Jump if bit 164 Jump if carry 164 jump if equal 154 Jump if not bit 165 Jump if not carry 165 jump if not equal 155 Jump if not zero 166 Jump if zero 166 Jump to address 164 Jump to PC+W 164 Jump to W 164 JW 15 JZ 166 -LLabels Window 103 LAST HEX 17 LCALL 145, 166 LED 187 Legend - Programming Tasks 25 LGOTO 145 LIBRARY 129 Link 51 LINKER file 128 LINKING 127, 128, 129 literal and control operations 145 Little Endian 17 LJMP 166 Loading a Source File 29 Long call ('5x) 166 Long call ('xx) 166 Long jump ('5x) 166 Long jump ('xx) 166 Long set ('5x) 166 Long set ('xx) 166 Low Voltage Programming 20 LSET 166 -MManual Serial Numbers 17 Match case 89 Match On options 121 Match whole word 89 Mathias 55 MCLR 15 MCU SECTION 6 © 2007 TechTools Index MCU Sections 6 Microchip to CVASM16 145 Misc. Options 7 Mode 31 Mode of Operation 55 Modifying item values 112 Modifying Values of watched items 108 Monitor a Self Powered Target 21 mov 169, 171, 172, 187, 190, 194 MOV [to I/O Control] 171 MOV [to OPTION] 169 MOV [to register] 169 MOV [to W] 172 MOV [using Expressions] 172 MOVB 174 Move bit2 to bit1 174 Move fr into OPTION 169 Move fr into W 172 Move fr2 into fr1 169 Move fr-W into W 172 Move literal into fr 169 Move literal into OPTION 169 Move literal into W 172 Move not bit2 to bit1 174 Move not fr into W 172 Move the decremented value of fr into W 172 Move the incremented value of fr into W 172 Move the left-rotated value of fr into W 172 Move the nibble-swapped value of fr into W 172 Move the right-rotated value of fr into W 172 Move W into fr 169 Move W into OPTION 169 MOVF 145, 172, 184 MOVFW 145 MOVLW 145, 172 MOVSZ 175 MOVWF 145, 164, 169 MPASM 127 MPASM to OBJ 128 MPASM-to-OBJ 127 MPLABC 129 MPLINK 127, 128 multi-file project 50 multiple opcode instruction 145 -NNEGF 145 © 2007 TechTools new project 46 No operation 175 Node Build Settings 46, 50 NOP 145, 175 NOT 176 Not fr 176 Not W 176 Number of Locations 10 -OOBJECT 129 Off Line 55 Open HEX File - Override HEX Options 9 Opening the Data Breakpoints Dialog 118 Opening The Project 28 Operation 15 Operations 6 Operator Notification 21 OPTION 145, 169 Option Editing 6 Options - Programming Sockets - Gang 17 Options - Select MCU Type 15 OR 176 OR fr into W 176 OR fr2 into fr1 176 OR literal into fr 176 OR literal into W 176 OR W into fr 176 org 194 oscillator frequency 59 OTP 15 Override Power Off Requirement 12 -PParent Node 25 password 7 Password to Enable Option Editing Paste 85 PC.DEF 130 PCB 130 PCM 130 PIC16C54 187 PIC16C74 194 Place at Address 10 Place in Code Memory 10 7 211 212 PicTools Manual 3.0 Place in EEPROM Memory 10 Place markers 91 popped 57 POPUP Menu 105 pop-up menu 80, 115, 116 Power First 15 power-on state 76 Print 67 Printing 67 Production Control 7 Program Counter 76, 77 Project 50, 95 Project and File Operations 44 Project Info 31 Project menu 28, 32, 46, 50, 68 project name 45 PROJECT NODE 48, 51, 127, 128, 129, 130, 131 Project Node Tool 48, 51 Project Tool 29 protecting your settings from accidental changes 14 pushed 57 Resetting the Emulator 41, 66 RET 178 Retain Z Order 62 RETFIE 145, 178 RETI 178 RETLW 17, 145, 178 RETLW OPCODE 10 RETURN 145 RETURN ADDRESSES 57 Return from Interrupt 178 Return from subroutine 178 retw 178, 190 rl 179, 194 RLF 145, 172, 179 Rotate fr left 179 Rotate fr right 179 rr 179, 194 RRF 145, 172, 179 Run menu 34, 35, 36, 38, 41, 43, 70, 71, 72, 73, 74, 75, 76, 77, 78 Running TDE 44 Running the Code 34 -Q- -S- QuickWriter 4 QuickWriter Control 5 -Rradix 115 Randomize File Registers 62 RC oscillator 187, 190 RC_OSC 190 Read 120 Read or Write 120 Reading from a lookup table 190 Reading the MCU Contents 19 redo 88 register modification window 97 Replace 89 Replace All 89 Replace with 89 RESET 76, 187, 190 Reset Mathias 66 Reset on Timeout 57 Resetting the Emulated PIC 76 Sample Project 27 Sample Projects 186 Save HEX File - Include Record Options SB 179 SC 179 Search 89 Search Again 89 Search and replace 89 Select and Add 109 Select and Drag & Drop 109 Select MCU Type 15 Selected line 95 Selecting the MCU 15 Self Modifying Code 118 Serial Number Options 10 Set and clear breakpoints 85 Set bit 180 Set carry 180 Set PC 77 Set zero flag 180 setb 180, 190, 194 SETC 145 Setting Breakpoints 41 9 © 2007 TechTools Index Setting device options 187, 190 Setting General Options 7 Setting HEX Options 9 Setting I.D. Locations 13 Setting I/O pins as inputs or outputs 187, 190 Setting Options for Production Personnel 14 Setting Serial Number Options 10 Setting the Configuration Word (Fuses) 15 Setting the Program Counter 77 Setting the reset vector 187, 190 Setup menu 31, 55, 62, 95, 118, 120, 186 SETZ 145 Shift + F9 74 Shortcuts 14 Show Execution Point 75 Show Hints 62 Showing the Execution Point 75 SIMPLE 187 SINGLE FILE MODE 127, 128 SINGLE SOURCE FILE 127, 128, 129, 130 Single Step 71 Single-Step Execution 71 Single-Stepping 35 SKIP 181 Skip Blank Locations 7 skip if above 157 skip if above or equal 157 skip if below 159 skip if below or equal 159 Skip if bit 179 Skip if carry 179 skip if equal 160 Skip if not bit 182 Skip if not carry 182 skip if not equal 161 Skip if not zero 182 Skip if zero 179 Skip Power Cycles 12 Skip the following instruction word 181 Skipped 17 SKPC 145 SKPDC 145 SKPNC 145 SKPNDC 145 SKPNZ 145 SKPZ 145 SLEEP 145, 181 sleep mode 181 © 2007 TechTools SNB 182 SNC 182 SNZ 182 sockets 17 SPASM 127 special instructions 145 Special Register Viewing Options Special Registers Window 97 Specific Data 121 Stack OverFlow 57 Stack UnderFlow 57 Starting TDE 28 STC 180 Step OUT Execution 72 Step Over Execution 73 Stop button 34, 36, 40 stop execution 36 Stopping Execution 34 STZ 180 SUB 183 SUBB 183 SUBCF 145 SUBDCF 145 SUBLW 145 Subtract bit from fr 183 Subtract fr2 from fr 183 Subtract literal from fr 183 Subtract W from fr 183 SUBWF 145, 172, 183 SWAP 184 Swap nibbles in fr 184 SWAPF 145, 172, 184 SZ 179 97 -TTab Stops 62 Target Design Recommendations Target Voltage Option 12 TDE Details 44 TechTools Equivalent 145 TEST 184 Test fr for zero 184 Test W for zero 184 third-party compiler or assembler Tmin 12 Toggle Marker 91 tool 51 20 126 213 214 PicTools Manual 3.0 Trace Buffer 60 Trace Buffer Module Trace Buffer Window Trace Size 60 TRIS 145 TRIS registers 171 TSTF 145 TVDDEN 12, 23 Window Basics Write 120 57 116 -Xxor 185, 187, 194 XOR fr into W 185 XOR fr2 into fr1 185 XOR literal into fr 185 XOR literal into W 185 XOR W into fr 185 XORLW 145, 176, 185 XORWF 145, 185 XT_OSC 194 -UUndo 88 Undo and redo 88 Use High Speed Transfers 7 Use Microchip Checksums 7 Using Breakpoints 78 Using Gang Adapters 17 Using global labels 187 Using labels 190 Using local labels 187 Using Serial Numbers 17 Using TDE's Windows 44 Using the Various TDE Windows 80 80 -VVDD 21 VDD First 15 View menu 38, 82, 93, 95, 97, 105, 108 Viewing Special Registers 38 Virtual Mathias 55 -WWARN if Code Protection Enabled 15 Warn if CODE/Data Protection is Enabled Watch 105 Watch button 36 Watch Dog Timer 57 watch list 112 Watch List Options 108 Watch List Window 108 Watching the Program Run 40 Watching Variable Values 36 Watching Variables 38 WDT 57 WDT_OFF 194 7 © 2007 TechTools (972) 272-9392, www.tech-tools.com

很抱歉,暂时无法提供与“QW1”相匹配的价格&库存,您可以联系我们找货

免费人工找货