Help with compiler syntax

chris_b

New Member
I'm using the linux compiler for the 18X device and having trouble understanding some errors it gives me:

1) A program containing the following:

symbol sdi = 5 ' 9852 serial data in (on sdio pin)

low sdi

out_32:
For b13 = 0 To 15 ; shift out MS 16 bits
sdi = bit15 ; from the MSB
pulsout sclk, us10 ; pulse sclk
w0 = w0 * 2 ; shift the word left one place
Next

Gives this error

PICAXE-18X Enhanced Compiler. Version 0.4

sdi = bit15 ; from the MSB
^
line# 110, col# 8

Error: syntax error
--------------------------------------------
2) A program containing the following:

symbol sdi = outpin5 ' 9852 serial data in (on sdio pin)

low sdi

out_32:
For b13 = 0 To 15 ; shift out MS 16 bits
sdi = bit15 ; from the MSB
pulsout sclk, us10 ; pulse sclk
w0 = w0 * 2 ; shift the word left one place
Next

Gives this error

low sdi
^
line# 43, col# 5

Error: This command requires '5' not the variable 'pin5'!
---------------------------------------------

3) This compiles ok:

symbol sdi = 5 ' 9852 serial data in (on sdio pin)

low sdi

out_32:
For b13 = 0 To 15 ; shift out MS 16 bits
outpin5 = bit15 ; from the MSB
pulsout sclk, us10 ; pulse sclk
w0 = w0 * 2 ; shift the word left one place
Next

-----------------------------------------------


I'm trying to be symbolic about this, and 3) isn't doing that. I can see that 1) could be expected not to work as the symbol replacement in the For loop says "5 = bit15". I'm surprised that 2) isn't ok.

Any ideas, have I misunderstood something?

TIA

Chris
 

hippy

Ex-Staff (retired)
This is a practical limitation which is very difficult to overcome and doesn't only affect the PICAXE but other programming languages as well.

"Low X" requires that X be a number constant, "X=bit15" requires that X be a variable name, and it's not possible to define X as both using Symbol.

The issue with code (2) is that what you intend as "low sdi" becomes "low outpin5" ( which is the same as "low pin5" as outpin5 and pin5 are synonyms, hence the error message itself ). What happens there is that outpin5 has a value 0 or 1 depending upon what the signal read on pin 5 is, low or high, so the command, once outpin5 has been evaluated as a variable becomes "Low 0" or "low 1", not the "Low 5" which was intended and why the compiler specifically issues an error for such use.

The simplest way to work round this issue is to define separately named but related Symbol definitions -

Symbol sdi_output = outpin5
Symbol sdi_input = pin5
Symbol sdi_pinnumber = 5

Low sdi_pinnumber
sdi_output = bit15
bit15 = sdi_input

or something along those lines.

Alternatively, you can lose the "sdi_pinnumber" definition and replace "Low sdi_pinnumber" with "sdi_output=0".
 
Last edited:

chris_b

New Member
Thanks for the explanation, all clear now.

I only have to use multiple definitions in the case of my sdi pin as that's the only one that's going to appear on the lhs of an expression and hence require the outpin form. In all other cases in my application the output pins are explicitly set or pulsed, eg the sclk in my example. so the following works

For the sdi pin:

Symbol sdi_output = outpin5
Symbol sdi_pinnumber = 5

low sdi_pinnumber

sdi_output = bit15


For the other output pins:

Symbol sclk = 3

low sclk

pulsout (sclk, us10)
 
Top