#ifdef picaxe

emilio0

New Member
Ciao a tutti,
ho bisogno per cortesia che qualcuno mi spieghi il funzionamento delle seguenti righe:

[ code]
#picaxe 18m2
#Define picaxe
#ifdef picaxe
symbol lcd=c.0 'Assign LCD to port
#else
symbol lcd=c.3 'Assign LCD to port
#endif
[ /code]

Le ho trovate anni fa nel forum ma non mi ricordo assolutamente in quale contesto. Ho cercato inultimente negli archivi ma sicuramente non e' di un archivio specifico ma si tratta di una aggiunta fatta per agevolare qualche lavoro in discussione.
Ora sto lavorando contemporaneamente con 08m2 e 18m2 e ogni volta che cambio devo (ovviamente) cambiare l'impostazione dell'editor.
Le suddette righe di programma potrebbero ovviare al mio problema oppure hanno tuttaltro scopo?
Quale?
Sto iniziando ad capire l'uso di #ifdef e ho capito che serve per sostituzione, e da esempi trovati in giro mi lasciano molto perplesso. Probabilmente (spero) di capirla in breve tempo lavorandoci con prove di vario genere.
Ringrazio anticipatamente chi volesse darmi una spiegazione.

у begins to all,
I need, please explain to me the functioning of the following lines:

Code:
#picaxe 18m2
#Define Picaxe
#IFDEF PICAXE 
    Symbol LCD = C.0 'Assign Lcd to Port
#else
    Symbol LCD = C.3 'Assign Lcd to Port
#endif
[ /code]

I found them years ago in the forum but I absolutely don't remember what context. I searched in the archives but it is certainly not a specific archive but it is an addition done to facilitate some work under discussion.
Now I am working simultaneously with 08m2 and 18m2 and every time I change I have to (obviously) to change the editor setting.
Could the aforementioned program lines remedy my problem or do they have the whole purpose?
Which?
I am starting to understand the use of #ifdef and I understood that it serves by replacement, and from examples found around they leave me very perplexed. Probably (I hope) to understand it in a short time by working with evidence of various kinds.
I thank in advance whoever wanted to give me an explanation.
 
Hi Emilio,

I think I understand your request: you want to select a different pin to connect your LCD to, depending on which M2 chip you use, right? That is a very clear and useful way to write your code in a maintainable way, allowing different Picaxe types to support the same functionality. So you are almost there ... .

The key here is to understand that the #Picaxe 18M2" statement is actually a very specific, shorter statement for the following general #define statement (I did not know either, had to look it up so I learned something here, too):
#picaxe 18m2 ---> #define _18m2.
See this page that defines the #picaxe directive where this is explained. Note the "_" character before the 18m2 name in the #define statement, this is crucial.

So now that you know that _18M2 is the defined symbol with your #picaxe directive, you can check in your program code whether it is actually defined or not:

Code:
REM select the actual picaxe device here
#picaxe 18M2
REM #picaxe 08M2

#ifdef _18M2
    symbol lcd=c.0 'Assign LCD to port
#else
    symbol lcd=c.3 'Assign LCD to port
#endif

As a test, when you enter the above code in the programming editor it should work. If you change the picaxe name in the #picaxe directive to 08M2 (thus defining the _08m2 symbol name), the PE will then ask you whether the picaxe type in the editor should change as well (generally yes).
Did this answer your question fully?
 
Last edited:
Hi Cranenborg,
Thanks for the help, you understood my problem perfectly but partially solved, look at the program I made for test.
With the definition for 08m2 it works correctly but I replace it with 18m2 does not go to the display but at terminal.
Where am I wrong in the program?

[ code]
;#picaxe 08M2 ;c.0 (works properly)
#picaxe 18M2 ;c.3 (The terminal starts instead of the display)

#define picaxe
#ifdef _08m2
symbol lcd=c.0 'Assign LCD to port 08m2
#else
symbol lcd=c.3 'Assign LCD to port 18m2
#endif

Serout lcd,N2400,(254,128," ",Cr,Lf)
Serout lcd,N2400,(254,192," ",Cr,Lf)
pause 700 ;It is used to see the working program
Serout lcd,N2400,(254,128,"xxxx5555")
[ /code]
 
I now note that:
  • you try to use the same pin for the LCD as for the output pin for the terminal (those are indeed C.0 for the 08M2, C.3 for the 18M2), that may not work properly - at least it does not work for the 18m2 version. I would suggest to always connect the LCD to a different pin (in the block diagram of the chip in the Programming Editor: an OUT pin instead of the Serial Out pin), change this also in the two symbol definitions and test again.
  • You still use a "#define picaxe" statement, but it is not useful, since you already use the #picaxe symbols. I suggest to delete this statement.

Could you also show us your hardware setup?

Regards,
Jurjen
 
Last edited:
To use another door to use the display simulator, it was something I had already taken into consideration, but the output goes to the terminal and the comfort of the software display simulator is missing, to observe live what will be displayed. It works if I intervene in the settings, and then the "IFDEF _08M2" education decays.
I needed this to emulate "programs" (tests) with different processors.
For this problem I have not currently hardware, but it was used to manage different processors such as you intuited, for crossed tests.
It is clear that if I have to mount two or more hardware to do display tests, it practically requires time and material, therefore not practical, even if I would like.

Of course, everything would fall if there was the possibility in some way to obtain cio with software command similar to "IFDEF _08m2" or a few particular rounds.
If you have other tips or "tricks" welcome, and thank you anyway for the attention dedicated to me.

Greetings Emilio
 
