Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 06:42 11 Nov 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Little PICAXE code help....

Author Message
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9750
Posted: 05:54am 27 Mar 2018
Copy link to clipboard 
Print this post

Yes, I still use PICAXE from time to time for simple stuff, but when I went to change a program for a data-filter I use an 08M2 for, the PICAXE program won't let me do it.





It keeps complaining about an IF without matching ENDIF, but from what I can see, I HAVE the endif in the right place. It is complaining about line 25 having that problem, but it does not care at all about the other 12 IF's above it needing an ENDIF....

Do any of the members here who still work with PICAXE know where I am wrong?

....I've got WAY to used to using MMBASIC, and I think I have forgotten some of my PICAXE-BASIC.
Smoke makes things work. When the smoke gets out, it stops!
 
radio_astro
Newbie

Joined: 21/05/2014
Location: Australia
Posts: 3
Posted: 06:29am 27 Mar 2018
Copy link to clipboard 
Print this post

You probably need to terminate each of the 14 or so " IF b0....etc" lines with an endif .

Hans
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9750
Posted: 07:42am 27 Mar 2018
Copy link to clipboard 
Print this post

You're right, I did have to!

As they are all single-line IF/THEN's, I did not expect they would need endif's of their own....

Oh well. Code passes syntax test now. Will now see if it works.
Smoke makes things work. When the smoke gets out, it stops!
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1106
Posted: 07:47am 27 Mar 2018
Copy link to clipboard 
Print this post

Hi Groggs

How did you manage to have all your bits free? Not doing anything else obviously.
I only had one liner IF's in the programs I could find. Glad its sorted.

ChopperP
ChopperP
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9750
Posted: 08:49am 27 Mar 2018
Copy link to clipboard 
Print this post

  Chopperp said  How did you manage to have all your bits free? Not doing anything else obviously.


Can you elaborate on what you mean by that?
Smoke makes things work. When the smoke gets out, it stops!
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1106
Posted: 09:24am 27 Mar 2018
Copy link to clipboard 
Print this post

I usually had b0 to b2 or b3 doing something eg. writing to a LCD

[code]Get next string of data & write to LCD & Tx (Looks for the "#" Chr)
serin 7, N2400,("#"),b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13
b1 = b3
gosub wrchr
b1 = b4
gosub wrchr
b1 = b5
gosub wrchr
b1 = b6
gosub wrchr
b1 = b7
gosub wrchr
b1 = b8
gosub wrchr
b1 = b9
gosub wrchr
b1 = b10
gosub wrchr
b1 = b11
gosub wrchr
b1 = " "
gosub wrchr
[/code]

ChopperP
ChopperP
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9750
Posted: 10:33am 27 Mar 2018
Copy link to clipboard 
Print this post

Oh, right. I see.

Yes, in my case, the PICAXE 08M2 is being used as a data-filter on the output of a 'Dumb' RF receiver. When the data is not valid, the receiver just outputs white-noise, which must be filtered out for reliable message reception.

The code is single-purpose only, and it just waits for valid data using the PICAXE's useful SERIN and qualifier idea. Once it has sent a message packet to the main system, it just sits there forever waiting on another one to forward.

Rogue characters(000-031 and 128-255 decimal) were making it past the original filter code every now and again, and confusing the hell out of the main system. Hence my adding the IF/THEN's to test each of the 13 bytes as valid first.
Smoke makes things work. When the smoke gets out, it stops!
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1106
Posted: 12:12pm 27 Mar 2018
Copy link to clipboard 
Print this post

Thanks for that Groggs. Great idea.

ChopperP
ChopperP
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3466
Posted: 03:12pm 27 Mar 2018
Copy link to clipboard 
Print this post

Speed may not matter, but if you put ":" after each "then" and change the "IF"s after the first one to ELSEIF and put an "ENDIF" at the end, then the comparisons will cease after the first invalid one is found (no ENDIF per line needed).

PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9750
Posted: 11:34pm 27 Mar 2018
Copy link to clipboard 
Print this post

Do you mean like this?





This compiles fine too.Edited by Grogster 2018-03-29
Smoke makes things work. When the smoke gets out, it stops!
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1106
Posted: 11:54pm 27 Mar 2018
Copy link to clipboard 
Print this post

Question? The CR at the end of your serout line, is that a PICAXE symbol for carriage return or is it for the other end or both?
ChopperP
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9750
Posted: 12:29am 28 Mar 2018
Copy link to clipboard 
Print this post

Yes it is. Well spotted.

PICAXE-BASIC has "CR" and "LF" predefined as carriage-return and line-feed respectively.

The transmitter nodes DON'T send a CR, they just send the data, which is always 13 bytes. Having sucked them into the PICAXE, once processed, that same data is sent out on another pin to the main system, with a CR added to the end. This is used by the MM main system as an 'End of message marker', allowing for all messages to be buffered in the MM COM port, and then the main loop just looks at the buffer. If there is something there, it reads bytes till it hits a CR, then stops. It then processes THAT message, then does it all again. That way, the beauty of the MM COM port buffer really comes into play as a fully automatic message queue.

By changing the COM port buffer RAM size, you can make the MM automatically queue a HEAP of messages if it has to, all of which will be processed one-by-one, till the buffer is empty, then the system just waits for more to arrive. They are a beautiful thing, those COM port buffers on the MM.....
Smoke makes things work. When the smoke gets out, it stops!
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1106
Posted: 12:50am 28 Mar 2018
Copy link to clipboard 
Print this post

Thanks for that Groggs,

I'm using a pair of old HOPE RF modules (CMM to a uM) which sends data in 32 byte lots including a CR & LF for each lot of data. (30 bytes + CR,LF; 62 bytes + CR,LF etc). My data gets checked for the correct length etc before sending.

I will look at your info on capturing the data a bit more closely later. I do something similar. I also use the Interrupt on the Com Port to signal Data In then go look later to see whats there.

ChopperP
ChopperP
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3466
Posted: 01:00pm 28 Mar 2018
Copy link to clipboard 
Print this post

  Grogster said   Do you mean like this?


Right. I thought from what you had said earlier that the colons (":") would be needed, but it looks better without, and if it compiles, it should work.

PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9750
Posted: 11:16pm 28 Mar 2018
Copy link to clipboard 
Print this post

Cool, thanks chums.

It's Easter weekend here from tomorrow, so I should get a chance to upload this code to a chip and try it out. Thanks to all who offered their help - I'm a little out of touch with PICAXE BASIC these days!
Smoke makes things work. When the smoke gets out, it stops!
 
plover

Guru

Joined: 18/04/2013
Location: Australia
Posts: 306
Posted: 06:03am 29 Mar 2018
Copy link to clipboard 
Print this post

Ooops, did not see page 2, I noticed the lack of ":"

Edited by plover 2018-03-30
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025