Need help with conversion from Pbasic to Mbasic

If anyone has the time, take a look at my code below. the problem I am having is token errors. I’m stuck on the line where DEC2 is causing an error. The Atom Pro manual has this modifier yet it can’t recognize it. Perhaps I am using the wrong syntax.
I have already changed the pin problems like “Clk PIN 14” to “Clk CON P14”

If anyone has the time, copy and paste this code in the IDE and run debug. Any help would be fantastic. If you need to original Pbasic code that worked, I can provide that as well.

[code]==========================================================================
’ -----------------------Botwire----------------------------

’ File… ADC08x32.BS2
’ Description… RSCU
’ Author… Mike Bookbinder
’ E-mail… [email protected]
’ Web… www.geocities.com/botwire
’ Updated… 1-14-06

’ {$STAMP BS2}
’ {$PBASIC 2.5}

’ ----- Program Description ]---------------------------------------------

’ This program is modified code from the Parallax ADC0832.bs2 program example.
’ I have modified this code to work with the RSCU Board.
’ For the original code example, please visit www.parallax.com for more
’ information.

’ ----- Revision History ]------------------------------------------------

'--------------------------------------------------------------------------

'----- Ping ]-------------------------------------------------------------

Ping CON P15

'--------------------------------------------------------------------------

’ PA0 CON 0 ’ pauses
PA1 CON 1
PA2 CON 2
PA3 CON 3
PA4 CON 4
PA5 CON 5
PA6 CON 6

Fast CON 7
Slow CON 8
Stress CON 14
Relax CON 15
Wait CON 16 ’ note underscore
Soft CON 18
Volume CON 20
Speed CON 21
Pitch CON 22
Bend CON 23
PortCtr CON 24
Port CON 25
Repeat
CON 26
CallPhr CON 28
GotoPhr CON 29
Delay CON 30
Reset CON 31

IY CON 128
IH CON 129
EY CON 130
EH_ CON 131
AY CON 132
AX CON 133
UX CON 134
OH CON 135
AW CON 136
OW CON 137
UH CON 138
UW CON 139
MM CON 140
NE CON 141
NO CON 142
NGE CON 143
NGO CON 144
LE CON 145
LO CON 146
WW CON 147
RR CON 148
IYRR CON 149
EYRR CON 150
AXRR CON 151
AWRR CON 152
OWRR CON 153
EYIY CON 154
OHIY CON 155
OWIY CON 156
OHIH CON 157
IYEH CON 158
EHLL CON 159
IYUW CON 160
AXUW CON 161
IHWW CON 162
AYWW CON 163
OWWW CON 164
JH CON 165
VV CON 166
ZZ CON 167
ZH CON 168
DH_ CON 169
BE CON 170
BO CON 171
EB CON 172
OB CON 173
DE CON 174
DO CON 175 ’ note underscore
ED CON 176
OD CON 177
GE CON 178
GO CON 179
EG CON 180
OG CON 181
CH
CON 182
HE CON 183
HO CON 184
WH CON 185
FF CON 186
SE CON 187
SO CON 188
SH CON 189
TH CON 190
TT CON 191
TU CON 192
TS CON 193
KE CON 194
KO CON 195
EK CON 196
OK CON 197
PE CON 198
PO CON 199

RO CON 200
R1 CON 201
R2 CON 202
R3 CON 203
R4 CON 204
R5 CON 205
R6 CON 206
R7 CON 207
R8 CON 208
R9 CON 209

A0 CON 210
A1 CON 211
A2 CON 212
A3 CON 213
A4 CON 214
A5 CON 215
A6 CON 216
A7 CON 217
A8 CON 218
A9 CON 219

_B0 CON 220 ’ note underscore
_B1 CON 221
_B2 CON 222
_B3 CON 223
_B4 CON 224
_B5 CON 225
_B6 CON 226
_B7 CON 227
_B8 CON 228
_B9 CON 229

C0 CON 230
C1 CON 231
C2 CON 232
C3 CON 233
C4 CON 234
C5 CON 235
C6 CON 236
C7 CON 237
C8 CON 238
C9 CON 239

D0 CON 240 ’ DTMF tones
D1 CON 241
D2 CON 242
D3 CON 243
D4 CON 244
D5 CON 245
D6 CON 246
D7 CON 247
D8 CON 248
D9 CON 249
D10 CON 250
D11 CON 251

M0 CON 252 ’ sonar pin
M1 CON 253 ’ pistol shot
M2 CON 254 ’ WOW
EOS CON 255
TX CON P9
RDY CON P10

phrase VAR Nib
phrase = 6
idx VAR Nib

'------------------------------ SpeakJet Setup ]-------------------------------------

'PAUSE 3000

SEROUT 9,$0054,"\0RX"] 'CLEAR BUFFER

SEROUT TX\RDY,$0054,[020,127]’ set volume to max
SEROUT 9,$0054,[PITCH,85,BEND,4]

