Docsity
Docsity

Prepare-se para as provas
Prepare-se para as provas

Estude fácil! Tem muito documento disponível na Docsity


Ganhe pontos para baixar
Ganhe pontos para baixar

Ganhe pontos ajudando outros esrudantes ou compre um plano Premium


Guias e Dicas
Guias e Dicas


PBP Reference Manual, Manuais, Projetos, Pesquisas de Mecatrônica

Manual de referências pic basic

Tipologia: Manuais, Projetos, Pesquisas

2012

Compartilhado em 30/01/2012

isaque-rodrigues-dos-santos-7
isaque-rodrigues-dos-santos-7 🇧🇷

2 documentos

1 / 319

Toggle sidebar

Esta página não é visível na pré-visualização

Não perca as partes importantes!

bg1
Reference
Manual
microEngineering Labs, Inc.
www.melabs.com
PICBASIC PRO Compiler
PBP
3
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Pré-visualização parcial do texto

Baixe PBP Reference Manual e outras Manuais, Projetos, Pesquisas em PDF para Mecatrônica, somente na Docsity!

Reference

Manual

microEngineering Labs, Inc.

www.melabs.com

PICBASIC PRO

Compiler

PBP 3

Table of Contents

  • 4 www.melabs.com 2011-11-
  • Chapter 1: Vital Information Table of Contents
    • 1.1 System Overview
    • 1.2 Integrated Development Environment (IDE)
      • 1.2.1 MPLAB
      • 1.2.2 MicroCode Studio
      • 1.2.3 Other IDEs
    • 1.3 Compile Modes PBPW and PBPL
    • 1.4 Microchip Datasheets
    • 1.5 Microchip Nomenclature
    • 1.6 Manual Conventions and Notes
      • 1.6.1 Command Prototypes
      • 1.6.2 Special Terminology and Acronyms
      • 1.6.3 Number formats
      • 1.6.4 Comments in code examples
    • 1.7 Technical Support
      • 1.7.1 Support Requirements
  • Chapter 2: PBP Syntax and Programming
    • 2.1 Program Organization (Example)
    • 2.2 I/O Pins
      • 2.2.1 Data Direction
      • 2.2.2 Aliasing
      • 2.2.3 Use in High-Level Commands
      • 2.2.4 Additional Configuration
      • 2.2.5 Pin Characteristics
    • 2.3 DEFINEs
      • 2.3.1 DEFINE OSC
      • 2.3.2 Global DEFINEs
      • 2.3.3 DEFINEs defined
    • 2.4 Aliases
    • 2.5 Labels
    • 2.6 Variables
      • 2.6.1 Creating Scalar Variables
      • 2.6.2 Creating Array Variables
      • 2.6.3 Using Scalar Variables
      • 2.6.4 Using Array Variables
    • 2.7 Constants
    • 2.8 Modifiers
      • 2.8.1 Modifiers used when creating variables
      • 2.8.2 Modifiers that access binary subsets of numeric values
      • 2.8.3 Modifiers for parsing and formatting ASCII strings
  • 2011-11-28 www.melabs.com Table of Contents - 2.8.4 Modifiers for specifying variable types in data space ....................
    • 2.9 ASCII and Strings ..................................................................................
    • 2.10 Input Modifiers for Parsing Strings.........................................................
      • 2.10.1 DEC ..............................................................................................
      • 2.10.2 BIN ................................................................................................
      • 2.10.3 HEX ..............................................................................................
      • 2.10.4 SKIP..............................................................................................
      • 2.10.5 STR...............................................................................................
      • 2.10.6 WAIT .............................................................................................
      • 2.10.7 WAITSTR ......................................................................................
    • 2.11 Output Modifiers for Formatting Strings .................................................
      • 2.11.1 DEC ..............................................................................................
      • 2.11.2 BIN ................................................................................................
      • 2.11.3 HEX ..............................................................................................
      • 2.11.4 REP ..............................................................................................
      • 2.11.5 STR...............................................................................................
    • 2.12 Numbers ................................................................................................
    • 2.13 Registers ...............................................................................................
    • 2.14 Comments .............................................................................................
    • 2.15 Case Sensitivity .....................................................................................
      • 2.15.1 DEFINEs .......................................................................................
      • 2.15.2 Variables .......................................................................................
    • 2.16 White Space ..........................................................................................
      • 2.16.1 Tabbing For Readability ................................................................
    • 2.17 Line-Extension ( _ ) ...............................................................................
    • 2.18 Line-Concatenation ( : ) .........................................................................
    • 2.19 INCLUDE ...............................................................................................
  • Chapter 3: Operators ......................................................................................
    • 3.1 Math Operators......................................................................................
      • 3.1.1 Multiplication .................................................................................
      • 3.1.2 '/' and '*' Special Multiplication .................................................
      • 3.1.3 Division .........................................................................................
      • 3.1.4 Remainder (Modulus) ...................................................................
      • 3.1.5 ABS...............................................................................................
      • 3.1.6 ATN...............................................................................................
      • 3.1.7 COS ..............................................................................................
      • 3.1.8 DCD ..............................................................................................
      • 3.1.9 DIG ...............................................................................................
      • 3.1.10 DIV32 ............................................................................................
      • 3.1.11 HYP ..............................................................................................
      • 3.1.12 MAX and MIN ...............................................................................
      • 3.1.13 NCD ..............................................................................................
  • 6 www.melabs.com 2011-11- Table of Contents - 3.1.14 REV.............................................................................................. - 3.1.15 SIN - 3.1.16 SQR
    • 3.2 Bitwise Operators
      • 3.2.1 & Bitwise AND.............................................................................
      • 3.2.2 | Bitwise OR
      • 3.2.3 ^ Bitwise EXCLUSIVE OR (XOR)
      • 3.2.4 ~ Bitwise NOT (INVERT)
      • 3.2.5 &/ Bitwise NOT AND (NAND)
      • 3.2.6 |/ Bitwise NOT OR (NOR)
      • 3.2.7 ^/ Bitwise NOT EXCLUSIVE OR (XNOR)
      • 3.2.8 << SHIFT LEFT...........................................................................
      • 3.2.9 >> SHIFT RIGHT
    • 3.3 Comparison Operators
      • 3.3.1 Signed vs. Unsigned Comparisons
      • 3.3.2 Equal To ( = or == )
      • 3.3.3 Not Equal To ( <> or != )
      • 3.3.4 Less Than ( < )
      • 3.3.5 Greater Than ( > )
      • 3.3.6 Less Than or Equal To ( <= )
      • 3.3.7 Greater Than or Equal To ( => )...................................................
    • 3.4 Logical Operators
      • 3.4.1 Using Parentheses
      • 3.4.2 Logical vs. Bitwise........................................................................
      • 3.4.3 AND
      • 3.4.4 OR
      • 3.4.5 XOR
      • 3.4.6 NOT
      • 3.4.7 ANDNOT
      • 3.4.8 ORNOT
      • 3.4.9 XORNOT......................................................................................
  • Chapter 4: Directives
    • 4.1 DISABLE
    • 4.2 DISABLE DEBUG
    • 4.3 DISABLE INTERRUPT
    • 4.4 ENABLE
    • 4.5 ENABLE DEBUG
    • 4.6 ENABLE INTERRUPT
    • 4.7 ON DEBUG...........................................................................................
    • 4.8 ON INTERRUPT
    • 4.9 #CONFIG...#ENDCONFIG
    • 4.10 #DEFINE
  • 2011-11-28 www.melabs.com Table of Contents
    • 4.11 #ERROR..............................................................................................
    • 4.12 #IF…#ELSE…#ENDIF ........................................................................
    • 4.13 #IFDEF…#ELSE…#ENDIF .................................................................
    • 4.14 #IFNDEF…#ELSE…#ENDIF...............................................................
    • 4.15 #MSG ..................................................................................................
    • 4.16 #WARNING .........................................................................................
  • Chapter 5: Commands .................................................................................
    • 5.1 Overview of Commands ......................................................................
    • 5.2 @ .........................................................................................................
    • 5.3 ADCIN .................................................................................................
    • 5.4 ARRAYREAD ......................................................................................
    • 5.5 ARRAYWRITE.....................................................................................
    • 5.6 ASM..ENDASM ...................................................................................
    • 5.7 BRANCH .............................................................................................
    • 5.8 BRANCHL ...........................................................................................
    • 5.9 BUTTON ..............................................................................................
    • 5.10 CALL ...................................................................................................
    • 5.11 CLEAR.................................................................................................
    • 5.12 CLEARWDT ........................................................................................
    • 5.13 COUNT ................................................................................................
    • 5.14 DATA ...................................................................................................
    • 5.15 DEBUG ................................................................................................
    • 5.16 DEBUGIN ............................................................................................
    • 5.17 DO..LOOP ...........................................................................................
    • 5.18 DTMFOUT ...........................................................................................
    • 5.19 EEPROM .............................................................................................
    • 5.20 END .....................................................................................................
    • 5.21 ERASECODE ......................................................................................
    • 5.22 EXIT ....................................................................................................
    • 5.23 FOR..NEXT .........................................................................................
    • 5.24 FREQOUT ...........................................................................................
    • 5.25 GOSUB................................................................................................
    • 5.26 GOTO ..................................................................................................
    • 5.27 HIGH ...................................................................................................
    • 5.28 HPWM .................................................................................................
    • 5.29 HSERIN ...............................................................................................
    • 5.30 HSERIN2 .............................................................................................
    • 5.31 HSEROUT ...........................................................................................
    • 5.32 HSEROUT2 .........................................................................................
    • 5.33 I2CREAD .............................................................................................
    • 5.34 I2CWRITE ...........................................................................................
    • 5.35 IF..THEN..............................................................................................
  • 8 www.melabs.com 2011-11- Table of Contents
    • 5.36 INPUT
    • 5.37 LCDIN
    • 5.38 LCDOUT
    • 5.39 {LET}
    • 5.40 LOOKDOWN
    • 5.41 LOOKDOWN2
    • 5.42 LOOKUP
    • 5.43 LOOKUP2
    • 5.44 LOW
    • 5.45 NAP
    • 5.46 ON GOSUB
    • 5.47 ON GOTO
    • 5.48 OUTPUT
    • 5.49 OWIN
    • 5.50 OWOUT
    • 5.51 PAUSE
    • 5.52 PAUSEUS...........................................................................................
    • 5.53 PEEK
    • 5.54 PEEKCODE
    • 5.55 POKE
    • 5.56 POKECODE
    • 5.57 POT
    • 5.58 PULSIN
    • 5.59 PULSOUT
    • 5.60 PWM
    • 5.61 RANDOM
    • 5.62 RCTIME
    • 5.63 READ
    • 5.64 READCODE
    • 5.65 REPEAT..UNTIL
    • 5.66 RESUME
    • 5.67 RETURN
    • 5.68 REVERSE...........................................................................................
    • 5.69 SELECT CASE
    • 5.70 SERIN
    • 5.71 SERIN2
    • 5.72 SEROUT
    • 5.73 SEROUT2
    • 5.74 SHIFTIN
    • 5.75 SHIFTOUT
    • 5.76 SLEEP
    • 5.77 SOUND
  • 2011-11-28 www.melabs.com Table of Contents
    • 5.78 STOP ...................................................................................................
    • 5.79 SWAP ..................................................................................................
    • 5.80 TOGGLE..............................................................................................
    • 5.81 USBIN..................................................................................................
    • 5.82 USBINIT ..............................................................................................
    • 5.83 USBOUT..............................................................................................
    • 5.84 USBSERVICE .....................................................................................
    • 5.85 WHILE..WEND ....................................................................................
    • 5.86 WRITE .................................................................................................
    • 5.87 WRITECODE.......................................................................................
    • 5.88 XIN ......................................................................................................
    • 5.89 XOUT...................................................................................................
  • Chapter 6: Interrupts.....................................................................................
    • 6.1 Interrupts Using ON INTERRUPT .......................................................
      • 6.1.1 In Practice ...................................................................................
      • 6.1.2 How ON INTERRUPT Works ......................................................
    • 6.2 Interrupts Using Assembly Language ..................................................
      • 6.2.1 Checklist .....................................................................................
      • 6.2.2 DEFINEs .....................................................................................
      • 6.2.3 Enabling Interrupts ......................................................................
      • 6.2.4 Placement of the Assembly Language Routine ..........................
      • 6.2.5 Declaring Special Variables to Save Context ..............................
      • 6.2.6 Access to PBP Variables from the Interrupt Handler ..................
      • 6.2.7 Time-Sensitive PBP Commands .................................................
    • 6.3 Assembly Interrupts for PIC18 Devices ...............................................
      • 6.3.1 Interrupt Priorities........................................................................
      • 6.3.2 Saving and Restoring Context ....................................................
      • 6.3.3 Example High/Low Priority ISR Framework for PIC18 ................
    • 6.4 Assembly Interrupts for Enhanced 14-Bit Instruction Set ....................
      • 6.4.1 Saving and Restoring Context ....................................................
      • 6.4.2 Example ISR Framework for Enhanced 14-Bit ...........................
    • 6.5 Assembly Interrupts for 14-Bit Instruction Set......................................
      • 6.5.1 Declaring Special Variables to Save Context ..............................
      • 6.5.2 Saving and Restoring Context ....................................................
      • 6.5.3 Example ISR Framework for the 14-Bit Instruction Set: ..............
  • Chapter 7: Advanced Techniques and Concepts .........................................
    • 7.1 In-Line Assembly Language ................................................................
      • 7.1.1 Inserting Assembly Code ............................................................
      • 7.1.2 Placement of In-line Assembly ....................................................
    • 7.2 Code Pages and RAM Banks ..............................................................
    • 7.3 RAM Allocation ....................................................................................
  • 10 www.melabs.com 2011-11- Table of Contents
    • 7.4 MPLAB® Development Environment
      • 7.4.1 Debugging Tool General Considerations
      • 7.4.2 Debugging Tool Device-Specific Considerations
    • 7.5 Hardware Stack
    • 7.6 Array Handling Mechanism
      • 7.6.1 The Danger
      • 7.6.2 Brackets Perform Offsets
      • 7.6.3 Sub-Arrays within Arrays............................................................
      • 7.6.4 Accessing Arrays as Multiple Variable-Types
      • 7.6.5 Applying Offsets to Bits within a Variable or Register
  • Chapter 8: Appendixes
    • 8.1 Debugging and Troubleshooting
      • 8.1.1 Configuration..............................................................................
      • 8.1.2 Initializing values
      • 8.1.3 DEFINE OSC
      • 8.1.4 Analog Inputs
      • 8.1.5 Internal Oscillator
      • 8.1.6 Read-Modify-Write
      • 8.1.7 Data Direction
      • 8.1.8 Analog Conversion.....................................................................
      • 8.1.9 I/O pin parameters and limitations
      • 8.1.10 Piggybacked pin functions
      • 8.1.11 Pin Relocation and Defines
      • 8.1.12 Omitting parentheses
      • 8.1.13 Channel numbers vs. pins..........................................................
      • 8.1.14 Hardware Stack
      • 8.1.15 Overrunning Array Variables
    • 8.2 12-Bit Instruction Set Considerations..................................................
    • 8.3 PBPX Command Line Operation
    • 8.4 Specifying Assembler Location with PBP_MPASM
    • 8.5 defs Include Files
      • 8.5.1 modedefs.bas
      • 8.5.2 bs1defs.bas................................................................................
      • 8.5.3 bs2defs.bas................................................................................
    • 8.6 SERIN2/SEROUT2 Mode List
    • 8.7 Defines
    • 8.8 Reserved Words
    • 8.9 ASCII Conversion Chart
    • 8.10 Glossary
    • 8.11 Index

