Syntax frustration

AlbertZ

Senior Member
Every time I try to run this I get the following:

"syntax error on Line 39 at/before position 20"

Apparently it is not happy with the "start" label, but I cant figure out why. Any suggestions?

Code:
'=======================FinishLine.bas======================
'===Version 1.0===
;This program is a complement to PinewoodDerby.bas
;Its only function is to determine and display the order
;of finish in a 3-lane Pinewood Derby race.
;It is intended to run on a PICAXE 14M2 acting as a co-processor

'===constants===

'===variables===


symbol Ln_3 = PinB.0    	; rename input B.0 'Ln_3'
symbol Ln_2 = PinB.1    	; rename input B.1 'Ln_2'
symbol Ln_1 = PinB.2    	; rename input B.2 'Ln_1'
symbol Start = PinB.3   	; rename input B.3 'Start'
symbol Display1 = C.0   	; rename output C.0 ‘Display1’
symbol Display2 = C.1   	; rename output C.1 ‘Display2’
symbol Display3 = C.2   	; rename output C.2 ‘Display3’


'===directives===
'#com3					'specify serial port
#picaxe 14M2				'specify processor
#no_data    				'save download time
'#terminal of     			'disable terminal window

'===================begin main program========================

setfreq M32 				'run program at max speed

let dirsC=%11111111     			'all outputs

let dirsB=%00100001     			'change bits 5, & 0 to outputs


main:

if PinB.3 = 1 then start        ;limit switch closed to start race

goto main


myloop:

b0 = pinsB & %00000111  		;mask off bits 0, 1 & 2

if bit0 = 1 then goto Lane3  	;IR beam broken on Lane 3
	endif 

if bit1 = 1 then goto Lane2   	;IR beam broken on Lane 2
	endif 
	
if bit2 = 1 then goto Lane1   	;IR beam broken on Lane 1
	endif 

if pinB.3 = 0 then goto main  	;resets for the next race
	
goto myloop
	
start:
pulsout C.0,150: pulsout C.1,150: pulsout C.2,150  ; reset displays to 0

sertxd ("START RACE")   		; send start of race message
goto myloop

Lane1:
	sertxd ("Lane 1 is the winner!")
Lane2:
	sertxd ("Lane 2 is the winner!")
Lane3:
	sertxd ("Lane 3 is the winner!")
Thanks

Al
 

srnet

Senior Member
The error from that program is;

Error: Expected a label not the variable Start

You have a symbol\variable called 'Start' and a label called 'Start'

So the editor is confused.
 

AlbertZ

Senior Member
The error from that program is;

Error: Expected a label not the variable Start

You have a symbol\variable called 'Start' and a label called 'Start'

So the editor is confused.
Thanks, couldn't see the forest for the trees

Al
 

Rick100

Senior Member
Hello Al,
Code:
if bit0 = 1 then goto Lane3  	;IR beam broken on Lane 3
	endif 

if bit1 = 1 then goto Lane2   	;IR beam broken on Lane 2
	endif 
	
if bit2 = 1 then goto Lane1   	;IR beam broken on Lane 1
	endif
You will also have to delete the endif statements or change the code to look like this to pass a syntax check.
Code:
if bit0 = 1 then
    goto Lane3  	;IR beam broken on Lane 3
endif 

if bit1 = 1 then
    goto Lane2   	;IR beam broken on Lane 2
endif 
	
if bit2 = 1 then
    goto Lane1   	;IR beam broken on Lane 1
endif

Good luck,
Rick
 

AlbertZ

Senior Member
Hello Al,
Code:
if bit0 = 1 then goto Lane3  	;IR beam broken on Lane 3
	endif 

if bit1 = 1 then goto Lane2   	;IR beam broken on Lane 2
	endif 
	
if bit2 = 1 then goto Lane1   	;IR beam broken on Lane 1
	endif
You will also have to delete the endif statements or change the code to look like this to pass a syntax check.
Code:
if bit0 = 1 then
    goto Lane3  	;IR beam broken on Lane 3
endif 

if bit1 = 1 then
    goto Lane2   	;IR beam broken on Lane 2
endif 
	
if bit2 = 1 then
    goto Lane1   	;IR beam broken on Lane 1
endif

Good luck,
Rick
Thanks Rick,

I will be updating my Pinewood Derby project shortly by adding order of finish. I want to develop some hardware & software concepts first.

Getting back to my syntax frustration, what is the difference between the two different iterations. Seems to me that the only difference is you moved the goto statement to the next line. Inquiring minds want to know.

Thanks

Al
 

neiltechspec

Senior Member
Also note you have specified all port c as output.

c.3 & c.5 are input only.

edit:

Also

b.0 is output only

Neil.
 
Last edited:

geoff07

Senior Member
Normally you have to put a ':' after 'then' if you want to add a statement on the same line, though I think there are exceptions. 'Historical reasons', probably.

How about
Code:
select b0
   case 1: ...
   case 2: ...
   case 4: ...
endselect
A little clearer perhaps?

or even, with some suitable symbol statements ..
Code:
select sensed_lane
   case lane_1: ...
   case lane_2: ...
   case lane_3: ...
endselect
 

Rick100

Senior Member
Getting back to my syntax frustration, what is the difference between the two different iterations. Seems to me that the only difference is you moved the goto statement to the next line. Inquiring minds want to know.
Leaving them on the same line gives an 'Error: Endif without If' . It seems to be the way the editor distinguishes between the multiple line 'if...then\ elseif \ else \ endif' and the single line 'if...then {goto}' .

Good luck,
Rick
 

neiltechspec

Senior Member
Just out of interest, here's how I would do it.

