DEFINE in Oshonsoft

Thread Starter

camerart

Joined Feb 25, 2013
3,830
Hi,
I'm following some Arduino code, where lines like this: [ #Define ak8963_st1 0x02 / / data ready STATUS Bit 0 ]
need writing into Oshonsoft.
How is it done please?
Camerart
 

ericgibbs

Joined Jan 29, 2010
21,442
hi C,
Clip from Osh manual.
E
Configuration Parameters.
There are two configuration parameters CONF_WORD and CONF_WORD_2 (not available for all devices) that can be set using DEFINE directive to override the default values.

The clock frequency of the target device can be specified by setting the CLOCK_FREQUENCY parameter (the value is expressed in MHz).

These parameters should be setup at the beginning of the basic Program.
For example:

DEFINE CONF_WORD = 0x3F72
DEFINE CLOCK_FREQUENCY = 20

#Define ak8963_st1 0x02 >> Define ak8963_st1 = 0x02
 

Thread Starter

camerart

Joined Feb 25, 2013
3,830
Hi E,
I'm getting errors when compiling. I think there's something wrong regarding BYTES. The 0x02 is a REGISTER ADDRESS.

This is what my CONFIG WORD AND CLOCK SPEED look like:

Define CONFIG1L = 0x00
Define CONFIG1H = 0x09 'INT OSC EXT CLOCK at RA6
Define CONFIG2L = 0x1e
Define CONFIG2H = 0x00
Define CONFIG3L = 0x00
Define CONFIG3H = 0x80 'Set for HVP
Define CONFIG4L = 0x80
Define CONFIG4H = 0x00
Define CONFIG5L = 0x0f
Define CONFIG5H = 0xc0
Define CONFIG6L = 0x0f
Define CONFIG6H = 0xe0
Define CONFIG7L = 0x0f
Define CONFIG7H = 0x40
'Define SIMULATION_WAITMS_VALUE = 1 'Comment in for SIM out for PIC
Define CLOCK_FREQUENCY = 8

C.
 

ericgibbs

Joined Jan 29, 2010
21,442
hi,
OK, can you post a clip showing how
#Define ak8963_st1 0x02

is used/called in the program, see how we can rework it.

E
try:
SYMBOL ak8963_st1 = 0x02' this should assign 0x02 to that label
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,830
hi,
OK, can you post a clip showing how
#Define ak8963_st1 0x02

is used/called in the program, see how we can rework it.

E
try:
SYMBOL ak8963_st1 = 0x02' this should assign 0x02 to that label
Hi E,
Previously I simply used the actual address, but while copying the Arduino code thought it may look neater, so it's not important.

FIND 'eric' for the pertinent lines
C.
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
3,830
hi,
OK, can you post a clip showing how
#Define ak8963_st1 0x02

is used/called in the program, see how we can rework it.

E
try:
SYMBOL ak8963_st1 = 0x02' this should assign 0x02 to that label
Hi E,
Just spotted your EDIT!
I get this error: [ Constant argument can not be used here '0x02' ]
But const works, as above.
Thanks, C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,830
Hi,
Trying to tidy up the program, I've messed up the code, so I've learnt how to use CONST, but I have had to revert to the old style. I'll try again later.
C.
 

djsfantasi

Joined Apr 11, 2010
9,237
I’m not familiar with Oshonsoft, but from your example it appears that “define” is used differently than in Arduino C.

I AM familiar with Arduino code. There is no “=“ in the Arduino “#define” syntax. In Arduino, #define is used to create a macro. Hence:
#define limitUpper 255;​
is processed at compile time. All occurrences of the token “limitUpper” are replaced by 255. The resultant code is then compiled.

This can also define a common line of code to make the code more readable, like this:
#define IsExitFunc if(digitalRead(pinCtl)==1)exit​
Then, in the actual code, you can write
IsExitFunc;​

Good programming practice is to use the “const” type qualifier for numbers, strings/car arrays. It actually results in smaller code.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,830
I’m not familiar with Oshonsoft, but from your example it appears that “define” is used differently than in Arduino C.

I AM familiar with Arduino code. There is no “=“ in the Arduino “#define” syntax. In Arduino, #define is used to create a macro. Hence:
#define limitUpper 255;​
is processed at compile time. All occurrences of the token “limitUpper” are replaced by 255. The resultant code is then compiled.

This can also define a common line of code to make the code more readable, like this:
#define IsExitFunc if(digitalRead(pinCtl)==1)exit​
Then, in the actual code, you can write
IsExitFunc;​

Good programming practice is to use the “const” type qualifier for numbers, strings/car arrays. It actually results in smaller code.
Hi D,
As mentioned, I was using some Arduino code that I've been given, as an example, but every time I try to read Arduino, it confuses me. It just looked neat.
I already have a CONST in my program for [ PI ], but that's a number, and I am not certain CONST can be used for a REG ADDRESS.
Anyway, in my program there is a lot that members here have written for me, that conflict with REG CONST, so I'll leave it for now.
C.
 

djsfantasi

Joined Apr 11, 2010
9,237
Hi D,
As mentioned, I was using some Arduino code that I've been given, as an example, but every time I try to read Arduino, it confuses me. It just looked neat.
I already have a CONST in my program for [ PI ], but that's a number, and I am not certain CONST can be used for a REG ADDRESS.
Anyway, in my program there is a lot that members here have written for me, that conflict with REG CONST, so I'll leave it for now.
C.
Good point. On the Arduino, registers are defined in the header files. If you’ve included the proper header files, you should simply assign the desired values in the setup() function. Particularly near the same code block that the initialization functions are called (this is optional, but helps in debugging.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,830
Good point. On the Arduino, registers are defined in the header files. If you’ve included the proper header files, you should simply assign the desired values in the setup() function. Particularly near the same code block that the initialization functions are called (this is optional, but helps in debugging.
Hi D,
Have you heard of the [ infinite monkey ] thereum? This is similar to how I program :)
C.
 
Top