一 前言
很多人使用keil的時候感覺keil的configuration wizard 很神奇,用起來特別方便,但是苦於不知道怎么去編寫自己的configuration wizard,其實keil的help文檔就有,只是很多人用着感覺英文不方便,又或者看了沒理解,為此,特寫了一個教程,希望大家能從中學到一些知識。
二 基本介紹
Configuration wizard 只能在keil中使用,能夠可以通過菜單的方式對一些預設值進行設置,修改,配置。
三.基本使用方法
在文檔中寫入 標記開始
<<< Use Configuration Wizard in Context Menu >>>
當檢測到以上關鍵字,keil就會認為這個文檔里面存着Configuration Wizard,並開始搜索內容中的其他關鍵字。當檢測到以下內容的時候,停止搜索
<<< end of configuration section >>>
注意: <<< Use Configuration Wizard in Context Menu >>>和<<< end of configuration section >>> 必須被“//”屏蔽 或者“;”。因為是額外的信息不能影響到文檔的編譯所以,必須屏蔽,但是屏蔽不可以用批量屏蔽如“/* 。。。。 */,即使“/* ”和“*/”在同一行也不可以。並且“//”或者“;”必須在行首。
下面我們來一步步完善這個例子:
新建一個test.c文檔作為測試文檔。
在文檔中輸入:
//<<< Use Configuration Wizard in Context Menu >>>
//<<< end of configuration section >>>
保存並且關閉,再打開
就可以看到Configuration Wizard 的選項了。點擊進去可以看到選項已經出來了,只是里面的內容還是空的。
命令字
1.標題命令字 <h>和</h>
<h>和</h>必須成對出現,<h>表示一個段落(組)開始,</h>表示段落(組)結束,如果只有<h>沒有</h>系統就會報錯。
我們繼續擴充我們的測試代碼:
//<<< Use Configuration Wizard in Context Menu >>>
//<h> this is a heading
//</h>
//<<< end of configuration section >>>
2.使能組<e>和</e>
和<h>類似,但是<e>確是有更大的功能,Enable。舉個例子:
//<<< Use Configuration Wizard in Context Menu >>>
// <h> this is a heading
// </h>
// <e>this is an options
// </e>
//<<< end of configuration section >>>
這里需要說明的是<e>只是一個單選的,enable or disable ,因此這里開始我們就想怎么跟我們的程序結合起來了。於是我在</e>的后面定義了一個8bit的tmp變量並且把他的值賦為0。
//<<< Use Configuration Wizard in Context Menu >>>
// <h> this is a heading
// </h>
// <e>this is an options
// </e>
uint8 tmp = 0;
//<<< end of configuration section >>>
當我把this is an options 打上勾勾的時候,
就自動變成了tmp=1:
這就是我們想要的。通過配置菜單,進行一些配置就可以改變到編譯的c文件的內容
那么如果我只想設置tmp的某一位,比如第三位,怎么辦?
通過<e.n> 命令,n表示第幾位。
選擇前:
//<<< Use Configuration Wizard in Context Menu >>>
// <h> this is a heading
// </h>
// <e.3>this is an options
// </e>
uint8 tmp=1;
//<<< end of configuration section >>>
選擇后:
//<<< Use Configuration Wizard in Context Menu >>>
// <h> this is a heading
// </h>
// <e.3>this is an options
// </e>
uint8 tmp=9;
//<<< end of configuration section >>>
我們再來擴充下視野:假設我的8bit的數據分成8個enable選項,應該怎么做呢?
//<<< Use Configuration Wizard in Context Menu >>>
// <h> this is a heading
// </h>
// <e.3>this is an options bit 3
// </e>
// <e.2>this is an options bit 2
// </e>
// <e.0>this is an options bit 0
// </e>
uint8 tmp=9;
//<<< end of configuration section >>>
3.infomations命令<i>
當鼠標停留在當前的條目的時候可以顯示提示信息。我們繼續代碼說明:
//<<< Use Configuration Wizard in Context Menu >>>
// <h> this is a heading
// <i> head start form here!
// </h>
// <e>this is an options
// </e>
//<<< end of configuration section >>>
4.位允許<q>
和<e>不同,<q>只是一個單選項,沒有段落(組)的概念。
// <h> this is a heading
// <i> head start form here!
// <q> this is single bitenable
// </h>
#define BitEnalbe 1
同樣也可以指定具體的某一位
// <h> this is a heading
// <i> head start form here!
// <q.0> this is single bitenable bit 0
// <q.1> this is single bitenable bit 1
// <q.7> this is single bitenable bit 7
// </h>
#define BitEnalbe 0x83
5.<o>選擇或者輸入數字
// <o> this is a 32bit input
uint32 tmp32=0x2000;
數字輸入涉及的問題就很多啦。比如我要限制啊,只能是一定范圍啊,咋辦?
<min-max>
// <o> this is a 32bit input
// <2-30>
uint32 tmp32=0x02;
只能選擇到極限值以內了。如果主動輸入限制范圍以外的數值呢?那可能會導致崩潰!
<min-max>后面還可以跟一個步進:<min-max:step>,比如:
// <o> this is a 32bit input
// <2-30:4>
uint32 tmp32=0x10;
步進就變成了4了,每次點擊上或者下,變化的步進就是4
那么這個數字能不能做成下拉菜單呢?當然是可以的。
// <o> this is a 32bit input
// <0=> 1 <1=> 2
uint32 tmp32=0x01;
當選擇2的時候把1賦給了后面的tmp32
那么指定位置呢?
當然也是可以的。
uint32 tmp32=0x01;
// <o.0> this is a 32bit input bit0
// <0=> 1 <1=> 2
uint32 tmp32=0x01;
// <o.0..7> this is a 32bit input bit0-7
// <0=> 1 <1=> 2 <255=> 3
uint32 tmp32=0xFF;
6.字符串輸入<s>
// <s> this is a string input
uint32 buf[]="hello";
如果要想要限制字符串輸入的長度可以用:<s:limt>
// <s.10> this is a string input
uint32 buf[]="hello12345";
這個基本功能就介紹完了,下面有個重點功能要介紹:
7.整合所有的配置項
我們說,配置項多的時候是需要整合的。整合的過程當中,我們必須看清楚一個功能,那就是怎么跟多個配置項的配對起來。
在一個段落中,keil是只會把數值賦給隨后的第一個定義,為了區分一個段落中的不同配置項,要用后綴來區分。上例子:
// <h> for multi-configuarations
// <q.0> this is single bit enable bit 0
// <q1.0> this is single bit enable bit 0
// <o> this is a 32bit input
// <2-30:4>
// <o1> this is a 32bit input
// <0=> 1 <1=> 2
// <o2.0> this is a 32bit input bit0
// <0=> 1 <1=> 2
// <o3.0..7> this is a 32bit input bit0-7
// <0=> 1 <1=> 2 <255=> 3
// <s> this is a string input
// <s1.10> this is a string input
// </h>
#define Q0 1
#define Q1 1
uint32 tmp32=0x15;
uint32 tmp32=0x00;
uint32 tmp32=0x01;
uint32 tmp32=0xFF;
uint32 buf[]="hello";
uint32 buf[]="hello12345";
https://blog.csdn.net/ropai/article/details/33719447