Mbasic Manual
Total Page:16
File Type:pdf, Size:1020Kb
User’sUser’s GuideGuide Learn to Program PIC Micrcontrollers in easy to use Basic Revision 5.2 Warranty Basic Micro warranties its products against defects in material and workmanship for a period of 90 days. If a defect is discovered, Basic Micro will at our discretion repair, replace, or refund the purchase price of the product in question. Contact us at [email protected] No returns will be accepted without the proper authorization. Copyrights and Trademarks Copyright© 2001-2002 by Basic Micro, Inc. All rights reserved. PICmicro® is a trademark of Microchip Technology, Inc. Basic Stamp I/II and Parallax are registered trademarks of Parallax Inc. MBasic, The Atom and Basic Micro are registered trademarks of Basic Micro Inc. Other trademarks mentioned are registered trademarks of their respective holders. Disclaimer Basic Micro cannot be held responsible for any incidental, or consequential damages resulting from use of products manufactured or sold by Basic Micro or its distributors. No products from Basic Micro should be used in any medical devices and/or medical situations. No product should be used in a life support situation. Contacts Email: [email protected] Tech support: [email protected] Web: http://www.basicmicro.com Discussion List A web based discussion board is maintained at http://www.basicmicro.com Updates In our continuing effort to provide the best and most innovative products, software updates are made available by contacting us at [email protected] Table of Contents 5 Table of Contents Contents Introduction ................................................12 What is MBasic ?.............................................................................. 12 This Manual .................................................................................... 12 On-line Discussion Forums ................................................................ 12 Updates .......................................................................................... 12 Technical Support ............................................................................ 12 Basic PICmicro Setup ..................................13 Which PICmicro should I use ? ........................................................... 14 Basic PICmicro Schematic ................................................................. 14 What Next ? .................................................................................... 15 Getting Started ............................................17 Software Installation ........................................................................ 18 Configuring MBasic ........................................................................... 18 What is an IDE ? .............................................................................. 19 Getting Familiar with the IDE ............................................................. 19 Terminal Window Selection ............................................................... 21 Control Characters ........................................................................... 21 User Tool Bar .................................................................................. 22 Config Setup Menu ........................................................................... 24 First Program .................................................................................. 26 Error Reporting................................................................................ 28 Conclusion ...................................................................................... 29 In Circuit Debugger .....................................31 ICD Setup ....................................................................................... 32 USB To Serial Adapter ...................................................................... 32 What is an ICD ? .............................................................................. 33 Getting Familiar with the ICD Controls................................................. 33 Using the ICD .................................................................................. 35 Exercise .......................................................................................... 36 Debug Mode .................................................................................... 37 Variable Watch Window .................................................................... 37 Trouble Shooting ............................................................................. 38 The Basic’s ...................................................41 Bits, Bytes, Words, Longs .................................................................. 42 MSBs and LSBs ................................................................................ 42 6 RAM, EEPROM and Program Memory.................................................. 42 Built-in Hardware ............................................................................. 42 Hexadecimal 101 ............................................................................. 43 ASCII ............................................................................................. 43 Programming Practices ..................................................................... 44 Optimizing ...................................................................................... 46 Line Labels ...................................................................................... 47 Variables ........................................................................................ 47 Arrays ............................................................................................ 48 Tables ............................................................................................ 49 Aliases ........................................................................................... 49 Variable Modifiers ............................................................................ 49 Command Modifiers ......................................................................... 53 Constants ....................................................................................... 56 Pins................................................................................................ 57 Pin Variables ................................................................................... 59 MBasic Specific’s .........................................61 Stack.............................................................................................. 62 Oscillator Settings ............................................................................ 62 Internal RC Calibration ..................................................................... 62 Memory .......................................................................................... 62 Compiling ....................................................................................... 62 Reserved Symbols ........................................................................... 63 Device Specific Issues ...................................................................... 63 MBasic and Assembly ..................................65 What is Assembly ? .......................................................................... 66 Mixing Assembly and MBasic ............................................................. 66 In-line Assembly .............................................................................. 66 Assembly and Variables .................................................................... 67 Math .............................................................69 Numerical Types .............................................................................. 70 Adding and Subtracting .................................................................... 70 Multiplication ................................................................................... 70 Division ........................................................................................... 72 Integer Math in general .................................................................... 72 General Math Functions .................................................................... 73 Bitwise Operators ............................................................................ 73 Comparison Operators ..................................................................... 74 Logical Operators............................................................................. 74 Floating Point Math .......................................................................... 75 Floating Point Format ....................................................................... 75 Floating Point Example Program ........................................................ 75 7 Syntax ..........................................................79 ADin ............................................................................................... 80 ASM {...} ........................................................................................ 82 Branch ............................................................................................ 83 Button ............................................................................................ 85 Clear .............................................................................................. 88 Count ............................................................................................. 89 Data (EEPROM) ..............................................................................