Vital Information

2011-11-28 www.melabs.com 11

Chapter 1: Vital Information

Vital Information

2011-11-28 www.melabs.com 13

Device Programmer

The device programmer takes the machine language code and "burns" it into the microcontroller. Examples of device programmers are the U2 Programmer from melabs and the PICkit™ 3 from Microchip. The melabs U2 Programmer is recommended for ease of use and availability of technical support.

Debugger

A debugger is used to "see" what is happening inside the microcontroller when it runs. The simplest method of debugging is to write bits of code into your program that display information like variable and register values. The term In-Circuit Debugger (ICD) refers to a device or method that gives you step-by-step control of program execution via a connection to the microcontroller. Examples of debuggers are the ICD3 from Microchip and the software-based ICD system offered in MicroCode Studio PLUS from Mecanique.

Vital Information

14 www.melabs.com 2011-11-

1.2 Integrated Development Environment (IDE)

PBP is designed to operate within an Integrated Development Environment (IDE). This means that, by itself, PBP is only a utility that accepts files as inputs and generates files as outputs. The IDE is what provides the user interface and program-editing capability.

1.2.1 MPLAB

Microchip (www.microchip.com) offers a free IDE called MPLAB. It is included on the PBP installation CD. In order to use MPLAB, PBP must be first installed as a language tool within that environment. A utility can be run from the PBP program group on the Start menu that will accomplish the installation and setup.

