Quantcast
Channel: MCS Electronics Forum
Viewing all articles
Browse latest Browse all 20771

BASCOM-AVR : Const - how to Create a Const and set a default value? : REPLY

$
0
0
You might want to work your way through this: [url]http://community.silabs.com/mgrfq63796/attachments/mgrfq63796/4/894/1/Radio_Header_Migration.pdf[/url] A #define in C does simply text replacement, in this case it connects human readable identifiers with the corresponding value. So far it equals to a Bascom constant, where at compile-time each occurrence of the constant is replaced with its value. What's different here is, that the const u8 RFM... will put the defined values into flash, which equals Bascom's Data statements. From there it can processed in order for init and other purposes. An equivalent would be: [code:1:aa16072d52]Const myconst1 = 14 Const myconst2 = 33 Const myconst3 = 69 ... const_data: Data myconst1, myconst2, myconst3[/code:1:aa16072d52] Your const/alias stuff won't work, but guess you found that out already. That still does not solve the problem with the default values, you can store them in a separate Data statements. Beside sequential processing them in order with the order of constants, the problem is to connect the defaults directly to the constants, means you can't tell a default by the name of the constant. So another approach would be to use the constants as index value and retrieve corresponding values from Data statements via lookup. The disadvantage is, it blows up the code and the constants can't be directly used, instead in every case the call of a function is neccessary, which retrieves the value(s) from its keys. [code:1:aa16072d52]Const myconst1 = 0 Const myconst2 = 1 Const myconst3 = 2 ... const_data: Data 14, 33, 69 const_data_defaults: Data 65, 11, 87[/code:1:aa16072d52]

Viewing all articles
Browse latest Browse all 20771

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>