’ ----- I/O Definitions ]-------------------------------------------------

CS CON P15 ’ ADC0832.1
Clk CON P14 ’ ADC0832.7
Dio CON P13 ’ ADC0832.5 / ADC0832.6

’ ----- Constants ]-------------------------------------------------------

Dif CON %0 ’ differential

Raw2mV CON $139B ’ 19.6 mV per count

’ ----- Variables ]-------------------------------------------------------

sglDif VAR Bit ’ adc mode (1 = SE)
oddSign VAR Bit ’ chan (Sgl), sign (Dif)
adc VAR Byte(2) ’ channel values
mVolts VAR Word(2) ’ millivolts
RightEar VAR Word ’ Right Electret Mic
LeftEar VAR Word ’ Left Electret Mic
counter VAR Word ’ Loop Counter

’ ----- EEPROM Data ]-----------------------------------------------------

’ ----- Initialization ]--------------------------------------------------

'Reset:
HIGH CS ’ deselect ADC

;DEBUG CLS, ’ Print display
; “ADC08x32”,
;CRSRXY, 0, 9, “Differential”, CR, CR,
;" Ch0:", CR,
;" Ch1:" ,CR

;DEBUG CRSRXY,0,5, ’ setup report screen
; "Parallax g Sonar ", CR,
; “=====================”, CR,
; "Time (uS)… ", CR,
; "Inches… ", CR,
; "Centimeters… "

’ ----- Main Program ]----------------------------------------------------

Main:

DO

sglDif = Dif
FOR oddSign = 0 TO 1
  GOSUB Read_0832
  mVolts(oddSign) = adc(oddSign) */ Raw2mV
  ;DEBUG CRSRXY, 7, (11 + oddSign),
    dec2 adc(oddSign), TAB,
    dec mVolts(oddSign) DIG 3, ".", DEC3 mVolts(oddSign)

     LeftEar = adc(0)  'Get value from Channel 0
     RightEar = adc(1)  'Get value from channel 1

  DEBUG HOME, CR, DEC3 RightEar 'Print value of CH1
  DEBUG CR, DEC3 LeftEar        'Print value of CH2

    IF RightEar > 15 THEN          'Threshold 5. If > then go to RightEarSub
      GOSUB RightEarSub
      DEBUG HOME, "RT Ear"
            ELSEIF LeftEar > 20 THEN   'Else if this is > the set threshold, go to LeftEarSub
                 GOSUB LeftEarSub
                   DEBUG HOME, "LT Ear"
                   ELSE
                   DEBUG HOME, "                 "


    ENDIF
NEXT

LOOP

END

’ ----- Subroutines ]-----------------------------------------------------

’ Reads ADC08x32

Read_0832: ’ Read ADC Chip
LOW CS
’ send start, mode, channel
SHIFTOUT Dio, Clk, MSBFIRST, %1\1, sglDif\1, oddSign\1]
’ read raw counts from ADC
SHIFTIN Dio, Clk, MSBPOST, [adc(oddSign)\8]
HIGH CS
RETURN

LeftEarSub:
LeftEar = 0
SEROUT TX\RDY, $0054,[PA1,LE,EY,FF,FF,TU,PA6,SE,OHIH,DE,PA2]

FOR counter = 1 TO 150 STEP 5
PULSOUT 5,500
PAUSE 20
NEXT

PAUSE 1000

FOR counter = 1 TO 150 STEP 5
PULSOUT 5,728
PAUSE 20
NEXT

FOR counter = 1 TO 50
GOSUB Read_0832
NEXT

RETURN

RightEarSub:
RightEar = 0 ’ Move servo right
SEROUT TX\RDY, $0054, [PA1,RR,RR,OHIH,TU,PA6,SE,OHIH,DE,PA2]
'Hello
'SEROUT TX\RDY, $0054,[HE,EH,LE,OWWW,PA2]

FOR counter = 1 TO 150 STEP 5
PULSOUT 5,1000
PAUSE 20
NEXT

PAUSE 1000

FOR counter = 1 TO 150 STEP 5
PULSOUT 5,728
PAUSE 20
NEXT

FOR counter = 1 TO 50
GOSUB Read_0832
NEXT

RETURN

'-------------------------------- SpeakJet Phrases ]-----------------------------------

ph1:
'My name is Vecter
SEROUT TX\RDY, $0054,[MM,OHIH,PA1,NE,EYIY,MM,PA2,IH,IH,SE,SE,PA2,VV,VV,EH,KO,TT,RR,RR,PA2]
RETURN

ph2:
'VERSION 1.0
SEROUT TX\RDY, $0054,[VV,AXRR,SH,SH,EY,NE,PA5,WW,WW,UX,NE,PO,OWIY,NE,TT,TT,PA5,OWWW,PA2,PA2,PA2,PA2]
RETURN

ph3:
'Object Detected
SEROUT TX\RDY, $0054,[OH,BE,JH,EY,KO,TT,PA2,DE,IY,TT,EH,EK,TT,EH,ED,PA2]
RETURN

