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.
|