KEIL编程小技巧-配置向导

电子说

1.2w人已加入

描述

介绍

Keil作为使用广泛的一款嵌入式开发IDE,大多数的工程师只用到了编译和仿真功能,其实只需要一些编程小技巧就可以通过Keil将代码的一些配置可视化。

本篇将要介绍的是Keil的一项功能叫做 Configuration Wizard (配置向导),这是内嵌在Keil编辑器中的一项功能,按照既定规则在代码中标记后则可以产生配置可视化的效果(如下图所示),由于是以注释的形式进行标记,所以并不会实际影响代码的移植编译以及正常功能。

RAM

配置向导语法

当编辑器检测到代码中存在有

//***<  < < Use Configuration Wizard in Context Menu  >>  >***

并且以如下代码结束

//***< < < end of configuration section > > >***

那么Keil的编辑器则会识别并解析注释内容生成对应的图形化配置界面,编码的规则如下所示

RAM

范例代码

如下是介绍章节显示图对应的帮助文档提供的范例代码,可以参考实际编码操作一下

//*** < < < Use Configuration Wizard in Context Menu > > > ***


FUNC void Setup (void) {

// < h > External Bus Interface (EBI)

//   < e1.13 > Enable Chip Select 0 (CSR0)
//     < o1.20..31 > BA: Base Address < 0x0-0xFFF00000:0x100000 >< #/0x100000 >
//                 < i > Start Address for Chip Select Signal
//     < o1.7..8 >   PAGES: Page Size     < 0= > 1M Byte   < 1= > 4M Bytes
//                                       < 2= > 16M Bytes < 3= > 64M Bytes
//                 < i > Selects Active Bits in Base Address
//     < o1.0..1 >   DBW: Data Bus Width   < 1= > 16-bit     < 2= > 8-bit
//     < o1.12 >     BAT: Byte Access Type < 0= > Byte-write
//                                       < 1= > Byte-select
//     < e1.5 >     WSE: Enable Wait State Generation
//       < o1.2..4 >   NWS: Number of Standard Wait States < 1-8 >< #-1 >
//     < /e >
//     < o1.9..11 > TDF: Data Float Output Time < 0-7 >
//                 < i > Number of Cycles Added after the Transfer
//   < /e >
 _WDWORD(0xFFE00000, 0x010024A9);   // EBI_CSR0: Flash

//   < e1.13 > Enable Chip Select 1 (CSR1)
//     < o1.20..31 > BA: Base Address < 0x0-0xFFF00000:0x100000 >< #/0x100000 >
//                 < i > Start Address for Chip Select Signal
//     < o1.7..8 >   PAGES: Page Size     < 0= > 1M Byte   < 1= > 4M Bytes
//                                       < 2= > 16M Bytes < 3= > 64M Bytes
//                 < i > Selects Active Bits in Base Address
//     < o1.0..1 >   DBW: Data Bus Width   < 1= > 16-bit     < 2= > 8-bit
//     < o1.12 >     BAT: Byte Access Type < 0= > Byte-write
//                                       < 1= > Byte-select
//     < e1.5 >     WSE: Enable Wait State Generation
//       < o1.2..4 >   NWS: Number of Standard Wait States < 1-8 >< #-1 >
//     < /e >
//     < o1.9..11 > TDF: Data Float Output Time < 0-7 >
//                 < i > Number of Cycles Added after the Transfer
//   < /e >
 _WDWORD(0xFFE00004, 0x040034A5);   // EBI_CSR1: RAM

//   < q1.4 >       DRP: Data Read Protocol
//                     < 0= > Standard Read
//                     < 1= > Early Read
_WDWORD(0xFFE00024, 0x00000010);   // EBI_MCR: Data Read Protocol

 _WDWORD(0xFFE00020, 0x00000001);   // EBI_RCR: Remap Command

// < /h >

// < o > Program Entry Point
 PC = 0x04000000;

}

// < s > Change ID
// < s1.30 > Change Password String
#define ID "My User ID"
char pw[] = "My Password";


/*********************************************************/
/* Example for enabling and disabling code             */

// < c1 > Use MY_CPU_VARIANT
// < i > Use MY_CPU_VARIANT, and set the include file
#define MY_CPU_VARIANT
#include "MyCpuVariant.h"
// < /c >

// < !c1 > Disable log
// < i > Disable log file generation
#define _USE_LOG
// < /c >

// < c1 > Example of inconsistent comment
// < i > a mix of commented and uncommented lines in the block create an inconsistency

// This type of comment, mixed with uncommented lines, creates the inconsistency
/* You can use this type of comment without creating an inconsistency */

  do_whatever;              // adding this type of comment here is allowed

// < /c >


//*** < < < end of configuration section > > >   ***

如有兴趣,那么可以查看Keil帮助文档中的配置向导部分内容,文档内容位置如下图所示,实际配置效果大家自行动手实践一下能加深印象。

RAM

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分