原创 CodeWarrior 宏定义

2008-6-7 10:32 2926 6 6 分类: MCU/ 嵌入式

 


                 有时候在程序中会出现


                             EnableInterrrupt;


                             ClearReg0


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


Defining a Macro <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />


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


Example:


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


The preprocessor expands the macro:


 


 


 


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 ; };


 


 


 


 

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
我要评论
0
6
关闭 站长推荐上一条 /3 下一条