I want to make a Flowcode program for different microcontrollers. I use also C-codes for some special registers. But different microcontrollers can have different registers. Using C-code with registers, which are not defined, will give an error.
Is it possible to define regsiters/variables in the following way?
if
{
char REGISTER_NAME;
....
}
else
{
.....
}
Kind regards
Jan Lichtenbelt
Register defintion
- Jan Lichtenbelt
- Posts: 797
- Joined: Tue Feb 17, 2009 8:35 pm
- Location: Haren GN, the Netherlands
- Has thanked: 128 times
- Been thanked: 264 times
- Contact:
- JonnyW
- Posts: 1230
- Joined: Fri Oct 29, 2010 9:13 am
- Location: Matrix Multimedia Ltd
- Has thanked: 63 times
- Been thanked: 290 times
- Contact:
Re: Register defintion
Hi Jan. You would typically use the pre-processor for this:
This means that the C compiler would never see the inappropriate definition. For portability it may be an idea to define a 'generic' register name that you can use anywhere you want:
You will then be able to use 'ANY_REGISTER_NAME' anywhere in your code and not have to change it.
Cheers,
Jonny
Code: Select all
#ifdef MY_CHIP
char REGISTER_NAME;
#else
char YOUR_REGISTER_NAME;
#endif
Code: Select all
#ifdef MY_CHIP
char MY_REGISTER_NAME;
#define ANY_REGISTER_NAME MY_REGISTER_NAME
#else
char YOUR_REGISTER_NAME;
#define ANY_REGISTER_NAME YOUR_REGISTER_NAME
#endif
Cheers,
Jonny