is there a simple way to make the following code valid for any clock frequency:
#if F_CPU == 8000000UL # define F_CPU_STR "8MHz" #elif F_CPU == 12000000UL # define F_CPU_STR "12MHz" #elif F_CPU == XY000000UL # define F_CPU_STR "XYMHz" #else # warning "unknown frequency" # define XSTR(_s_) STR(_s_) # define STR(_s_) #_s_ # define F_CPU_STR XSTR(F_CPU) "Hz" // output may contain a lot of zeros and 'UL' of constant F_CPU #endif printfP(PSTR("CrystalFrq: " F_CPU_STR "\n"));
As you can see I want to put the frequency in MHz units as string into the binary.
I could use the compiler, but I want to verify with a simple glance on the binary file for what it was compiled.
A division by 1000000UL with a later stringifictaion seems not wo work.
I was wondering, if I already got the last out of the preprocessor. There are some discussions, if the preprocessor can perform integer divisions or not, for example at http://stackoverflow.com/questions/1560357/can-the-c-preprocessor-perform-integer-arithmetic.
And there is also the preprocessor boost library, which can also perform integer arithmetics.
I also studied this thread:
Is there a easy way to avoid the if/elif/else preprocessor clause with a closed expression?
BTW: Maybe the GNU make tool can already calculate F_CPU_MHZ = F_CPU/1000000UL somehow?!
A solution for this is not essential, but it would make my code more generic...