MPLAB should be installed even if you are using a different IDE. The MPLAB installation includes the Microchip assembler, MPASM, which is needed for operation of PBP.

1.2.2 MicroCode Studio

MicroCode Studio is a purpose-built IDE offered by Mecanique (www.mecanique.co.uk). MicroCode Studio is included on the PBP installation CD. It is a favorite among PBP users for its ease of use.

Mecanique offers an advanced version (MicroCode Studio Plus) that adds features for in-circuit debugging and bootloader programming.

1.2.3 Other IDEs

Any text editor can be used to create programs for PBP, though it is best to use one that is designed with compiler-management capability. Even better is an IDE that is PBP-aware and will highlight PBP syntax with color and text formatting.

Vital Information

16 www.melabs.com 2011-11-

1.4 Microchip Datasheets

At the time of this writing, PBP supports more than 500 microcontrollers. Each of these devices has its own set of internal registers that perform specific functions. The names and construction of these registers differ between device families. Some family's internal workings are incredibly powerful and complex. Microchip provides a datasheet for each family that details how things work.

In order to use PBP, you must become familiar with the datasheet for the device you have chosen to use. It isn't necessary to read a datasheet from cover to cover, but the datasheet will provide the reference documentation that is needed to manage the device with PBP.

PBP is a full-fledged, professional-level compiler for embedded development. It is also a tool with a reputation for ease-of-use, suitable to the hobbyist. If you are moving to PBP from a "microcontroller-like" device that didn't require you to use datasheets, then you have stepped up considerably. We congratulate you and we'll do everything possible to help you make the transition.

