Syntax error, what am I doing wrong?

regpye

New Member
I have not been able to overcome this syntax error, help please. 14M2 chip using in only pin.

symbol filler_time = 0

if pinC.3 = 0 then
filler_time = 30
endif
if pinC.3 = 1 then
filler_time = 240
endif
 
symbol filler_time = 0 doesn't declare a variable 'filler_time' and set it to zero; it just sets a 'shortcut' called 'filler_time' to a value of zero.

So filler_time = 30 is trying to set memory location "0" to a value of 30, but using a syntax that isn't allowed - you would have to use
poke filler_time,30 to do that.

But what you're probably wanting to do, is set up a shortcut to one of the 'named' memory locations (b0->b27) that you can load with a direct 'equate' operation, so symbol filler_time = b10 (for example) would let you use filler_time = 30 (and would set b10 to 30)

One tends to use the 'unnamed' memory locations, only when the 'named' ones have been exhausted (because they're a lot less flexible)
 
symbol filler_time = 0 doesn't declare a variable 'filler_time' and set it to zero; it just sets a 'shortcut' called 'filler_time' to a value of zero.

So filler_time = 30 is trying to set memory location "0" to a value of 30, but using a syntax that isn't allowed - you would have to use
poke filler_time,30 to do that.

But what you're probably wanting to do, is set up a shortcut to one of the 'named' memory locations (b0->b27) that you can load with a direct 'equate' operation, so symbol filler_time = b10 (for example) would let you use filler_time = 30 (and would set b10 to 30)

One tends to use the 'unnamed' memory locations, only when the 'named' ones have been exhausted (because they're a lot less flexible)
Thanks for your quick reply and answer
Do you mean like this? I tried a few things before seeing your reply and I think it may be what you mean.

symbol filler_time = b0
let b0 =0
if pinC.3 = 0 then
filler_time = 30
endif
if pinC.3 = 1 then
filler_time = 240
endif

Now how can I show on the screen what the value is so that I know it is working properly?
 
Thanks for your quick reply and answer
Do you mean like this? I tried a few things before seeing your reply and I think it may be what you mean.

symbol filler_time = b0
let b0 =0
if pinC.3 = 0 then
filler_time = 30
endif
if pinC.3 = 1 then
filler_time = 240
endif

Now how can I show on the screen what the value is so that I know it is working properly?
It's okay I worked it out.
Code:
main:
symbol filler_time = b0 
let b0 =0
if pinC.3 = 0 then 
    filler_time = 30
endif
if pinC.3 = 1 then
    filler_time = 240
endif 
debug filler_time; transmit value to computer screen
pause 5000; short delay
goto main
 
If you use
Code:
symbol filler_time = b0
Then it is better (and far less confusing) to be consistent and use filler_time throughout, and not switch between b0 and filler_time.

Also, it is easier for someone to follow the program if you group all your symbol definitions at the beginning of the program. They are not executable statements - they are directions to the compiler
 
Note that DEBUG has shortcomings and in particular can make timings difficult if critical.

Most experienced users will want to use SERTXD to display values to the console: SERTXD ("Filler Time: ",#filler_time,cr,lf)

You can put in quoted strings; "#" indicates that the ASCII value for the variable is printed--if omitted, the binary value is printed (and might be an unprintable character, in which case you wouldn't see anything for the value); "cr" and "lf" are predefined constants for "carriage return" and "line feed" which will move the next character position (effective cursor) to the line following the one printed by SERTXD.
 
Then it is better (and far less confusing) to be consistent and use filler_time throughout, and not switch between b0 and filler_time.
I tried that and got a syntax error. I found that it works Okay the way I did it. Maybe you have a different method that what I used?
 
Using your code from post #4
Code:
main:
symbol filler_time = b0 
let filler_time =0
if pinC.3 = 0 then 
    filler_time = 30
endif
if pinC.3 = 1 then
    filler_time = 240
endif 
debug filler_time; transmit value to computer screen
pause 5000; short delay
goto main
where the initialisation of filler_time is done using filler_time rather than b0, it works. The only other reference in your bit of code to b0 is in the symbol definition, where you define what filler_time is. If you say
Code:
symbol filler_time = filler_time
then you will get a syntax error, because the compiler does not know what filler_time is (you can't define something in terms of itself, and in any case you would then lose the connection to b0 altogether).
 
OK here is my take to incorporate into your code:
Code:
symbol filler_time = b0        'define what filler_timer referes to

init:
    #terminal 9600        'open terminal window
    pause 500            'allow terminal to open and connect
    filler_time = 0        'initialise to 0
    
main:
    if pinC.3 = 0 then    'if pinc.3 is low, then filler_time is 30
        filler_time = 30
    endif

    if pinC.3 = 1 then    'if pinc.3 is high then filler_time is 240
        filler_time = 240
    endif
    
    sertxd (#filler_time, 13, 10)
    pause 1000            'hold here for 1 second
    goto main
I would be tempted to use a symbo, to refrence pinc.3 aswell, but that is a prefrence more than anything else.
Something else to note, the input pin can only be 1 of 2 states. while it wqont do any harm there is no point in setting the filler_time variable to 0 on every loop.
 
Top