Directives & Predefined Flags

Beta Testing discussion on mikroPascal PRO for AVR.
Post Reply
Author
Message
JohannesH
Posts: 68
Joined: 23 Apr 2007 07:51

Directives & Predefined Flags

#1 Post by JohannesH » 02 Dec 2008 13:00

Hi!

First of all thank you for the beta release of the pascal compiler!

Now the problem.

Project Settings: ATmega16, Clock 16.000000

Code snippet:

Code: Select all

{$IFDEF ATmega16}
    PORTC := 1;
{$ELSE}
    PORTC := 0;
{$ENDIF}
The definition for ATmega16 is not found and the code within {$ELSE} always is generated.
This is not what the documentation is tellung us: See Compiler Directives / Predefined Flags.

Additional Question: Please give us a list of ALL predefined flags, this is missing from the documentation.

Additional Question: Is it possible to give us a predefined flag which represents the clock frequency set within the project settings? (e.g. F_CPU_8000000 for 8 MHz clock)

regards
Johannes

User avatar
zristic
mikroElektronika team
Posts: 6608
Joined: 03 Aug 2004 12:59
Contact:

Re: Directives & Predefined Flags

#2 Post by zristic » 02 Dec 2008 14:36

Thanks for the report.

Predefined flags in form of device name are mistakenly omitted. We will fix this quickly. :oops:
Please give us a list of ALL predefined flags, this is missing from the documentation.
The list will be published as soon as we fix the problem from above.
Is it possible to give us a predefined flag which represents the clock frequency set within the project settings? (e.g. F_CPU_8000000 for 8 MHz clock)
Sure. Just suggest us some shorter format, the one you have given is too long for typing (also, too many zeros, it may be mistyped easily).
Thanks.

jpc
Posts: 1986
Joined: 22 Apr 2005 17:40
Location: France 87

#3 Post by jpc » 02 Dec 2008 15:40

regarding the clock, this seems to me a tricky one , as there are allmost infinite number of frequency's there will be allmost infinite number of flags needed !

User avatar
zristic
mikroElektronika team
Posts: 6608
Joined: 03 Aug 2004 12:59
Contact:

#4 Post by zristic » 02 Dec 2008 15:45

jpc wrote:regarding the clock, this seems to me a tricky one , as there are allmost infinite number of frequency's there will be allmost infinite number of flags needed !
True, but only one will be defined at the time, the one which is setup in the project.

jpc
Posts: 1986
Joined: 22 Apr 2005 17:40
Location: France 87

#5 Post by jpc » 02 Dec 2008 15:54

if i get it right , you suggest making the result of clock_kHz and clock_mHz available as flags ?

JohannesH
Posts: 68
Joined: 23 Apr 2007 07:51

#6 Post by JohannesH » 02 Dec 2008 16:17

Hi zristic!

Thank you for the very quick response!
I would be very happy with a flag for the frequency (in addition to the already available functions).

Here is a new suggestion for a shorter name: Fnnnnn
This is the shortest I can imagine.
F - Frequency
nnnnn - KiloHz
This gives us a range from 1 KHz to 99.999 KHz which is 99 MHz.

Can you imagine to do something like this?

regards
Johannes

JohannesH
Posts: 68
Joined: 23 Apr 2007 07:51

#7 Post by JohannesH » 03 Dec 2008 08:09

@jpc

The difference to the functions you mentioned is that a flag would give the clock frequency information at compile time instead of runtime.
This is very useful for conditional compilation depending on the clock frequency (e.g. defining constants with different values depending on the clock frequency).

Johannes

jpc
Posts: 1986
Joined: 22 Apr 2005 17:40
Location: France 87

#8 Post by jpc » 03 Dec 2008 09:19

i think you can already do this , if your constant is defined as function of clock it will be calculated correctly at compile-time. I use this quite often and do not see how to implement this by flags.

User avatar
zristic
mikroElektronika team
Posts: 6608
Joined: 03 Aug 2004 12:59
Contact:

#9 Post by zristic » 03 Dec 2008 09:51

jpc is right, you can use Clock_kHz and Clock_MHz for that purpose. See help for details.
If that is not good for you, then we will discuss the predefined flag further.

JohannesH
Posts: 68
Joined: 23 Apr 2007 07:51

#10 Post by JohannesH » 03 Dec 2008 13:58

Hi!

I had a further look into this issue.
First I have to say that you are right that one can use Clock_KHz to define constants and it will be done at compile time.
That helps a lot in all cases where you can have a math formula to define the constant. But in other cases where you dont have such a math formula it does not help. Also in cases where different code should be included into the final program depending on the clock frequency you would need such a flag.

You also have this included into the new C compiler (__FOSC__) as a macro. I know that microPascal does not support such macros (but I would be very happy if it would) and because of this a predefined flag can be seen as something like "poor mans macro" for this purposes.

So, please think about including it into the compiler.

Thank You
regards
Johannes

Post Reply

Return to “mikroPascal PRO for AVR Beta Testing”