EDN首页   博客首页

日志档案

发表于 2008-6-7 10:32:11

1

标签: CodeWarrior  C  

CodeWarrior 宏定义

 

                 有时候在程序中会出现

                             EnableInterrrupt;

                             ClearReg0

        我们看字面意思很容易懂它是什么意思,但是一般初学者一般会被它搞晕,为什么就这样一个单词就能表示开中断呢,其实它在头文件中时有定义的,那就是宏定义,这个单词代表的是一些语句,在包含文件里面有定义的,就是方便编程,增加程序的可读性,下面是CodeWarrior 宏定义的解释:

Defining a Macro

An HLI assembler macro is defined using the preprocessor directive `define'.

Example:

/* Following macro clears the register zero. */
#define ClearReg0 {asm CLR Reg0;} 

The macro is invoked in the following way in the source code:

ClearReg0; 

The preprocessor expands the macro:

{asm CLR Reg0;}; 

 

 

 

Example:

/* Following macro clears the registers 0 and 1. */

 

#define ClearReg0And1 {asm CLR Reg0; asm CLR Reg1}

 

The macro is invoked in the following way in the source code:

 

ClearReg0And1;

 

 

The preprocessor expands the macro:

{asm CLR Reg0; asm CLR Reg1; };

You can define an HLI assembler macro on several lines using the line separator `\'.

 

Example:

/* Following macro clears the registers 0 and 1. */

 

#define ClearR0andR1 {asm CLR Reg0; \

                      asm CLR Reg1}

 

The macro is invoked in the following way in the source code:

 

ClearR0andR1;

 

The preprocessor expands the macro:

{asm CLR Reg0; asm CLR Reg1; };

Using Macro Parameters

An HLI assembler macro may have some parameters which are referenced in the macro code.

Example:

/* This macro initializes the specified variable to 0.*/

#define Clear(var) {asm CLR var}

The macro is invoked in the following way in the source code:

Clear(var1);

The preprocessor expands the macro:

{asm CLR var1 ; };

 

 

 

 

系统分类: 单片机   |   用户分类: Codewarrior   |   来源: 原创   |   【推荐给朋友】   |   【添加到收藏夹】

    阅读(139)    回复(0)  

投一票您将和博主都有获奖机会!