logo image - link to home page

Products | Support | Resources | PurchaseContact  | Basket  | Checkout

  Home
  What's New
  Products
  Distributors
  Purchasing Info
  Developer Resources
  Support
  Upgrades
  Site Index
  Contact Us
  Pb-Free Info (RoHS)
 

 

keyword search:
 


 

Home:
  Support home:
General Topics:
    FAQ
    MCU selector guide
    Developer's resources
    Downloads and patches
    Sample programs
Support by Product:
    melabs USB/U2 
Programmer
    melabs Serial 
Programmer
    EPIC™ Plus PICmicro®  
Programmer
    Programming Adapters
    PICBASIC PRO™ 
Compiler
    PICBASIC™ Compiler
    PICPROTO™ Boards
    LAB-X1 Experimenter Board
    LAB-X2 Experimenter Board
    LAB-X3 Experimenter Board
    LAB-X4 Experimenter Board
    LAB-X18 Experimenter Board
    LAB-X20 Experimenter Board
    LAB-XT Experimenter Board
    LAB-XUSB Experimenter 
Board
    melabs Loader
 

Converting programs from BS2 to PICBASIC PRO™

Many users migrate to PICBASIC PRO™ from BASIC Stamp II.  Others find BSII program samples on the web that they would like to use with PICBASIC PRO.  Here is a guide for converting BSII code to PICBASIC PRO.  This works best if you have PICBASIC PRO Compiler version 2.40 or later.


1.  Add the following line to the top of the program to define the BS2 variables for PICBASIC PRO:

    include "bs2defs.bas"


2.  If DEBUG commands are used in the code, you may have to configure the PBP DEBUG parameters.   This is done with DEFINEs at the beginning of your program.  Refer to the DEBUG page in the PICBASIC PRO Compiler manual for the details.


3.  The BASIC Stamp variable names Dirs, Dira, Dirh, Dirl and Dir0-Dir15 cannot be used with the PICBASIC PRO Compiler. TRIS should be used instead, but has the opposite state of Dirs.  In other words, invert each bit in the Dir command when setting the TRIS register.

BSII syntax Equivalent PBP syntax
   
Dir0 = 1 TRISB.0 = 0
Dir10 = 0 TRISC.2 = 1
DirH = %00001111 TRISC = %11110000
Dirs = $FF0F TRISC = $00 : TRISB = $F0

On most PICmicro® MCUs, the Dir names correspond to TRIS registers as follows:

DirA      >>       TRISA
DirL      >>        TRISB
DirH      >>       TRISC
Dirs       >>         TRISC : TRISB (combined - no direct equivalent in PBP)
Dir0 - Dir7     >>       TRISB.0 - TRISB.7
Dir8 - Dir15   >>       TRISC.0 - TRISC.7


4.  OutA should be changed to PORTA in PICBASIC PRO.


5.  Nibble variable types are not supported in PICBASIC PRO.  You can usually use a BYTE variable instead.  If you are splitting a byte with .lownib and .highnib, you'll have to use math operators instead.

BSII syntax Equivalent PBP syntax
   
x = mybyte.lownib x = (mybyte & $0F)
x = mybyte.highnib x = (mybyte >> 4)

6.  When you write a For..Next loop and say that you want the index to count from high to low, the stamp assumes that you want to increment by -1 on each iteration.  PICBASIC PRO makes no such assumption.  You have to specify the Step value.

BSII syntax Equivalent PBP syntax
   
For x = 16 to 0 For x = 16 to 0 Step -1

7.  SERIN/SEROUT commands must be changed to SERIN2/SEROUT2.  This allows you to use the same syntax for the remainder of the command.

BSII syntax Equivalent PBP syntax
   
Serout  pin, mode, ["Hello"] Serout2  pin, mode, ["Hello"]

8.  LOOKUP/LOOKDOWN commands may need to be modified.

PICBASIC PRO does not allow Word-size values or variables in LOOKUP or LOOKDOWN.  LOOKUP2 and LOOKDOWN2 are provided for this purpose.

In PICBASIC PRO, expressions are not allowed in any of these commands.  You will have to rewrite these instances using a temporary variable.

BSII syntax Equivalent PBP syntax
   
Lookdown x, [235, z], y Lookdown2 x, [235, z], y
Lookdown x, [235, 1000], y Lookdown2 x, [235, 1000], y
Lookup x, [10, (a+b), 0], y tempvar = a+b
Lookup2 x, [10,tempvar,0], y

That should do it.  If you missed anything, you will receive errors when you compile, telling you the line number that needs updating.  

 

Copyright 2008
microEngineering Labs, Inc.
Box 60039
Colorado Springs CO 80960
(719) 520-5323
(719) 520-1867 fax
email: support@melabs.com

Last Updated: 08/04/2008

Home | What's New | Products | Support
Resources
| Purchase | Index Contact

PIC, PICmicro, dsPIC, and  MPLAB are registered trademarks of Microchip Technology Inc. in the USA and other countries.  PICBASIC, PICBASIC PRO, PICPROTO, and EPIC are trademarks of Microchip Technology Inc. in the USA and other countries.   BASIC Stamp is a trademark of Parallax, Inc.

Microchip third-party partner  Microchip Consultant Program Member