Datasheets can be found at www.microchip.com. A search of the website using the device part number should turn up the datasheet quickly.

If you need help understanding the datasheet, contact melabs support.

Vital Information

2011-11-28 www.melabs.com 17

1.5 Microchip Nomenclature

This manual may refer to device families by prefix or instruction set, but one should not assume that prefix always denotes instruction set. The prefixes "PIC12" and "PIC16" include parts from multiple instruction sets:

PIC10 (prefix) small, inexpensive devices that use the 12-bit or 14-bit instruction sets PIC12 (prefix) 8-pin devices that may use the 12-bit, 14-bit, or enhanced 14- bit instruction sets PIC16 (prefix) (^) devices ranging from 14-pin to 64-pin that may use the 12-bit, 14-bit, or enhanced 14-bit instruction sets PIC18 (prefix) high-performance devices that use the 16-bit instruction set 12 - bit instruction set (denoted as "Baseline Architecture" by Microchip)

mostly attractive for low cost, these devices may not be compatible with all PBP commands, PBP LONG variables not available 14 - bit instruction set (denoted as "Mid-Range Architecture" by Microchip)

compatible with all PBP commands, PBP LONG variables not available

Enhanced 14-bit instruction set (denoted as "Enhanced Mid-Range Architecture" by Microchip)

