** Dim var as word : var=400 : HI2C_BAUD_RATE var assembles if useful**
Why? the script that calculates the correct regiser settngs will NOT read the variable. You must use a Constant. I have not assessed the impact of using a script so I cannot comment. But, using a variable will fail to set the appropiate registers correctly.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
So you can redefine a contant with another constant not a variable and
that would work with if then?
You can't use if.
You may be thinking of #ifdef
That is a preprocessor derivative that works with #define
But only in the preprocessor at compile time
The #derivatives nolonger exist at runtime.
I'm using version 0.98.01 with an 18F4550.
This below code is not working.
If var = 1 Then
#define HI2C_BAUD_RATE 400
End If
'
If var = 2 Then
#define HI2C_BAUD_RATE 100
End If
Does GCB allow #define statements to be used like this?
You assumption is correct. All #define are processed prior to ordering of conditions.
You can use a script.
Dim var as word : var=400 : HI2C_BAUD_RATE var assembles if useful
This method WILL NOT work.
Why? the script that calculates the correct regiser settngs will NOT read the variable. You must use a Constant. I have not assessed the impact of using a script so I cannot comment. But, using a variable will fail to set the appropiate registers correctly.
It may not produce a compiler error but it certainly will not work.
You are trying to access a runtime variable with a compile time statement.
The preprocessor will ignore the undknown portion.
That holds for all compilers not just GCBASIB.
On Mon, 5 Mar 2018 11:33 pm stan cartwright, stanleyella@users.sourceforge.net wrote:
Thanks!
Pleasure.
You can use a constant
#define myI2CSpeed 100
then change use#define HI2C_BAUD_RATE myI2CSpeed
Anobium
So you can redefine a contant with another constant not a variable and that would work with if then? Doesn't seem like if it's a #define.
It is a Define and it works.
You can't use if.
You may be thinking of #ifdef
That is a preprocessor derivative that works with #define
But only in the preprocessor at compile time
The #derivatives nolonger exist at runtime.