but I replace it with 18m2 does not go to the display but at terminal
What version of PE are you using?

I'm using v6.2.1.0 and when I set the simulation LCD to use C.3 and then run your program in post #3 with #picaxe 18M2 uncommented it open the LCD on C.3:
18M2 with LCD on C.3.PNG
 
Hi Flenser,
Thank you for taking up the post but for it to work you still need to go into simulation and select the correct pin to have the display (simulated editor SW).

The whole discussion focuses on the work of the editor (6.2.1.0) in emulation with the function reported above.

example:
I start with sheet 1= 08m2 with #picaxe 08m2 and everything works.
in sheet 2= 18m2 and I have to go back into the simulation (rightly) to notify the editor of the processor change. But at this point the text from the program that should go to the display is not displayed (with #ifdef _08m2)
my aim was to switch from the 08m2 program to the 18m2 program and vice versa without going into simulation
and having to change every time I switch from one to the other.
So the editor in all sheets available at the moment, set the same processor.
If one sheet uses 08m2 and another uses 18m2 I have to manually switch processors in the editor each time for one or the other.
Evidently a similar function is not available.

everything at the HW level works correctly by telling the editor to put the correct processor without any other changes.
I hope I have expressed my thoughts clearly and that Google translates it correctly.

Greetings Emilio
 
To do this you need two workspaces, one set to 08M2 PICAXE type and the other set to 18M2 (and with the simulator setup (e.g. LCD pin) as you require) .
Both workspaces can share the same .bas code file.
You then simply swap between the two workspaces to swap between chip types/simulator configuration.

Note you will need to remove the #picaxe line completely, because the picaxe type now comes from the workspace setting, not the code file.
 
my aim was to switch from the 08m2 program to the 18m2 program and vice versa without going into simulation
and having to change every time I switch from one to the other.
Emilio,

You misunderstand how the pin is chosen.

The SEROUT command can be used on more than one pin so the Program Editor cannot automatically choose which pin the simulation LCD is connected to based on which #PICAXE directive your code is using.

You must always choose which pin to use when you enable the LCD simulation in the options:
Untitled.png
 

Attachments

  • Saved Workspaces.png
    Saved Workspaces.png
    11.1 KB · Views: 2
You then simply swap between the two workspaces to swap between chip types/simulator configuration.
Technical,

I was taking some screenshots to show Emilio and I could not get the different LCD simulation options to be saved with the two different workspaces.

I setup an 08M2 workspace with the LCD simulation setup to AXE033, 16x2 on C.0:
08M2 Workspace with LCD on C.0.PNG

I clicked OK on the options dialog, reopened the options to check the settings, saved the workspace, closed PE, restarted PE, which opened my 08M2 workspace, and opened the options dialog to confirm the LCD simulation settings were still correct in my 08M2 workspace.

I setup an 18M2 workspace with the LCD simulation setup to AXE133, 20x2 on C.3:
18M2 Workspace with LCD on C.3.PNG

I clicked OK on the options dialog, reopened the options to check the settings, saved the workspace, closed PE, restarted PE, which opened my 18M2 workspace, and opened the options dialog to confirm the LCD simulation settings were still correct in my 18M2 workspace.

At this point PE is running with the 18M2 workspace open.
I then opened my 08M2 workspace and the LCD simulation options are now AXE133, 20x2 on C.3 so these settings do not appear to have been saved with the workspace.
08M2 Workspace with LCD on C.0#2.PNG
 

Attachments

  • 18M2 with LCD on C.3.PNG
    18M2 with LCD on C.3.PNG
    545.7 KB · Views: 2
Last edited:
Hello everyone,

for Technician:
using 2 workspaces (.wsp) set with different processor, ok. But if I load the same file with the two workspaces it tells me that the file cannot be loaded because it is used by another program. How do I share?

for Flanges:
after creating the 2 workspaces separately and closing them and reopening them, the second workspace tells me that the file cannot be loaded because it is used by another program.

Greetings Emilio
 
after creating the 2 workspaces separately and closing them and reopening them, the second workspace tells me that the file cannot be loaded because it is used by another program.
You cannot start two copies of PE and use them to open different workspaces that open the same .bas file.

You can only use one copy of PE.
- Start one copy of PE
- create two workspaces
- open one of the two workspaces
- open the .bas file in the workspace that you have opened.

The LCD simulation settings do not appear to be saved with the workspace so I do not think you will be able to use two workspaces to switch between 08M2 & 18M2 with different LCD simulation settings.
 
Emilio,

You can use two copies of PE if you only have the .bas file open in one of them.

Open the first copy of PE with the LCD simulation on pin C.0
Open the 08M2 workspace

Open the second copy of PE with the LCD simulation on pin C.3
Open the 18M2 workspace

Switch to the first copy of PE
Open the .bas file
Write and test your code changes in simulation for the 08M2
Close and save the .bas file

Switch the second copy of PE
Open the .bas file
Write and test your code changes in simulation for the 18M2
Close and save the .bas file

and repeat as you switch between your testing for the 08M2 & 18M2
 
Hi Flange,
the explanation is clear and I appreciate it very much, but it is too cumbersome.
I prefer to use a single PE, load the program, modify the standard definitions #picaxe 08m2 and #picaxe 18m2, alternatively enabling one or the other, set the display port, save it. Change the #picaxe xxx and display port settings without charging it and test it with the other processor. I have used this system up until now, but I thought you would suggest a faster/convenient system.
Anyway THANK YOU, you suggested some possibilities that I didn't know about and would never have used.

Greetings from Emilio who is always learning new things.
 
Back
Top