compatible with all PBP commands, some features in common with 16- bit instruction set, PBP LONG variables not available 16 - bit instruction set (denoted as "PIC18 Architecture" by Microchip)

All devices with prefix PIC18, compatible with all PBP commands, PBP LONG variables supported, high-speed and generally better performance than the other families supported by PBP

Vital Information

2011-11-28 www.melabs.com 19

1.6.2 Special Terminology and Acronyms

Some acronyms and terms that will be used extensively in this manual are:

PBP PICBASIC PRO™ Compiler PBPW PBP in WORD mode PBPL PBP in LONG mode melabs microEngineering Labs, Inc.

1.6.3 Number formats

Numbers in this manual may be written as decimal (99), hexadecimal ($63) or binary (%1100011). The choice of number format will depend on the context. The intent is to improve readability by expressing numbers in formats that match the application of the value. (see section 2.12 for more information on PBP number formats and handling)

1.6.4 Comments in code examples

For the sake of readability, comments in code examples will begin with a comment character, but may wrap to multiple lines without comment characters on subsequent lines. To compile many of these examples, comment characters would have to be added. For example:

WRITE 5,B0 ' Send value in B0 to EEPROM location 5

The comment begins with an apostrophe, but wraps to a second line that would result in a compile error if typed literally into your program. To avoid the error, the example would be written like this:

WRITE 5,B0 ' Send value in B0 to EEPROM ' location 5

Vital Information

20 www.melabs.com 2011-11-

1.7 Technical Support

microEngineering Labs takes great pride in providing the best technical support possible. Depending on the PBP edition that you have purchased, tech support is available in different forms.

Online Forum Available for all users Direct Email Available for licensed users of premium editions Telephone Available for licensed users of premium editions

See the Support section of our website (www.melabs.com) for contact details.

1.7.1 Support Requirements

The support we provide can only be as detailed as the information that you provide to us. Please have the following information ready when requesting support.

  • PBP version number.
  • Complete, exact error message, if an error has been encountered. (An exact error message will usually result in an immediate solution.)
  • The exact part number of the device you are compiling for.
  • Complete details about your operating system, including Windows version, your access privilege level, and whether a virtual machine is in use.
  • The method that you are using for test/debug. (Hardware platform, ICD device, running in simulation on PC, etc.)

Please note that reading program code verbally over a telephone connection is our least favorite way of providing support. It just doesn't work. We understand that some users prefer the immediate response of a phone call, but this shouldn't preclude an email with a file attachment. Send us an email, then dial.