Code:
;=======================FinishLine.bas======================
;===Version 1.0===
;This program is a complement to PinewoodDerby.bas
;Its only function is to determine and display the order
;of finish in a 3-lane Pinewood Derby race.
;It is intended to run on a PICAXE 14M2 acting as a co-processor

;===directives===

;#com3				;specify serial port
#picaxe 14M2			;specify processor
#no_data    			;save download time
;#terminal off     		;disable terminal window

;===constants===

;===variables===

symbol Ln_3 = PinB.1    	;input B.1 Ln_3
symbol Ln_2 = PinB.2    	;input B.2 Ln_2
symbol Ln_1 = PinB.3    	;input B.3 Ln_1
symbol Start = PinB.4   	;input B.4 Start
symbol Display1 = C.0   	;output C.0 Display1
symbol Display2 = C.1   	;output C.1 Display2
symbol Display3 = C.2   	;output C.2 Display3

;===================begin main program========================

setfreq M32 			;run program at max speed

main:
	if Start = 1 then begin ;limit switch closed to start race

	goto main


myloop:

	do
	
	if Ln_3 = 1 then goto Lane3 	;IR beam broken on Lane 3	

	if Ln_2 = 1 then goto Lane2  	;IR beam broken on Lane 2
	 
	if Ln_1 = 1 then goto Lane1  	;IR beam broken on Lane 1
	
	if Start = 0 then goto main	;resets for the next race
	
	loop
	
begin:
	pulsout Display1,150: pulsout Display2,150: pulsout Display3,150  ; reset displays to 0

	sertxd ("START RACE")   	;send start of race message

	goto myloop

Lane1:
	sertxd ("Lane 1 is the winner!")
	goto main

Lane2:
	sertxd ("Lane 2 is the winner!")
	goto main
	
Lane3:
	sertxd ("Lane 3 is the winner!")
	goto main
Neil.
 

AlbertZ

Senior Member
Normally you have to put a ':' after 'then' if you want to add a statement on the same line, though I think there are exceptions. 'Historical reasons', probably.

How about
Code:
select b0
   case 1: ...
   case 2: ...
   case 4: ...
endselect
A little clearer perhaps?

or even, with some suitable symbol statements ..
Code:
select sensed_lane
   case lane_1: ...
   case lane_2: ...
   case lane_3: ...
endselect
Thanks Geoff

I have been considering using the select...case command for this particular application. Intuitively it seems like the way to go, I just don't have much programming experience so I'm a little hesitant to stray too far from what I know (which isn't a whole lot).

Al
 

AlbertZ

Senior Member
Just out of interest, here's how I would do it.

Code:
;=======================FinishLine.bas======================
;===Version 1.0===
;This program is a complement to PinewoodDerby.bas
;Its only function is to determine and display the order
;of finish in a 3-lane Pinewood Derby race.
;It is intended to run on a PICAXE 14M2 acting as a co-processor

;===directives===

;#com3				;specify serial port
#picaxe 14M2			;specify processor
#no_data    			;save download time
;#terminal off     		;disable terminal window

;===constants===

;===variables===

symbol Ln_3 = PinB.1    	;input B.1 Ln_3
symbol Ln_2 = PinB.2    	;input B.2 Ln_2
symbol Ln_1 = PinB.3    	;input B.3 Ln_1
symbol Start = PinB.4   	;input B.4 Start
symbol Display1 = C.0   	;output C.0 Display1
symbol Display2 = C.1   	;output C.1 Display2
symbol Display3 = C.2   	;output C.2 Display3

;===================begin main program========================

setfreq M32 			;run program at max speed

main:
	if Start = 1 then begin ;limit switch closed to start race

	goto main


myloop:

	do
	
	if Ln_3 = 1 then goto Lane3 	;IR beam broken on Lane 3	

	if Ln_2 = 1 then goto Lane2  	;IR beam broken on Lane 2
	 
	if Ln_1 = 1 then goto Lane1  	;IR beam broken on Lane 1
	
	if Start = 0 then goto main	;resets for the next race
	
	loop
	
begin:
	pulsout Display1,150: pulsout Display2,150: pulsout Display3,150  ; reset displays to 0

	sertxd ("START RACE")   	;send start of race message

	goto myloop

Lane1:
	sertxd ("Lane 1 is the winner!")
	goto main

Lane2:
	sertxd ("Lane 2 is the winner!")
	goto main
	
Lane3:
	sertxd ("Lane 3 is the winner!")
	goto main
Neil.
Thanks Neil

Working my way up to it. I'll be posting more on my other thread regarding this project. As I said I'm still working through some hardware and software concepts. This is only the beginning of the software. Obviously the sub-routines Lane1, Lane2 and Lane 3 will contain code for sorting out the second and third place finishers as well as code to light up the LED display.

Stay tuned - more to follow.

Al
 

geoff07

Senior Member
The thing to aim for is absolute simplicity and clarity. Let the computer do the work. Think in terms of layers - your objectives at the top, and the hardware interfaces at the bottom, hidden behind call statements and subroutines, and variables with meaningful names. What you don't want is the software equivalent of a breadboard, with wires (gotos) all over the place. Done right, you will be able to modify the code if needed, and understand it in six months time. The days of having to squeeze every last byte or cycle out of a microprocessor are gone, at least for most purposes, due to high clock speeds and large memory.

Also, don't be misled by the name Basic. Picaxe Basic isn't anything like the original BASIC, and competes very well indeed against C and other languages for microcontrollers, due to its powerful constructs, including select/case on the one hand, and its control of the PIC hardware on the other, and, especially, on productivity..
 
Top