ph4:
'Completed
SEROUT TX\RDY, $0054,[KO,MM,PO,LE,IY,TT,EH,ED,PA2]
RETURN

ph5:
'Hello
SEROUT TX\RDY, $0054,[HE,EH,LE,OWWW,PA2]
RETURN

ph6:
'BATTERY LOW
SEROUT TX\RDY, $0054,[OB,AY,TT,AXRR,IY,PA2,LE,LE,LE,OW,OW,OWWW,PA2]
RETURN

ph7:
'Initializing
SEROUT TX\RDY, $0054,[FAST,IH,NE,IH,SH,SH,UX,LE,OHIH,ZZ,ZZ,NGE,PA2]

ph8:
'LEFT SIDE
SEROUT TX\RDY, $0054,[PA1,LE,EY,FF,FF,TU,PA6,SE,OHIH,DE,PA2]
RETURN

ph9:
'RIGHT SIDE
SEROUT TX\RDY, $0054, [PA1,RR,RR,OHIH,TU,PA6,SE,OHIH,DE,PA2]
RETURN

ph10:
SEROUT TX\RDY, $0054, [HO,OH,SE,TT,OH,LE,UX,VV,IY,IY,SE,TT,OH,PA2,BE,EYIY,OB,IY,IY,PA2]
RETURN

ph11:
'Status OK
SEROUT TX\RDY, $0054, [SE,SE,TT,AY,TT,UX,SO,SO,PA2,OW,KE,EYIY]
RETURN

ph12:
'Sonar Ready
SEROUT TX\RDY, $0054, [SE,OW,NE,AWRR,PA2,RR,EY,DE,IY,PA2]
RETURN

ph13:
'Roaming Mode
SEROUT TX\RDY, $0054, [RR,OWWW,MM,MM,NGE,PA2,MM,OWWW,ED,PA2]
RETURN

ph14:
'RSCU
SEROUT TX\RDY, $0054, [AWRR,EH,SE,SE,PA1,SE,IY,IY,PA1,IY,UW,PA1,OB,OWWW,RR,ED,PA2]
RETURN

ph15:
'Processing Data
SEROUT TX\RDY, $0054, [FAST,PE,RR,OH,SO,SE,EH,SO,NGE,NGE,PA2,_DO,EYIY,DE,UX,pa2]
RETURN

END[/code]

I believe the problem is that dec2 is a modifier not a command. It looks like you commented out the DEBUG statement above, but did not comment out the next two lines which are continuations of that line.

Kurt

Well I am beginning to learn the syntax. I figured out how to use serout for the speak jet using Mbasic. The modifiers are still a mystery, and I have yet to figure out how to have multi commands on a single line.

I also played around with sending data to the EEPROM. This can be useful for setting program modes, so when you turn off the BAP, then back on again, you can have it execute a certain section of code based on the value read from the EEPROM. This non-volatile memory is a great feature.

I don’t think you can do multiple commands on the same source line.

Yes, I use the EEPROM code to save away movement sequences. The only problem I had was at times it appeared like it only wanted to write a maximum number of bytes per write or that it wanted to be alligned on certain byte boundries. If I remember correctly is was something like 8 byes max that I could write reliably…

I do like working on this chip. I hope they come out with a new version of their beta soon

Kurt

Ok, I though you could seperate them with a “:” to have them on one line. I tried it and it did not work.

All I would use the EEPROM for is storing numbers 0-9. Each number would represent what “mode”, or what section of code to jump to on startup.

Well I found my answer:

When using MODifiers and DEBUG, you need to have it all inside the brackets “]” example: DEBUG [DEC 3 variable(index)]

I was not used to using ] around everything for the DEBUG command.

I have been experimenting with learning Mbasic syntax vs. Pbasic and it’s starting make sense to me. I use the DEBUG command a lot when programming to see what’s going on with the code.

For anyone who is a beginner in Mbasic like I am, this code might be useful. It’s a simple program than counts from 0 to 10, then resets to 0 and counts to 10 over and over. It uses some of the DEBUG modifiers as well.

[code]; DEBUG Example program
; Program example by Mike B.
; 5-26-2007
;
;

countr var nib
countr = 0

main:

debug "Current Number: ",DEC countr] ; This line prints the lable then the value. Note the space after the “:”
;debug [DEC countr, 13] ; This line is used to disply the number with a carrige return code “13”
pause 500 ; This line provides a half second pause, 1000 is one second
debug [0] ; Debug command with code “0” which is the code for clearing the screen

if countr > 9 then ; If counter is greater than 9, then set it to 0
countr = 0
else
countr = countr + 1 ; If the counter is less than 9, add 1 to the value
endif

goto main ; Start at the top and do the loop again[/code]

What other things did you have to change?

You can have multiple commands on a line:

high p0:low p1:low p2

But if you run this in the debugger and step through the code that line will run as one not three individual steps.